Elffuss BraidHub

kikocis/ncnn public

master · 1.8 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
4//
5// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6// in compliance with the License. You may obtain a copy of the License at
7//
8// https://opensource.org/licenses/BSD-3-Clause
9//
10// Unless required by applicable law or agreed to in writing, software distributed
11// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13// specific language governing permissions and limitations under the License.
14
15#include "bias_arm.h"
16
17#if __ARM_NEON
18#include <arm_neon.h>
19#endif // __ARM_NEON
20
21namespace ncnn {
22
23int Bias_arm::forward_inplace(Mat& bottom_top_blob, const Option& opt) const
24{
25 int w = bottom_top_blob.w;
26 int h = bottom_top_blob.h;
27 int d = bottom_top_blob.d;
28 int channels = bottom_top_blob.c;
29 int size = w * h * d;
30
31 const float* bias_ptr = bias_data;
32 #pragma omp parallel for num_threads(opt.num_threads)
33 for (int q = 0; q < channels; q++)
34 {
35 float* ptr = bottom_top_blob.channel(q);
36
37 float bias = bias_ptr[q];
38
39#if __ARM_NEON
40 int nn = size >> 2;
41 int remain = size - (nn << 2);
42#else
43 int remain = size;
44#endif // __ARM_NEON
45
46#if __ARM_NEON
47 float32x4_t _bias = vdupq_n_f32(bias);
48 for (; nn > 0; nn--)
49 {
50 float32x4_t _p = vld1q_f32(ptr);
51 float32x4_t _outp = vaddq_f32(_p, _bias);
52 vst1q_f32(ptr, _outp);
53
54 ptr += 4;
55 }
56#endif // __ARM_NEON
57
58 for (; remain > 0; remain--)
59 {
60 *ptr = *ptr + bias;
61
62 ptr++;
63 }
64 }
65
66 return 0;
67}
68
69} // namespace ncnn