15
#include "sigmoid_riscv.h"
18
#include <riscv_vector.h>
19
#include "rvv_mathfun.h"
20
#include "rvv_mathfun_fp16s.h"
25
Sigmoid_riscv::Sigmoid_riscv()
28
support_packing = true;
30
support_fp16_storage = true;
35
int Sigmoid_riscv::forward_inplace(Mat& bottom_top_blob, const Option& opt) const
37
#if __riscv_vector && __riscv_zfh
38
int elembits = bottom_top_blob.elembits();
40
if (opt.use_fp16_storage && elembits == 16)
42
if (opt.use_fp16_arithmetic)
43
return forward_inplace_fp16sa(bottom_top_blob, opt);
45
return forward_inplace_fp16s(bottom_top_blob, opt);
49
int w = bottom_top_blob.w;
50
int h = bottom_top_blob.h;
51
int d = bottom_top_blob.d;
52
int channels = bottom_top_blob.c;
53
int elempack = bottom_top_blob.elempack;
54
int size = w * h * d * elempack;
56
#pragma omp parallel for num_threads(opt.num_threads)
57
for (int q = 0; q < channels; q++)
59
float* ptr = bottom_top_blob.channel(q);
65
size_t vl = vsetvl_e32m8(n);
67
vfloat32m8_t _p = vle32_v_f32m8(ptr, vl);
68
_p = sigmoid_ps(_p, vl);
69
vse32_v_f32m8(ptr, _p, vl);
75
for (int i = 0; i < size; i++)
77
*ptr = 1.f / (1.f + exp(-*ptr));
87
#if __riscv_vector && __riscv_zfh
88
int Sigmoid_riscv::forward_inplace_fp16s(Mat& bottom_top_blob, const Option& opt) const
90
int w = bottom_top_blob.w;
91
int h = bottom_top_blob.h;
92
int d = bottom_top_blob.d;
93
int channels = bottom_top_blob.c;
94
int elempack = bottom_top_blob.elempack;
95
int size = w * h * d * elempack;
97
#pragma omp parallel for num_threads(opt.num_threads)
98
for (int q = 0; q < channels; q++)
100
__fp16* ptr = bottom_top_blob.channel(q);
105
size_t vl = vsetvl_e16m4(n);
107
vfloat32m8_t _p = vfwcvt_f_f_v_f32m8(vle16_v_f16m4(ptr, vl), vl);
108
_p = sigmoid_ps(_p, vl);
109
vse16_v_f16m4(ptr, vfncvt_f_f_w_f16m4(_p, vl), vl);
119
int Sigmoid_riscv::forward_inplace_fp16sa(Mat& bottom_top_blob, const Option& opt) const
121
int w = bottom_top_blob.w;
122
int h = bottom_top_blob.h;
123
int d = bottom_top_blob.d;
124
int channels = bottom_top_blob.c;
125
int elempack = bottom_top_blob.elempack;
126
int size = w * h * d * elempack;
128
#pragma omp parallel for num_threads(opt.num_threads)
129
for (int q = 0; q < channels; q++)
131
__fp16* ptr = bottom_top_blob.channel(q);
136
size_t vl = vsetvl_e16m8(n);
138
vfloat16m8_t _p = vle16_v_f16m8(ptr, vl);
139
_p = sigmoid_ps(_p, vl);
140
vse16_v_f16m8(ptr, _p, vl);