• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2023 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 convolutionress or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifdef ENABLE_ARM64
18 #include "nnacl/kernel/convolution_sw_arm64.h"
19 #include "nnacl/kernel/convolution_slidewindow.h"
20 #include "nnacl/fp32/conv_sw_arm64_fp32.h"
21 
ConvSWARM64InitGlobalVariable(ConvolutionBaseStruct * conv)22 void ConvSWARM64InitGlobalVariable(ConvolutionBaseStruct *conv) {
23   ConvolutionSWStruct *conv_sw = (ConvolutionSWStruct *)conv;
24   NNACL_CHECK_NULL_RETURN_VOID(conv_sw);
25   ConvParameter *conv_param = (ConvParameter *)conv->base_.param_;
26   NNACL_CHECK_NULL_RETURN_VOID(conv_param);
27 
28   conv_sw->oc_tile_ = C8NUM;
29   conv_sw->oc_res_ = conv_param->output_channel_ % conv_sw->oc_tile_;
30 }
31 
ConvSWARM64RunImpl(ConvolutionBaseStruct * conv,int task_id)32 int ConvSWARM64RunImpl(ConvolutionBaseStruct *conv, int task_id) {
33   ConvolutionSWStruct *conv_sw = (ConvolutionSWStruct *)conv;
34   NNACL_CHECK_NULL_RETURN_ERR(conv_sw);
35   ConvParameter *conv_param = (ConvParameter *)conv->base_.param_;
36   NNACL_CHECK_NULL_RETURN_ERR(conv_param);
37   ConvSWArm64Fp32(conv_sw->input_data_, (float *)conv->packed_weight_, (float *)conv->bias_data_, conv_sw->output_data_,
38                   task_id, conv_param, &conv_sw->sw_param_);
39   return NNACL_OK;
40 }
41 
CreateConvolutionSWARM64(ConvParameter * conv_param)42 ConvolutionBaseStruct *CreateConvolutionSWARM64(ConvParameter *conv_param) {
43   ConvolutionSWStruct *sw = (ConvolutionSWStruct *)malloc(sizeof(ConvolutionSWStruct));
44   NNACL_MALLOC_CHECK_NULL_RETURN_NULL(sw);
45   memset(sw, 0, sizeof(ConvolutionSWStruct));
46 
47   sw->conv_.run_impl_ = ConvSWARM64RunImpl;
48   sw->conv_.init_global_variable_ = ConvSWARM64InitGlobalVariable;
49   sw->conv_.pack_weight_ = ConvSWPackWeight;
50   sw->conv_.malloc_weight_bias_ = ConvSWMallocWeightBiasData;
51 
52   sw->conv_.base_.Compute = ConvolutionSWCompute;
53   sw->conv_.base_.Prepare = ConvolutionSWPrepare;
54   sw->conv_.base_.Release = ConvolutionSWRelease;
55   sw->conv_.base_.Resize = ConvolutionSWResize;
56 
57   return (ConvolutionBaseStruct *)sw;
58 }
59 #endif
60