From f8f3b0b5aadef4e15bfcb5fcb47c4c2d0d5a7e3e Mon Sep 17 00:00:00 2001 From: nihuini Date: Fri, 11 Oct 2019 15:51:43 +0800 Subject: [PATCH] shufflechannel pack4 --- src/layer/arm/reshape_arm.cpp | 2 + src/layer/arm/shufflechannel_arm.cpp | 211 +++++++++++++++++++++++++++ src/layer/arm/shufflechannel_arm.h | 32 ++++ 3 files changed, 245 insertions(+) create mode 100644 src/layer/arm/shufflechannel_arm.cpp create mode 100644 src/layer/arm/shufflechannel_arm.h diff --git a/src/layer/arm/reshape_arm.cpp b/src/layer/arm/reshape_arm.cpp index 4a2e531fd..d6da147fa 100644 --- a/src/layer/arm/reshape_arm.cpp +++ b/src/layer/arm/reshape_arm.cpp @@ -71,6 +71,7 @@ int Reshape_arm::destroy_pipeline(const Option& opt) int Reshape_arm::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const { +#if __ARM_NEON if (opt.use_packing_layout) { @@ -300,6 +301,7 @@ int Reshape_arm::forward(const Mat& bottom_blob, Mat& top_blob, const Option& op return 0; } // opt.use_packing_layout +#endif // __ARM_NEON return Reshape::forward(bottom_blob, top_blob, opt); } diff --git a/src/layer/arm/shufflechannel_arm.cpp b/src/layer/arm/shufflechannel_arm.cpp new file mode 100644 index 000000000..a97dc3356 --- /dev/null +++ b/src/layer/arm/shufflechannel_arm.cpp @@ -0,0 +1,211 @@ +// 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 "shufflechannel_arm.h" + +#include "layer_type.h" + +#if __ARM_NEON +#include +#endif // __ARM_NEON + +namespace ncnn { + +DEFINE_LAYER_CREATOR(ShuffleChannel_arm) + +ShuffleChannel_arm::ShuffleChannel_arm() +{ +#if __ARM_NEON + support_packing = true; +#endif // __ARM_NEON +} + +int ShuffleChannel_arm::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const +{ + if (group == 1) + { + top_blob = bottom_blob; + return 0; + } + + int elempack = bottom_blob.elempack; + +#if __ARM_NEON + if (opt.use_packing_layout) + { + + int w = bottom_blob.w; + int h = bottom_blob.h; + int channels = bottom_blob.c; + int size = w * h; + size_t elemsize = bottom_blob.elemsize; + + if (elempack == 4) + { + if (group <= 4 && channels % group == 0) + { + top_blob.create(w, h, channels, elemsize, elempack, opt.blob_allocator); + if (top_blob.empty()) + return -100; + + int channels_per_group = channels / group; + + if (group == 2) + { + for (int q=0; q