| 43 | |
| 44 | const int default_prio = 300; |
| 45 | void elu_kernel(int i, int id, void* data, const float* input, float* output, float alpha) |
| 46 | { |
| 47 | int elem_num = ((int*)data)[0]; |
| 48 | float32x4_t _one = vdupq_n_f32(1.f); |
| 49 | float32x4_t _zero = vdupq_n_f32(0.f); |
| 50 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 51 | const float* cur_input = input + id * elem_num; |
| 52 | float* cur_output = output + id * elem_num; |
| 53 | for(int i = 0; i < (elem_num & -4); i += 4) |
| 54 | { |
| 55 | float32x4_t _p = vld1q_f32(cur_input); |
| 56 | uint32x4_t _lemask = vcleq_f32(_p, _zero); |
| 57 | |
| 58 | float32x4_t _nps = exp_ps(_p); |
| 59 | _nps = vsubq_f32(_nps, _one); |
| 60 | _nps = vmulq_f32(_nps, _alpha); |
| 61 | |
| 62 | _p = vbslq_f32(_lemask, _nps, _p); |
| 63 | vst1q_f32(cur_output, _p); |
| 64 | cur_input += 4; |
| 65 | cur_output += 4; |
| 66 | } |
| 67 | for(int i = elem_num & ~3; i < elem_num; i++) |
| 68 | { |
| 69 | if (*cur_input < 0.f) |
| 70 | *cur_output = (exp(*cur_input) - 1.f) * alpha; |
| 71 | else |
| 72 | *cur_output = *cur_input; |
| 73 | cur_input ++; |
| 74 | cur_output ++; |
| 75 | } |
| 76 | } |
| 77 | struct EluOps : public NodeOps |
| 78 | { |
| 79 | EluOps() |