From 615c977caa51dd28f15549696aa51310010d321c Mon Sep 17 00:00:00 2001 From: yujianfeng Date: Thu, 15 Jul 2021 19:45:20 +0800 Subject: [PATCH] code check cleanup --- .../ccsrc/frontend/optimizer/ad/kpynative.cc | 1 - mindspore/ccsrc/pipeline/jit/pipeline.cc | 4 ++-- mindspore/ccsrc/pipeline/jit/pipeline.h | 4 ++-- .../jit/static_analysis/static_analysis.cc | 1 - mindspore/core/abstract/prim_arrays.cc | 14 ++++++++------ mindspore/core/ir/anf.cc | 6 ++++-- mindspore/core/ops/assign.cc | 4 ++-- mindspore/core/utils/check_convert_utils.cc | 18 +++++++++--------- mindspore/core/utils/check_convert_utils.h | 2 +- 9 files changed, 28 insertions(+), 26 deletions(-) diff --git a/mindspore/ccsrc/frontend/optimizer/ad/kpynative.cc b/mindspore/ccsrc/frontend/optimizer/ad/kpynative.cc index 02c75063f8d..2f946897f09 100644 --- a/mindspore/ccsrc/frontend/optimizer/ad/kpynative.cc +++ b/mindspore/ccsrc/frontend/optimizer/ad/kpynative.cc @@ -959,7 +959,6 @@ void KPynativeCellImpl::SetSensAndWeights(const AnfNodePtrList &weights, bool ha } // Add sens parameter if (has_sens_arg) { - // sens parameter; auto sens_param = tape_->add_parameter(); sens_param->debug_info()->set_name("sens"); sens_param->set_abstract(last_node_adjoint_iter->second->out()->ToAbstract()->Broaden()); diff --git a/mindspore/ccsrc/pipeline/jit/pipeline.cc b/mindspore/ccsrc/pipeline/jit/pipeline.cc index 2c9ddb46c75..db4c7a70e3e 100644 --- a/mindspore/ccsrc/pipeline/jit/pipeline.cc +++ b/mindspore/ccsrc/pipeline/jit/pipeline.cc @@ -1338,7 +1338,7 @@ void ClearResAtexit() { trace::ClearTraceStack(); } -py::bytes PyEncrypt(char *plain_data, const size_t plain_len, char *key, const size_t key_len, std::string enc_mode) { +py::bytes PyEncrypt(char *plain_data, size_t plain_len, char *key, size_t key_len, const std::string &enc_mode) { size_t encrypt_len; auto encrypt_data = mindspore::Encrypt(&encrypt_len, reinterpret_cast(plain_data), plain_len, reinterpret_cast(key), key_len, enc_mode); @@ -1349,7 +1349,7 @@ py::bytes PyEncrypt(char *plain_data, const size_t plain_len, char *key, const s return py_encrypt_data; } -py::bytes PyDecrypt(std::string encrypt_data_path, char *key, const size_t key_len, std::string dec_mode) { +py::bytes PyDecrypt(const std::string &encrypt_data_path, char *key, size_t key_len, const std::string &dec_mode) { size_t decrypt_len; auto decrypt_data = mindspore::Decrypt(&decrypt_len, encrypt_data_path, reinterpret_cast(key), key_len, dec_mode); diff --git a/mindspore/ccsrc/pipeline/jit/pipeline.h b/mindspore/ccsrc/pipeline/jit/pipeline.h index 4084320d4c7..36f5bd433d8 100644 --- a/mindspore/ccsrc/pipeline/jit/pipeline.h +++ b/mindspore/ccsrc/pipeline/jit/pipeline.h @@ -160,8 +160,8 @@ bool InitExecDatasetVm(const std::string &queue_name, int64_t size, int64_t batc void ProcessVmArgInner(const py::tuple &args, const ResourcePtr &res, VectorRef *const arg_list); -py::bytes PyEncrypt(char *plain_data, const size_t plain_len, char *key, const size_t key_len, std::string enc_mode); -py::bytes PyDecrypt(std::string encrypt_data_path, char *key, const size_t key_len, std::string dec_mode); +py::bytes PyEncrypt(char *plain_data, size_t plain_len, char *key, size_t key_len, const std::string &enc_mode); +py::bytes PyDecrypt(const std::string &encrypt_data_path, char *key, size_t key_len, const std::string &dec_mode); bool PyIsCipherFile(const std::string &file_path); } // namespace pipeline } // namespace mindspore diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.cc b/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.cc index 032b39926fe..a93b9ff2e52 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.cc +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.cc @@ -222,7 +222,6 @@ EvalResultPtr AnalysisEngine::Eval(const AnfNodeConfigPtr &conf) { auto abstract = EvalValueNode(value_node, conf); eval_result = std::make_shared(abstract, std::make_shared()); } else if (node->isa()) { - // CheckNoStackInSameFuncGraph(conf); auto cnode = node->cast(); trace::TraceEvalCNodeEnter(conf); eval_result = EvalCNode(cnode, conf); diff --git a/mindspore/core/abstract/prim_arrays.cc b/mindspore/core/abstract/prim_arrays.cc index 9a16ae58a76..aeeafabbbad 100644 --- a/mindspore/core/abstract/prim_arrays.cc +++ b/mindspore/core/abstract/prim_arrays.cc @@ -801,7 +801,7 @@ AbstractBasePtr InferImplReshape(const AnalysisEnginePtr &, const PrimitivePtr & if (it_second != shape.end()) { MS_LOG(EXCEPTION) << "At most one component of input shape can be -1"; } - auto index = std::distance(shape.begin(), it_first); + auto index = LongToSize(std::distance(shape.begin(), it_first)); int64_t infer_value = x_num; int64_t infer_min_value = x_min_num; int64_t infer_max_value = x_max_num; @@ -1164,7 +1164,9 @@ AbstractBasePtr InferImplDynamicStitch(const AnalysisEnginePtr &, const Primitiv const AbstractBasePtrList &args_spec_list) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - (void)CheckAndConvertUtils::CheckInteger("input number", args_spec_list.size(), kEqual, 2, prim_name); + constexpr int64_t args_size = 2; + (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(args_spec_list.size()), kEqual, args_size, + prim_name); for (const auto &item : args_spec_list) { MS_EXCEPTION_IF_NULL(item); } @@ -1188,16 +1190,16 @@ AbstractBasePtr InferImplDynamicStitch(const AnalysisEnginePtr &, const Primitiv MS_LOG(EXCEPTION) << "The number of input[0] must be the same as input[0]!"; } - int indices_total_size = 0; + int64_t indices_total_size = 0; std::map types; - types.emplace("data0", data0->BuildType()); + (void)types.emplace("data0", data0->BuildType()); for (size_t i = 1; i < data.size(); ++i) { auto indicesi_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(indices[i]->BuildShape())[kShape]; auto datai_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(data[i]->BuildShape())[kShape]; if (indicesi_shape.size() > datai_shape.size()) { MS_LOG(EXCEPTION) << "The rank of indices[i] must be <= rank of data[i]!"; } - indices_total_size += indicesi_shape.size(); + indices_total_size += SizeToLong(indicesi_shape.size()); } std::set valid_types = ops::common_valid_types; auto infer_type = CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, prim_name); @@ -1206,7 +1208,7 @@ AbstractBasePtr InferImplDynamicStitch(const AnalysisEnginePtr &, const Primitiv for (size_t i = indices0_shape.size(); i < data0_shape.size(); ++i) { out_shape.push_back(data0_shape[i]); } - const size_t EXPAND_MAX = 10; + const int64_t EXPAND_MAX = 10; ShapeVector min_shape = out_shape; ShapeVector max_shape = out_shape; min_shape[0] = 1; diff --git a/mindspore/core/ir/anf.cc b/mindspore/core/ir/anf.cc index bbeaed863e2..3ef25ab473b 100644 --- a/mindspore/core/ir/anf.cc +++ b/mindspore/core/ir/anf.cc @@ -411,9 +411,11 @@ std::string GetVirtualNodeTargetFromInputs(const AnfNodePtr &node) { const size_t update_state_valid_input_index = 2; const size_t make_tuple_valid_input_index = 1; if (IsPrimitiveCNode(node, prim::kPrimUpdateState) && inputs.size() > update_state_valid_input_index) { - std::copy(inputs.begin() + update_state_valid_input_index, inputs.end(), std::back_inserter(real_inputs)); + (void)std::copy(inputs.begin() + SizeToLong(update_state_valid_input_index), inputs.end(), + std::back_inserter(real_inputs)); } else if (IsPrimitiveCNode(node, prim::kPrimMakeTuple) && inputs.size() > make_tuple_valid_input_index) { - std::copy(inputs.begin() + make_tuple_valid_input_index, inputs.end(), std::back_inserter(real_inputs)); + (void)std::copy(inputs.begin() + SizeToLong(make_tuple_valid_input_index), inputs.end(), + std::back_inserter(real_inputs)); } std::string first_input_target = kTargetUnDefined; bool has_diff_target = diff --git a/mindspore/core/ops/assign.cc b/mindspore/core/ops/assign.cc index a828ff1bcd0..4561d2988e1 100644 --- a/mindspore/core/ops/assign.cc +++ b/mindspore/core/ops/assign.cc @@ -30,8 +30,8 @@ AbstractBasePtr InferImplAssign(const abstract::AnalysisEnginePtr &, const Primi const AbstractBasePtrList &args_spec_list) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - (void)CheckAndConvertUtils::CheckInteger("Assign infer", (CheckAndConvertUtils::GetRemoveMonadAbsNum(args_spec_list)), - kEqual, 2, prim_name); + (void)CheckAndConvertUtils::CheckInteger( + "Assign infer", SizeToLong(CheckAndConvertUtils::GetRemoveMonadAbsNum(args_spec_list)), kEqual, 2, prim_name); auto check_types = common_valid_types; check_types.emplace(kBool); auto variable_type = args_spec_list[0]->BuildType(); diff --git a/mindspore/core/utils/check_convert_utils.cc b/mindspore/core/utils/check_convert_utils.cc index 5756504a0ec..94d701e3855 100644 --- a/mindspore/core/utils/check_convert_utils.cc +++ b/mindspore/core/utils/check_convert_utils.cc @@ -402,7 +402,7 @@ ShapeMap CheckAndConvertUtils::ConvertShapePtrToShapeMap(const BaseShapePtr &sha abstract::ShapePtr CheckAndConvertUtils::GetTensorInputShape(const std::string &prim_name, const std::vector &input_args, int64_t index) { - auto abstract = CheckAndConvertUtils::CheckArgs(prim_name, input_args, index); + auto abstract = CheckAndConvertUtils::CheckArgs(prim_name, input_args, LongToSize(index)); MS_EXCEPTION_IF_NULL(abstract); auto base_shape = abstract->BuildShape(); MS_EXCEPTION_IF_NULL(base_shape); @@ -517,7 +517,7 @@ TypePtr CheckAndConvertUtils::_CheckTypeSame(const std::mapisa()) { + if ((tensor_flag && !type->isa()) || (!tensor_flag && type->isa())) { buffer << "For " << prim_name << "'s " << "type is not same"; for (const auto &error_elem : args) { @@ -532,9 +532,9 @@ TypePtr CheckAndConvertUtils::_CheckTypeSame(const std::mapelement(); MS_EXCEPTION_IF_NULL(element); return_type = element->DeepCopy(); - types_id.emplace(element->type_id()); + (void)types_id.emplace(element->type_id()); } else { - types_id.emplace(type->type_id()); + (void)types_id.emplace(type->type_id()); return_type = type->DeepCopy(); } if (types_id.size() > 1) { @@ -587,13 +587,13 @@ void CheckAndConvertUtils::CheckSummaryParam(const AbstractBasePtr &name, const MS_EXCEPTION_IF_NULL(name); MS_EXCEPTION_IF_NULL(value); CheckMode(class_name); - CheckTypeValid("name", name->BuildType(), {kString}, class_name); + (void)CheckTypeValid("name", name->BuildType(), {kString}, class_name); auto s = GetValue(name->BuildValue()); if (s.empty()) { MS_EXCEPTION(ValueError) << "For 'name' the value should by valid string in " << class_name << ", but got an empty string."; } - CheckTypeValid("value", value->BuildType(), {kTensorType}, class_name); + (void)CheckTypeValid("value", value->BuildType(), {kTensorType}, class_name); } void CheckAndConvertUtils::CheckMode(const std::string &class_name) { @@ -660,15 +660,15 @@ int64_t CheckAndConvertUtils::GetAndCheckFormat(const ValuePtr &value) { } return data_format; } -int64_t CheckAndConvertUtils::GetRemoveMonadAbsNum(const AbstractBasePtrList &abs_list) { - int64_t remove_monad_count = abs_list.size(); +size_t CheckAndConvertUtils::GetRemoveMonadAbsNum(const AbstractBasePtrList &abs_list) { + size_t remove_monad_count = abs_list.size(); for (const auto &item : abs_list) { if (item->isa()) { --remove_monad_count; } } - for (int64_t i = 0; i < remove_monad_count; ++i) { + for (size_t i = 0; i < remove_monad_count; ++i) { if (abs_list[i]->isa()) { MS_EXCEPTION(UnknownError) << "The monad inputs of the node must at last of the node inputs."; } diff --git a/mindspore/core/utils/check_convert_utils.h b/mindspore/core/utils/check_convert_utils.h index d82b652d9c5..435966c2c32 100644 --- a/mindspore/core/utils/check_convert_utils.h +++ b/mindspore/core/utils/check_convert_utils.h @@ -307,7 +307,7 @@ class CheckAndConvertUtils { const std::string &arg_name); static void CheckMinMaxShape(const ShapeVector &shape, ShapeVector *min_shape, ShapeVector *max_shape); static int64_t GetAndCheckFormat(const ValuePtr &value); - static int64_t GetRemoveMonadAbsNum(const AbstractBasePtrList &abs_list); + static size_t GetRemoveMonadAbsNum(const AbstractBasePtrList &abs_list); private: static bool IsEqualVector(const std::vector &vec_1, const std::vector &vec_2);