MCPcopy Create free account
hub / github.com/OAID/Tengine / relu_kernel

Function relu_kernel

executor/operator/arm32/relu_float.cpp:43–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41const int default_prio = 300;
42
43inline bool relu_kernel(const int i, const int id, const void* data, const float* input,float* output, const float slope)
44{
45 float32x4_t _zero = vdupq_n_f32(0.f);
46 int step = ((int*)data)[0];
47 const float* cur_input = input + id * step;
48 float* cur_output = output + id * step;
49 if(slope == 0)
50 {
51 for(int l=0; l< (step & -4); l += 4)
52 {
53 float32x4_t _p = vld1q_f32(cur_input);
54 _p = vmaxq_f32(_p, _zero);
55 vst1q_f32(cur_output, _p);
56 cur_input += 4;
57 cur_output += 4;
58
59 }
60 for(int i = step & ~3; i < step; i++)
61 {
62 *cur_output++ = MAX(*cur_input++, 0.f);
63 }
64 }
65 else
66 {
67 float32x4_t _slope = vdupq_n_f32(slope);
68 for(int l=0; l< (step & -4); l += 4)
69 {
70 float32x4_t _p = vld1q_f32(cur_input);
71 // ri = ai <= bi ? 1...1:0...0
72 uint32x4_t _lemask = vcleq_f32(_p, _zero);
73 float32x4_t _ps = vmulq_f32(_p, _slope);
74 // bitwise select
75 _p = vbslq_f32(_lemask, _ps, _p);
76 vst1q_f32(cur_output, _p);
77 cur_input += 4;
78 cur_output += 4;
79 }
80 for(int i = step & ~3; i < step; i++)
81 {
82 *cur_output++ = MAX(cur_input[0], 0.f) + slope * MIN(cur_input[0], 0.f);
83 cur_input ++;
84 }
85 }
86 return true;
87}
88
89struct ReluOps : public NodeOps
90{

Callers 1

RunMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected