• 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 #ifndef NNACL_FP16_POWER_FP16_H_
18 #define NNACL_FP16_POWER_FP16_H_
19 
20 #include <math.h>
21 #include "nnacl/op_base.h"
22 #include "nnacl/intrinsics/ms_simd_instructions_fp16.h"
23 #include "nnacl/pow_parameter.h"
24 
25 #if defined(ENABLE_NEON)
26 typedef float16x8_t (*PowerSimdFunFp16)(float16x8_t x, const void *exponent);
27 #endif
28 typedef float16_t (*PowerScalarFunFp16)(float16_t x, const void *exponent);
29 typedef void (*PowerFunFp16)(const float16_t *, const float16_t *, float16_t *, int, float, float);
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
CheckIntegerFp16(float16_t f)34 static inline bool CheckIntegerFp16(float16_t f) { return floorf(f) == f; }
35 
StdPowerScalarFp16(float16_t x,const void * exponent)36 static inline float16_t StdPowerScalarFp16(float16_t x, const void *exponent) {
37   return powf(x, *(float16_t *)exponent);
38 }
39 
40 #if defined(ENABLE_NEON)
StdPowerSimdFp16(float16x8_t x,const void * exponent)41 static inline float16x8_t StdPowerSimdFp16(float16x8_t x, const void *exponent) {
42   float16x8_t result;
43   result[0] = powf(x[0], *(float16_t *)exponent);
44   result[1] = powf(x[1], *(float16_t *)exponent);
45   result[2] = powf(x[2], *(float16_t *)exponent);
46   result[3] = powf(x[3], *(float16_t *)exponent);
47   result[4] = powf(x[4], *(float16_t *)exponent);
48   result[5] = powf(x[5], *(float16_t *)exponent);
49   result[6] = powf(x[6], *(float16_t *)exponent);
50   result[7] = powf(x[7], *(float16_t *)exponent);
51   return result;
52 }
53 #endif
54 int PowerFp16(const float16_t *input, const float16_t *exponent, float16_t *output, int len, float scale, float shift,
55               bool broadcast);
56 void PowerSingleFp16(const float16_t *input, const float16_t *exponent, float16_t *output, int len, float scale,
57                      float shift);
58 void PowerBroadCastFp16(const float16_t *input, const float16_t *exponent, float16_t *output, int len, float scale,
59                         float shift);
60 #ifdef __cplusplus
61 }
62 #endif
63 
64 #endif  //  NNACL_FP16_POWER_FP16_H_
65