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 "schema/model_v0_generated.h" 18 #include "src/ops/populate/populate_register.h" 19 #include "nnacl/conv_parameter.h" 20 21 namespace mindspore { 22 namespace lite { 23 namespace { PopulateConvDwParameter(const void * prim)24OpParameter *PopulateConvDwParameter(const void *prim) { 25 auto *primitive = static_cast<const schema::v0::Primitive *>(prim); 26 MS_ASSERT(primitive != nullptr); 27 auto depthwise_conv2d_prim = primitive->value_as_DepthwiseConv2D(); 28 if (depthwise_conv2d_prim == nullptr) { 29 MS_LOG(ERROR) << "depthwise_conv2d_prim is nullptr"; 30 return nullptr; 31 } 32 auto *conv_param = reinterpret_cast<ConvParameter *>(malloc(sizeof(ConvParameter))); 33 if (conv_param == nullptr) { 34 MS_LOG(ERROR) << "malloc ConvParameter failed."; 35 return nullptr; 36 } 37 memset(conv_param, 0, sizeof(ConvParameter)); 38 conv_param->op_parameter_.type_ = schema::PrimitiveType_Conv2DFusion; 39 40 conv_param->group_ = depthwise_conv2d_prim->channelIn(); 41 conv_param->kernel_h_ = depthwise_conv2d_prim->kernelH(); 42 conv_param->kernel_w_ = depthwise_conv2d_prim->kernelW(); 43 conv_param->stride_h_ = depthwise_conv2d_prim->strideH(); 44 conv_param->stride_w_ = depthwise_conv2d_prim->strideW(); 45 conv_param->pad_u_ = depthwise_conv2d_prim->padUp(); 46 conv_param->pad_d_ = depthwise_conv2d_prim->padDown(); 47 conv_param->pad_l_ = depthwise_conv2d_prim->padLeft(); 48 conv_param->pad_r_ = depthwise_conv2d_prim->padRight(); 49 conv_param->input_channel_ = depthwise_conv2d_prim->channelIn(); 50 conv_param->output_channel_ = depthwise_conv2d_prim->channelIn(); 51 conv_param->dilation_h_ = depthwise_conv2d_prim->dilateH(); 52 conv_param->dilation_w_ = depthwise_conv2d_prim->dilateW(); 53 54 auto pad_mode = depthwise_conv2d_prim->padMode(); 55 switch (pad_mode) { 56 case schema::v0::PadMode_SAME_UPPER: 57 conv_param->pad_mode_ = Pad_same; 58 break; 59 case schema::v0::PadMode_VALID: 60 conv_param->pad_mode_ = Pad_valid; 61 break; 62 default: 63 conv_param->pad_mode_ = Pad_pad; 64 break; 65 } 66 auto act_type = depthwise_conv2d_prim->activationType(); 67 switch (act_type) { 68 case schema::v0::ActivationType_RELU: 69 conv_param->act_type_ = ActType_Relu; 70 break; 71 case schema::v0::ActivationType_RELU6: 72 conv_param->act_type_ = ActType_Relu6; 73 break; 74 default: 75 conv_param->act_type_ = ActType_No; 76 break; 77 } 78 conv_param->channel_multiplie_ = depthwise_conv2d_prim->channelMultiplier(); 79 return reinterpret_cast<OpParameter *>(conv_param); 80 } 81 } // namespace 82 83 Registry g_depthwiseConv2DV0ParameterRegistry(schema::v0::PrimitiveType_DepthwiseConv2D, PopulateConvDwParameter, 84 SCHEMA_V0); 85 } // namespace lite 86 } // namespace mindspore 87