• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <math.h>
18 #include "nnacl/op_base.h"
19 #include "nnacl/fp16_grad/arithmetic_self_grad.h"
20 #include "nnacl/errorcode.h"
21 
Fp16LogGrad(const float16_t * src0,const float16_t * src1,size_t length,float16_t * dst)22 int Fp16LogGrad(const float16_t *src0, const float16_t *src1, size_t length, float16_t *dst) {
23   int i = 0;
24 #ifdef ENABLE_NEON
25   float16x8_t log_10 = vdupq_n_f16(log(10));
26   for (; i < length - 4; i += 4) {
27     float16x8_t src0_4 = vld1q_f16(src0 + i);
28     float16x8_t src1_4 = vld1q_f16(src1 + i);
29     float16x8_t dst_4 = vmulq_f16(src0_4, vrecpeq_f16(vmulq_f16(src1_4, log_10)));
30     vst1q_f16(dst + i, dst_4);
31   }
32 #endif
33   for (; i < length; i++) {
34     dst[i] = src0[i] * 1.0f / (src1[i] * log(10));
35   }
36   return NNACL_OK;
37 }
38