diff --git a/mindspore/lite/src/ops/compat/v0/strided_slice_compat_v0.cc b/mindspore/lite/src/ops/compat/v0/strided_slice_compat_v0.cc index 69471b4147a..04ce2dc057c 100644 --- a/mindspore/lite/src/ops/compat/v0/strided_slice_compat_v0.cc +++ b/mindspore/lite/src/ops/compat/v0/strided_slice_compat_v0.cc @@ -28,7 +28,7 @@ int TransferStridedSliceAttr(Model::Node *node, std::vector *d dst_tensors->clear(); auto prim = reinterpret_cast(node->primitive_); MS_ASSERT(prim != nullptr); - int inputs_size = node->input_indices_.size(); + int inputs_size = static_cast(node->input_indices_.size()); auto param = prim->value_as_StridedSlice(); if (param == nullptr) { diff --git a/mindspore/lite/src/ops/populate/adder_populate.cc b/mindspore/lite/src/ops/populate/adder_populate.cc index 284b632448b..5b41e4f5ae7 100644 --- a/mindspore/lite/src/ops/populate/adder_populate.cc +++ b/mindspore/lite/src/ops/populate/adder_populate.cc @@ -53,8 +53,8 @@ OpParameter *PopulateAdderParameter(const void *prim) { param->stride_w_ = static_cast(*(stride->begin() + 1)); param->pad_u_ = static_cast(*(pad_list->begin())); param->pad_d_ = static_cast(*(pad_list->begin() + 1)); - param->pad_l_ = static_cast(*(pad_list->begin() + 2)); - param->pad_r_ = static_cast(*(pad_list->begin() + 3)); + param->pad_l_ = static_cast(*(pad_list->begin() + kOffsetTwo)); + param->pad_r_ = static_cast(*(pad_list->begin() + kOffsetThree)); param->dilation_h_ = static_cast(*(dilation->begin())); param->dilation_w_ = static_cast(*(dilation->begin() + 1)); param->input_channel_ = static_cast(value->in_channel()); diff --git a/mindspore/lite/src/ops/populate/conv2d_populate.cc b/mindspore/lite/src/ops/populate/conv2d_populate.cc index ab61ea062c8..ceec07cb670 100644 --- a/mindspore/lite/src/ops/populate/conv2d_populate.cc +++ b/mindspore/lite/src/ops/populate/conv2d_populate.cc @@ -20,7 +20,6 @@ using mindspore::schema::PrimitiveType_Conv2DFusion; namespace mindspore { namespace lite { -constexpr auto kMinShapeSize = 2; OpParameter *PopulateConvParameter(const void *prim) { auto primitive = static_cast(prim); MS_ASSERT(primitive != nullptr); @@ -47,7 +46,8 @@ OpParameter *PopulateConvParameter(const void *prim) { free(param); return nullptr; } - if (kernel_size->size() < kMinShapeSize || stride->size() < kMinShapeSize || dilation->size() < kMinShapeSize) { + if (kernel_size->size() < kMinShapeSizeTwo || stride->size() < kMinShapeSizeTwo || + dilation->size() < kMinShapeSizeTwo) { MS_LOG(ERROR) << "Invalid shape size!kernel_size size: " << kernel_size->size() << ", stride size: " << stride->size() << ", dilation size: " << dilation->size(); free(param); @@ -68,7 +68,7 @@ OpParameter *PopulateConvParameter(const void *prim) { default: param->pad_mode_ = Pad_pad; } - if (pad_list == nullptr || pad_list->size() < 4) { + if (pad_list == nullptr || pad_list->size() < kMinShapeSizeFour) { param->pad_u_ = 0; param->pad_d_ = 0; param->pad_l_ = 0; @@ -76,8 +76,8 @@ OpParameter *PopulateConvParameter(const void *prim) { } else { param->pad_u_ = static_cast(*(pad_list->begin())); param->pad_d_ = static_cast(*(pad_list->begin() + 1)); - param->pad_l_ = static_cast(*(pad_list->begin() + 2)); - param->pad_r_ = static_cast(*(pad_list->begin() + 3)); + param->pad_l_ = static_cast(*(pad_list->begin() + kOffsetTwo)); + param->pad_r_ = static_cast(*(pad_list->begin() + kOffsetThree)); } param->dilation_h_ = static_cast(*(dilation->begin())); param->dilation_w_ = static_cast(*(dilation->begin() + 1)); diff --git a/mindspore/lite/src/ops/populate/deconv2d_populate.cc b/mindspore/lite/src/ops/populate/deconv2d_populate.cc index 1e6a8328f12..f9bd06890e2 100644 --- a/mindspore/lite/src/ops/populate/deconv2d_populate.cc +++ b/mindspore/lite/src/ops/populate/deconv2d_populate.cc @@ -20,7 +20,6 @@ using mindspore::schema::PrimitiveType_Conv2dTransposeFusion; namespace mindspore { namespace lite { -constexpr auto kMinShapeSize = 2; OpParameter *PopulateDeconvParameter(const void *prim) { auto primitive = static_cast(prim); MS_ASSERT(primitive != nullptr); @@ -48,7 +47,8 @@ OpParameter *PopulateDeconvParameter(const void *prim) { free(param); return nullptr; } - if (kernel_size->size() < kMinShapeSize || stride->size() < kMinShapeSize || dilation->size() < kMinShapeSize) { + if (kernel_size->size() < kMinShapeSizeTwo || stride->size() < kMinShapeSizeTwo || + dilation->size() < kMinShapeSizeTwo) { MS_LOG(ERROR) << "Invalid shape size!kernel_size size: " << kernel_size->size() << ", stride size: " << stride->size() << ", dilation size: " << dilation->size() << ", output_paddings size:" << output_paddings->size(); @@ -72,7 +72,7 @@ OpParameter *PopulateDeconvParameter(const void *prim) { default: param->pad_mode_ = Pad_pad; } - if (pad_list == nullptr || pad_list->size() < 4) { + if (pad_list == nullptr || pad_list->size() < kMinShapeSizeFour) { param->pad_u_ = 0; param->pad_d_ = 0; param->pad_l_ = 0; @@ -80,8 +80,8 @@ OpParameter *PopulateDeconvParameter(const void *prim) { } else { param->pad_u_ = static_cast(*(pad_list->begin())); param->pad_d_ = static_cast(*(pad_list->begin() + 1)); - param->pad_l_ = static_cast(*(pad_list->begin() + 2)); - param->pad_r_ = static_cast(*(pad_list->begin() + 3)); + param->pad_l_ = static_cast(*(pad_list->begin() + kOffsetTwo)); + param->pad_r_ = static_cast(*(pad_list->begin() + kOffsetThree)); } param->dilation_h_ = static_cast(*(dilation->begin())); param->dilation_w_ = static_cast(*(dilation->begin() + 1)); diff --git a/mindspore/lite/src/ops/populate/detection_post_process_populate.cc b/mindspore/lite/src/ops/populate/detection_post_process_populate.cc index e8526010db0..9ff37e4082b 100644 --- a/mindspore/lite/src/ops/populate/detection_post_process_populate.cc +++ b/mindspore/lite/src/ops/populate/detection_post_process_populate.cc @@ -19,7 +19,6 @@ using mindspore::schema::PrimitiveType_DetectionPostProcess; namespace mindspore { namespace lite { -constexpr auto kScaleMinSize = 4; OpParameter *PopulateDetectionPostProcessParameter(const void *prim) { auto primitive = static_cast(prim); MS_ASSERT(primitive != nullptr); @@ -43,15 +42,15 @@ OpParameter *PopulateDetectionPostProcessParameter(const void *prim) { free(param); return nullptr; } - if (scale->size() < kScaleMinSize) { + if (scale->size() < kMinShapeSizeFour) { MS_LOG(ERROR) << "Invalid scale shape size " << scale->size(); free(param); return nullptr; } param->h_scale_ = *(scale->begin()); param->w_scale_ = *(scale->begin() + 1); - param->x_scale_ = *(scale->begin() + 2); - param->y_scale_ = *(scale->begin() + 3); + param->x_scale_ = *(scale->begin() + kOffsetTwo); + param->y_scale_ = *(scale->begin() + kOffsetThree); param->nms_iou_threshold_ = value->nms_iou_threshold(); param->nms_score_threshold_ = value->nms_score_threshold(); param->max_detections_ = value->max_detections(); diff --git a/mindspore/lite/src/ops/populate/pooling_populate.cc b/mindspore/lite/src/ops/populate/pooling_populate.cc index 29adecdecaa..8b2933aa85b 100644 --- a/mindspore/lite/src/ops/populate/pooling_populate.cc +++ b/mindspore/lite/src/ops/populate/pooling_populate.cc @@ -20,10 +20,6 @@ using mindspore::schema::PrimitiveType_MaxPoolFusion; namespace mindspore { namespace lite { -constexpr size_t kMinShapeSize = 2; -constexpr size_t kMinPadSize = 4; -constexpr int kOffsetTwo = 2; -constexpr int kOffsetThree = 3; OpParameter *PopulateAvgPoolParameter(const void *primitive) { auto pooling_prim = static_cast(primitive); MS_ASSERT(pooling_prim != nullptr); @@ -44,7 +40,7 @@ OpParameter *PopulateAvgPoolParameter(const void *primitive) { param->pool_mode_ = PoolMode_AvgPool; param->global_ = value->global(); auto strides = value->strides(); - if (strides == nullptr || strides->size() < kMinShapeSize) { + if (strides == nullptr || strides->size() < kMinShapeSizeTwo) { MS_LOG(ERROR) << "strides is invalid!"; free(param); return nullptr; @@ -52,7 +48,7 @@ OpParameter *PopulateAvgPoolParameter(const void *primitive) { param->stride_w_ = static_cast(*(strides->begin() + 1)); param->stride_h_ = static_cast(*(strides->begin())); auto pad = value->pad(); - if (pad != nullptr && pad->size() >= kMinPadSize) { + if (pad != nullptr && pad->size() >= kMinShapeSizeFour) { param->pad_u_ = static_cast(*(pad->begin())); param->pad_d_ = static_cast(*(pad->begin() + 1)); param->pad_l_ = static_cast(*(pad->begin() + kOffsetTwo)); @@ -60,7 +56,7 @@ OpParameter *PopulateAvgPoolParameter(const void *primitive) { } if (!param->global_) { auto kernel_size = value->kernel_size(); - if (kernel_size == nullptr || kernel_size->size() < kMinShapeSize) { + if (kernel_size == nullptr || kernel_size->size() < kMinShapeSizeTwo) { MS_LOG(ERROR) << "kernel_size is invalid"; free(param); return nullptr; @@ -126,8 +122,8 @@ OpParameter *PopulateMaxPoolParameter(const void *primitive) { if (!param->global_) { auto kernel_size = value->kernel_size(); auto strides = value->strides(); - if (kernel_size == nullptr || strides == nullptr || kernel_size->size() < kMinShapeSize || - strides->size() < kMinShapeSize) { + if (kernel_size == nullptr || strides == nullptr || kernel_size->size() < kMinShapeSizeTwo || + strides->size() < kMinShapeSizeTwo) { MS_LOG(ERROR) << "kernel_size or strides is invalid"; free(param); return nullptr; @@ -137,7 +133,7 @@ OpParameter *PopulateMaxPoolParameter(const void *primitive) { param->stride_w_ = static_cast(*(strides->begin() + 1)); param->stride_h_ = static_cast(*(strides->begin())); auto pad = value->pad(); - if (pad != nullptr && pad->size() >= kMinPadSize) { + if (pad != nullptr && pad->size() >= kMinShapeSizeFour) { param->pad_u_ = static_cast(*(pad->begin())); param->pad_d_ = static_cast(*(pad->begin() + 1)); param->pad_l_ = static_cast(*(pad->begin() + kOffsetTwo)); diff --git a/mindspore/lite/src/ops/populate/populate_register.h b/mindspore/lite/src/ops/populate/populate_register.h index 0537156cee2..1f248395f99 100644 --- a/mindspore/lite/src/ops/populate/populate_register.h +++ b/mindspore/lite/src/ops/populate/populate_register.h @@ -27,6 +27,10 @@ namespace mindspore { namespace lite { +constexpr int kOffsetTwo = 2; +constexpr int kOffsetThree = 3; +constexpr size_t kMinShapeSizeTwo = 2; +constexpr size_t kMinShapeSizeFour = 4; typedef OpParameter *(*ParameterGen)(const void *prim); class PopulateRegistry { diff --git a/mindspore/lite/tools/converter/converter_flags.cc b/mindspore/lite/tools/converter/converter_flags.cc index d97136bdf45..26062c85ddd 100644 --- a/mindspore/lite/tools/converter/converter_flags.cc +++ b/mindspore/lite/tools/converter/converter_flags.cc @@ -32,6 +32,7 @@ namespace converter { namespace { constexpr int kBase = 10; constexpr int kQuantBitNumInt16 = 16; +constexpr int kPathLengthUpperLimit = 1024; } // namespace Flags::Flags() { AddFlag(&Flags::fmkIn, "fmk", "Input model framework type. TF | TFLITE | CAFFE | MINDIR | ONNX", ""); @@ -428,7 +429,7 @@ std::string GetStrFromConfigFile(const std::string &file, const std::string &tar } #ifdef _WIN32 - char *real_path = _fullpath(resolved_path.get(), file.c_str(), 1024); + char *real_path = _fullpath(resolved_path.get(), file.c_str(), kPathLengthUpperLimit); #else char *real_path = realpath(file.c_str(), resolved_path.get()); #endif @@ -486,7 +487,6 @@ std::vector SplitStringToVector(const std::string &raw_str, const c } return res; } - } // namespace converter } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/registry/model_parser_registry.cc b/mindspore/lite/tools/converter/registry/model_parser_registry.cc index 93796131f3c..975df7a09e0 100644 --- a/mindspore/lite/tools/converter/registry/model_parser_registry.cc +++ b/mindspore/lite/tools/converter/registry/model_parser_registry.cc @@ -46,6 +46,5 @@ int ModelParserRegistry::RegParser(const FmkType fmk, ModelParserCreator creator instance->parsers_[fmk] = creator; return RET_OK; } - } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/optimizer/common/gllo_utils.cc b/mindspore/lite/tools/optimizer/common/gllo_utils.cc index ebb43ea0f87..7f3a6d8c99c 100644 --- a/mindspore/lite/tools/optimizer/common/gllo_utils.cc +++ b/mindspore/lite/tools/optimizer/common/gllo_utils.cc @@ -1494,9 +1494,7 @@ CNodePtr GenTransposeNode(const FuncGraphPtr &func_graph, const AnfNodePtr &inpu auto cnode = func_graph->NewCNode(trans_prim, {input_node, perm_node}); MS_ASSERT(cnode != nullptr); cnode->set_fullname_with_scope(cnode_name); - size_t input_size = 2; - size_t output_size = 1; - auto quant_params_holder = std::make_shared(input_size, output_size); + auto quant_params_holder = std::make_shared(kInputSizeTwo, 1); auto trans_insert_prim = GetValueNode(cnode->input(0)); trans_insert_prim->AddAttr("quant_params", quant_params_holder); return cnode;