1
// Xavier Hsinyuan is pleased to support the open source community by making ncnn available.
3
// Copyright (C) 2021 Xavier Hsinyuan <me@lstlx.com>. All rights reserved.
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
8
// https://opensource.org/licenses/BSD-3-Clause
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.
15
#include "selu_riscv.h"
18
#include <riscv_vector.h>
19
#include "rvv_mathfun.h"
20
#endif // __riscv_vector
24
int SELU_riscv::forward_inplace(Mat& bottom_top_blob, const Option& opt) const
26
int w = bottom_top_blob.w;
27
int h = bottom_top_blob.h;
28
int d = bottom_top_blob.d;
29
int channels = bottom_top_blob.c;
30
int elempack = bottom_top_blob.elempack;
31
int size = w * h * d * elempack;
33
float alphaxlambda = alpha * lambda;
34
#pragma omp parallel for num_threads(opt.num_threads)
35
for (int q = 0; q < channels; q++)
37
float* ptr = bottom_top_blob.channel(q);
42
size_t vl = vsetvl_e32m8(n);
43
vfloat32m8_t _p = vle32_v_f32m8(ptr, vl);
44
vbool4_t _lower = vmflt_vf_f32m8_b4(_p, 0.f, vl);
45
vbool4_t _higher = vmnot_m_b4(_lower, vl);
47
_p = vfmul_vf_f32m8_m(_higher, _p, /*op1*/ _p, lambda, vl);
48
vfloat32m8_t _nps = exp_ps(_p, vl);
49
_nps = vfsub_vf_f32m8_m(_lower, _p, /*op1*/ _nps, 1.f, vl);
50
_nps = vfmul_vf_f32m8_m(_lower, _p, /*op1*/ _nps, alphaxlambda, vl);
52
vse32_v_f32m8(ptr, _nps, vl);
57
for (int i = 0; i < size; i++)
60
ptr[i] = (expf(ptr[i]) - 1.f) * alphaxlambda;
64
#endif // __riscv_vector