| 41 | const int default_prio = 300; |
| 42 | |
| 43 | inline 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 | |
| 89 | struct ReluOps : public NodeOps |
| 90 | { |