1 /**
2 * Copyright 2020-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 "nnacl/fp32/exp_fp32.h"
18 #include "nnacl/exp_fp32_simd.h"
19 #include <math.h>
20 #include <string.h>
21 #include "nnacl/errorcode.h"
22
ExpFp32(const float * src,float * dst,int num)23 void ExpFp32(const float *src, float *dst, int num) {
24 int i = 0;
25
26 SIMD_RUN_NO_SCALAR(ExpFp32, i, src, dst, num);
27 for (; i < num; ++i) {
28 simd_exp32(src[i], dst + i);
29 }
30 }
31
ExpFusionFp32(const void * src_data,void * dst_data,const ExpStruct * exp,int task_id)32 int ExpFusionFp32(const void *src_data, void *dst_data, const ExpStruct *exp, int task_id) {
33 NNACL_CHECK_ZERO_RETURN_ERR(exp->base_.thread_nr_);
34 ExpParameter *param = (ExpParameter *)exp->base_.param_;
35 NNACL_CHECK_NULL_RETURN_ERR(param);
36 const float *src = (const float *)src_data;
37 float *dst = (float *)dst_data;
38
39 int stride = UP_DIV(exp->element_num_, exp->base_.thread_nr_);
40 int start = stride * task_id;
41 int end = MSMIN(exp->element_num_, start + stride);
42 int num = end - start;
43
44 if (param->scale_ == 1) {
45 ExpFp32(src + start, dst + start, num);
46 } else {
47 int i = 0;
48 SIMD_RUN_NO_SCALAR(ExpFp32WithInScale, i, src, dst, num, exp->in_scale_);
49 for (; i < num; ++i) {
50 simd_exp32(src[i] * exp->in_scale_, dst + i);
51 }
52 }
53 if (exp->out_scale_ != 1) {
54 int i = 0;
55 SIMD_RUN_NO_SCALAR(ExpFp32WithOutScale, i, src, dst, num, exp->out_scale_);
56 for (; i < num; ++i) {
57 simd_exp32(src[i], dst + i);
58 dst[i] *= exp->out_scale_;
59 }
60 }
61 return NNACL_OK;
62 }
63