// Tencent is pleased to support the open source community by making ncnn available. // // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. // // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at // // https://opensource.org/licenses/BSD-3-Clause // // Unless required by applicable law or agreed to in writing, software distributed // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR // CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. #include "slice_arm.h" #include "layer_type.h" #if __ARM_NEON #include #endif // __ARM_NEON namespace ncnn { DEFINE_LAYER_CREATOR(Slice_arm) Slice_arm::Slice_arm() { #if __ARM_NEON support_packing = true; packing_pack1 = 0; #endif // __ARM_NEON support_bf16_storage = true; } int Slice_arm::create_pipeline(const Option& opt) { #if __ARM_NEON if (opt.use_packing_layout) { { packing_pack1 = ncnn::create_layer(ncnn::LayerType::Packing); ncnn::ParamDict pd; pd.set(0, 1); packing_pack1->load_param(pd); packing_pack1->create_pipeline(opt); } } #endif // __ARM_NEON return 0; } int Slice_arm::destroy_pipeline(const Option& opt) { #if __ARM_NEON if (opt.use_packing_layout) { if (packing_pack1) { packing_pack1->destroy_pipeline(opt); delete packing_pack1; packing_pack1 = 0; } } #endif // __ARM_NEON return 0; } int Slice_arm::forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& opt) const { if (opt.use_bf16_storage) return forward_bf16s(bottom_blobs, top_blobs, opt); const Mat& bottom_blob = bottom_blobs[0]; int dims = bottom_blob.dims; size_t elemsize = bottom_blob.elemsize; int elempack = bottom_blob.elempack; const int* slices_ptr = slices; #if __ARM_NEON if (opt.use_packing_layout) { if (dims == 1) // axis == 0 { // slice vector int w = bottom_blob.w * elempack; int q = 0; for (size_t i=0; iforward(bottom_blob, bottom_blob_unpacked, opt); } const float* ptr = bottom_blob_unpacked; for (size_t i=0; iforward(bottom_blob, bottom_blob_unpacked, opt); } int p = 0; for (size_t i=0; i& bottom_blobs, std::vector& top_blobs, const Option& opt) const { const Mat& bottom_blob = bottom_blobs[0]; int dims = bottom_blob.dims; size_t elemsize = bottom_blob.elemsize; int elempack = bottom_blob.elempack; const int* slices_ptr = slices; #if __ARM_NEON if (opt.use_packing_layout) { if (dims == 1) // axis == 0 { // slice vector int w = bottom_blob.w * elempack; int q = 0; for (size_t i=0; iforward(bottom_blob, bottom_blob_unpacked, opt); } const unsigned short* ptr = bottom_blob_unpacked; for (size_t i=0; i(j); for (int j=0; j(j); for (size_t i=0; i(j); memcpy(outptr, ptr, top_blob.w * elemsize); ptr += top_blob.w * elempack; } } return 0; } if (dims == 3 && axis == 0) { // slice dim channel int w = bottom_blob.w; int h = bottom_blob.h; int channels = bottom_blob.c * elempack; int q = 0; for (size_t i=0; iforward(bottom_blob, bottom_blob_unpacked, opt); } int p = 0; for (size_t i=0; i(j); memcpy(outptr, ptr, top_blob.w * elemsize); ptr += top_blob.w * elempack; } } } return 0; } } // opt.use_packing_layout #endif // __ARM_NEON return Slice::forward(bottom_blobs, top_blobs, opt); } } // namespace ncnn