diff --git a/include/api/status.h b/include/api/status.h index 8103cd93b12..ffa6d6ebc49 100644 --- a/include/api/status.h +++ b/include/api/status.h @@ -142,7 +142,7 @@ class MS_API Status { private: // api without std::string Status(enum StatusCode status_code, const std::vector &status_msg); - Status(const enum StatusCode code, int line_of_code, const char *file_name, const std::vector &extra); + Status(enum StatusCode code, int line_of_code, const char *file_name, const std::vector &extra); std::vector ToCString() const; std::vector GetErrDescriptionChar() const; std::vector SetErrDescription(const std::vector &err_description); diff --git a/mindspore/ccsrc/cxx_api/model/model_impl.cc b/mindspore/ccsrc/cxx_api/model/model_impl.cc index 955f9a42d00..e269268fb66 100644 --- a/mindspore/ccsrc/cxx_api/model/model_impl.cc +++ b/mindspore/ccsrc/cxx_api/model/model_impl.cc @@ -14,6 +14,7 @@ * limitations under the License. */ #include "cxx_api/model/model_impl.h" +#include #include "cxx_api/dlutils.h" namespace mindspore { diff --git a/mindspore/core/ir/tensor.cc b/mindspore/core/ir/tensor.cc index ca69a19b40b..c6570d8331d 100644 --- a/mindspore/core/ir/tensor.cc +++ b/mindspore/core/ir/tensor.cc @@ -197,7 +197,7 @@ class TensorStringifier { TensorStringifier(const T *data, size_t data_size, size_t ndim) : data_(data), data_size_(data_size), ndim_(ndim) {} ~TensorStringifier() = default; - std::string ToString(TypeId type, const ShapeVector &shape, bool use_comma) const { + std::string ToString(TypeId, const ShapeVector &shape, bool use_comma) const { constexpr auto valid = std::is_same::value || std::is_same::value || std::is_same::value || std::is_same::value || std::is_same::value || std::is_same::value || @@ -214,7 +214,8 @@ class TensorStringifier { std::ostringstream ss; if (data_size_ == 1 && ndim_ == 0) { // Scalar - OutputDataString(ss, 0, 0, 1, false, 0); + int max = 0; + OutputDataString(ss, 0, 0, 1, false, &max); return ss.str(); } @@ -919,7 +920,7 @@ static std::map> GroupingTensors(const TensorPt auto &chunk = chunks.back(); chunk.size += tensor->DataSize(); chunk.bytes += tensor_bytes; - chunk.tensors.emplace_back(tensor); + (void)chunk.tensors.emplace_back(tensor); } return group_info; } @@ -980,7 +981,7 @@ TensorPtrList Tensor::GetFlattenedTensors(const TensorPtrList &tensors) { TensorPtrList result_tensors; for (auto &entry : chunk_map) { auto &chunk_tensors = entry.second; - result_tensors.insert(result_tensors.end(), chunk_tensors.begin(), chunk_tensors.end()); + (void)result_tensors.insert(result_tensors.end(), chunk_tensors.begin(), chunk_tensors.end()); } return result_tensors; } @@ -1052,7 +1053,6 @@ const size_t CSRTensor::GetSizeAt(size_t index) const { return sizeof(int64_t); } MS_LOG(EXCEPTION) << "Invalid index: " << index << " for CSRTensor: " << ToString(); - return kTypeUnknown; } TensorPtr CSRTensor::GetTensorAt(size_t index) const { @@ -1069,7 +1069,6 @@ TensorPtr CSRTensor::GetTensorAt(size_t index) const { return std::make_shared(shape_[index - kShapeIdx], TypeIdToType(kNumberTypeInt64)); } MS_LOG(EXCEPTION) << "Invalid index: " << index << " for CSRTensor: " << ToString(); - return nullptr; } TensorPtr COOTensor::GetTensorAt(size_t index) const { diff --git a/mindspore/core/ir/tensor.h b/mindspore/core/ir/tensor.h index b70c56162cf..54cac758020 100644 --- a/mindspore/core/ir/tensor.h +++ b/mindspore/core/ir/tensor.h @@ -174,7 +174,6 @@ class MS_CORE_API Tensor final : public MetaTensor { /// /// \param[in] tensor [Tensor] The input tensor. explicit Tensor(const Tensor &tensor); - /// \brief Create tensor with given data type from another tensor. /// /// \param[in] tensor [Tensor] The input tensor. diff --git a/mindspore/core/load_mindir/anf_model_parser.cc b/mindspore/core/load_mindir/anf_model_parser.cc index e09193badc5..e69abd3934d 100644 --- a/mindspore/core/load_mindir/anf_model_parser.cc +++ b/mindspore/core/load_mindir/anf_model_parser.cc @@ -406,16 +406,16 @@ void MSANFModelParser::SetCNodePrimAttrAndAbstract(const mind_ir::NodeProto &nod abstract::AbstractTensorPtr MSANFModelParser::GetAbsTensorFromTensorProto(const mind_ir::TensorProto &tensor_proto) { ShapeVector shape; for (int i = 0; i < tensor_proto.dims_size(); ++i) { - shape.emplace_back(tensor_proto.dims(i)); + (void)shape.emplace_back(tensor_proto.dims(i)); } ShapeVector min_shape; for (int i = 0; i < tensor_proto.min_dims_size(); ++i) { - min_shape.emplace_back(tensor_proto.min_dims(i)); + (void)min_shape.emplace_back(tensor_proto.min_dims(i)); } ShapeVector max_shape; for (int i = 0; i < tensor_proto.max_dims_size(); ++i) { - max_shape.emplace_back(tensor_proto.max_dims(i)); + (void)max_shape.emplace_back(tensor_proto.max_dims(i)); } if (!tensor_proto.has_data_type()) { @@ -504,36 +504,38 @@ bool MSANFModelParser::GetTensorDataFromExternal(const mind_ir::TensorProto &ten return false; } data = plain_data.get(); - tenor_data_.emplace(tensor_proto.external_data().location(), std::move(plain_data)); + (void)tenor_data_.emplace(tensor_proto.external_data().location(), std::move(plain_data)); } else { // Read file std::basic_ifstream fid(file, std::ios::in | std::ios::binary); if (!fid) { MS_LOG(EXCEPTION) << "Open file '" << file << "' failed, please check the correct of the file."; } - fid.seekg(0, std::ios_base::end); + (void)fid.seekg(0, std::ios_base::end); size_t file_size = static_cast(fid.tellg()); fid.clear(); - fid.seekg(0); + (void)fid.seekg(0); auto plain_data = std::make_unique(file_size); constexpr Byte is_little_endian = 1; constexpr int byte_order_index = 0; - fid.read(plain_data.get(), file_size); + (void)fid.read(plain_data.get(), SizeToLong(file_size)); fid.close(); // if byte order is not same return false - if ((plain_data[byte_order_index] == is_little_endian) != little_endian()) { + if ((plain_data[byte_order_index] == is_little_endian) ^ little_endian()) { MS_LOG(ERROR) << "The byte order of export MindIr device and load MindIr device is not same!"; return false; } data = reinterpret_cast(plain_data.get()); - tenor_data_.emplace(tensor_proto.external_data().location(), - std::unique_ptr(reinterpret_cast(plain_data.release()))); + (void)tenor_data_.emplace(tensor_proto.external_data().location(), + std::unique_ptr(reinterpret_cast(plain_data.release()))); } } auto *tensor_data_buf = reinterpret_cast(tensor_info->data_c()); MS_EXCEPTION_IF_NULL(tensor_data_buf); - auto ret = common::huge_memcpy(tensor_data_buf, tensor_info->data().nbytes(), - data + tensor_proto.external_data().offset(), tensor_proto.external_data().length()); + MS_EXCEPTION_IF_NULL(data); + auto ret = + common::huge_memcpy(tensor_data_buf, tensor_info->data().nbytes(), data + tensor_proto.external_data().offset(), + LongToSize(tensor_proto.external_data().length())); if (ret != 0) { MS_LOG(ERROR) << "Build parameter occur memcpy_s error."; return false; @@ -1065,15 +1067,15 @@ bool MSANFModelParser::GetAttrValueForValueNodeWithType(const std::string &value mind_ir::TensorProto tensor_proto = attr_proto.tensors(0); if (tensor_proto.has_raw_data()) { // For real tensor. - ObtainValueNodeInTensorForm(value_node_name, tensor_proto); + (void)ObtainValueNodeInTensorForm(value_node_name, tensor_proto); } else { // For data type. - ObtainValueNodeInTypeForm(value_node_name, tensor_proto); + (void)ObtainValueNodeInTypeForm(value_node_name, tensor_proto); } break; } case mind_ir::AttributeProto_AttributeType_NONE: { - ObtainValueNodeInNoneForm(value_node_name); + (void)ObtainValueNodeInNoneForm(value_node_name); break; } case mind_ir::AttributeProto_AttributeType_UMONAD: { @@ -1158,7 +1160,7 @@ bool MSANFModelParser::GetAttrValueForValueNode(const std::string &value_node_na break; } case FORM_PARSE_NONE: { - ObtainValueNodeInNoneForm(value_node_name); + (void)ObtainValueNodeInNoneForm(value_node_name); break; } case FORM_PARSE_MONAD: { @@ -1350,10 +1352,6 @@ CNodePtr MSANFModelParser::BuildCNodeForFuncGraph(const FuncGraphPtr &outputFunc bool MSANFModelParser::BuildReturnForFuncGraph(const FuncGraphPtr &outputFuncGraph, const mind_ir::GraphProto &importProto) { MS_EXCEPTION_IF_NULL(outputFuncGraph); - if (importProto.output_size() <= 0 || importProto.output_size() > INT_MAX) { - MS_LOG(ERROR) << "importProto.output_size is: " << importProto.output_size(); - return false; - } std::vector inputs; if (importProto.output_size() > 1) { inputs.push_back(NewValueNode(prim::kPrimMakeTuple)); @@ -1402,10 +1400,6 @@ bool MSANFModelParser::BuildReturnForFuncGraph(const FuncGraphPtr &outputFuncGra bool MSANFModelParser::ImportNodesForGraph(const FuncGraphPtr &outputFuncGraph, const mind_ir::GraphProto &importProto) { MS_EXCEPTION_IF_NULL(outputFuncGraph); - if (importProto.node_size() < 0 || importProto.node_size() > INT_MAX) { - MS_LOG(ERROR) << "importProto.node_size is: " << importProto.node_size(); - return false; - } MS_LOG(DEBUG) << "The node size: " << importProto.node_size(); CNodePtr cnode_ptr = nullptr; for (int i = 0; i < importProto.node_size(); ++i) { @@ -1514,11 +1508,10 @@ bool MSANFModelParser::SetValueForTopGraphParameter(const FuncGraphPtr &topGraph const std::map &weights) { size_t fv_param_count = 0; auto parameters = topGraph->parameters(); - for (int i = parameters.size() - 1; i >= 0; --i) { - size_t index = IntToSize(i); - auto parameter = parameters[index]->cast(); + for (int64_t i = SizeToLong(parameters.size()) - 1; i >= 0; --i) { + auto parameter = parameters[i]->cast(); if (parameter == nullptr) { - MS_LOG(ERROR) << "AnfNode " << parameters[index]->DebugString() << " should be Parameter."; + MS_LOG(ERROR) << "AnfNode " << parameters[i]->DebugString() << " should be Parameter."; return false; } auto type = parameter->Type(); @@ -1633,7 +1626,7 @@ const LayoutMap MSANFModelParser::ParseLayout(const mind_ir::ModelProto &model_p } std::vector tensor_map; for (int num = 0; num < layout_proto.tensor_map_int_size(); ++num) { - tensor_map.emplace_back(layout_proto.tensor_map_int(num)); + (void)tensor_map.emplace_back(layout_proto.tensor_map_int(num)); } std::vector slice_shape; for (int num = 0; num < layout_proto.slice_shape_int_size(); ++num) { @@ -1759,7 +1752,7 @@ abstract::AbstractBasePtr MSANFModelParser::BuildAbstractFunction(const mind_ir: MS_LOG(WARNING) << "Can't get the abstract of function union closure: " << item_proto.DebugString(); return nullptr; } - func_list.emplace_back(item_abstract->cast()); + (void)func_list.emplace_back(item_abstract->cast()); } return std::make_shared(func_list); } @@ -1777,7 +1770,7 @@ void MSANFModelParser::CorrectFuncGraph(const FuncGraphPtr &root) { auto valid = std::all_of(inputs.begin(), inputs.end(), [](const AnfNodePtr &arg) -> bool { return arg->abstract() != nullptr; }); if (valid) { - ValidMindir(root); + (void)ValidMindir(root); } else { MS_LOG(INFO) << "There are some nullptr of abstract in the top function graph parameters." << root->DumpText(); } diff --git a/mindspore/core/load_mindir/anf_model_parser.h b/mindspore/core/load_mindir/anf_model_parser.h index 41847e31530..ea30201bcac 100644 --- a/mindspore/core/load_mindir/anf_model_parser.h +++ b/mindspore/core/load_mindir/anf_model_parser.h @@ -64,7 +64,7 @@ using LayoutMap = std::map; class MSANFModelParser { public: - MSANFModelParser() : producer_name_(""), model_version_(""), ir_version_("") {} + MSANFModelParser() = default; ~MSANFModelParser() = default; static void LoadTensorMapClear() { load_tensor_map_.clear(); } @@ -92,7 +92,7 @@ class MSANFModelParser { bool BuildAttrForFuncGraph(const FuncGraphPtr &outputFuncGraph, const mind_ir::GraphProto &importProto); bool ImportParametersForGraph(const FuncGraphPtr &outputFuncGraph, const mind_ir::GraphProto &importProto); bool ImportNodesForGraph(const FuncGraphPtr &outputFuncGraph, const mind_ir::GraphProto &importProto); - bool BuildParameterForFuncGraph(const ParameterPtr &node, const mind_ir::TensorProto &tensor_proto); + bool BuildParameterForFuncGraph(const ParameterPtr &node, const mind_ir::TensorProto ¶meter_proto); bool SetValueForTopGraphParameter(const FuncGraphPtr &topGraph, const std::map &weights); bool GetTensorDataFromExternal(const mind_ir::TensorProto &tensor_proto, const tensor::TensorPtr &tensor_info); bool BuildInputForFuncGraph(const ParameterPtr &node, const mind_ir::ValueInfoProto &value_proto); @@ -116,13 +116,13 @@ class MSANFModelParser { void SetCNodePrimAttrAndAbstract(const mind_ir::NodeProto &node_proto, const CNodePtr &cnode_ptr); bool ObtainValueNodeInTensorForm(const string &value_node_name, const mind_ir::TensorProto &attr_tensor); bool ObtainValueNodeInTupleTensorForm(const string &value_node_name, const mind_ir::AttributeProto &attr_proto); - bool GetAttrValueForValueNode(const std::string &value_node_name, const mind_ir::AttributeProto &attr_tensor); + bool GetAttrValueForValueNode(const std::string &value_node_name, const mind_ir::AttributeProto &attr_proto); bool GetAttrValueForValueNodeWithType(const std::string &value_node_name, const mind_ir::AttributeProto &attr_proto); bool ObtainValueNodeInTypeForm(const string &value_node_name, const mind_ir::TensorProto &attr_tensor); bool ObtainValueNodeInNoneForm(const std::string &value_node_name); bool ObtainValueNodeInMonadForm(const std::string &value_node_name, const mind_ir::AttributeProto &attr_proto); ValuePtr ObtainValueInSequenceForm(const mind_ir::AttributeProto &attr_proto); - bool little_endian() { return little_endian_; } + bool little_endian() const { return little_endian_; } mindspore::HashMap GetAbstractForNode( const mind_ir::AttributeProto &attr_proto); AnfNodePtr GetAnfNode(const std::string &node_name); @@ -139,7 +139,7 @@ class MSANFModelParser { mindspore::HashMap anfnode_build_map_; std::string mindir_path_; const unsigned char *mindir_dec_key_{nullptr}; - size_t mindir_key_size_; + size_t mindir_key_size_{0}; std::string mindir_dec_mode_; bool little_endian_ = common::IsLittleByteOrder(); std::map> tenor_data_; diff --git a/mindspore/core/load_mindir/infer_mindir.cc b/mindspore/core/load_mindir/infer_mindir.cc index 1397acbbaf9..985264dfa71 100644 --- a/mindspore/core/load_mindir/infer_mindir.cc +++ b/mindspore/core/load_mindir/infer_mindir.cc @@ -50,7 +50,7 @@ class MindIREngine { void InferParameter(const AnfNodePtr &node); void InferValueNode(const AnfNodePtr &node); void InferCNode(const AnfNodePtr &node); - void EvalAbstractFunction(const abstract::AbstractFuncAtomPtr &abstractFunc, const CNodePtr &node, + void EvalAbstractFunction(const abstract::AbstractFuncAtomPtr &func, const CNodePtr &node, const AbstractBasePtrListPtr &args); void EvalPrimitiveAbastract(const abstract::PrimitiveAbstractClosurePtr &func, const CNodePtr &node, const AbstractBasePtrListPtr &args); diff --git a/mindspore/core/load_mindir/load_model.cc b/mindspore/core/load_mindir/load_model.cc index c008d6d4e5b..6fab5e345a0 100644 --- a/mindspore/core/load_mindir/load_model.cc +++ b/mindspore/core/load_mindir/load_model.cc @@ -61,8 +61,8 @@ bool get_all_files(const std::string &dir_in, std::vector *files) { return false; } if (S_ISDIR(st.st_mode)) { - ret = static_cast(get_all_files(name, files)); - if (!ret) { + ret = get_all_files(name, files); + if (ret) { MS_LOG(ERROR) << "Get files failed, ret is : " << ret; closedir(open_dir); return false; @@ -182,7 +182,7 @@ std::vector MindIRLoader::LoadPreprocess(const std::string &file_na return map_jsons; } -std::vector MindIRLoader::LoadMindIRs(std::vector file_names) { +std::vector MindIRLoader::LoadMindIRs(const std::vector &file_names) { std::vector funcgraph_vec; MS_LOG(DEBUG) << "Load multiple MindIR files."; for (const auto &file_name : file_names) { @@ -245,12 +245,12 @@ FuncGraphPtr MindIRLoader::LoadMindIR(const std::string &file_name) { return nullptr; } // Load parameter into graph - if (endsWith(std::string(abs_path_buff), "_graph.mindir") && origin_model.graph().parameter_size() == 0) { + if (endsWith(std::string(abs_path_buff), "_graph.mindir") && (origin_model.graph().parameter_size() == 0)) { if (strlen(abs_path_buff) < strlen("graph.mindir")) { MS_LOG(ERROR) << "The abs_path_buff length is less than 'graph.mindir'."; return nullptr; } - int path_len = SizeToInt(strlen(abs_path_buff) - strlen("graph.mindir")); + size_t path_len = strlen(abs_path_buff) - strlen("graph.mindir"); string var_path = std::string(abs_path_buff).substr(0, path_len); var_path += "variables"; std::ifstream ifs(var_path); @@ -270,10 +270,6 @@ FuncGraphPtr MindIRLoader::LoadMindIR(const std::string &file_name) { return nullptr; } - if (param_graph.parameter_size() < 0 || param_graph.parameter_size() > INT_MAX) { - MS_LOG(ERROR) << "param_graph.parameter_size() is : " << param_graph.parameter_size(); - return nullptr; - } for (int param_index = 0; param_index < param_graph.parameter_size(); param_index++) { mind_ir::TensorProto *param_proto = mod_graph->add_parameter(); param_proto->set_name(param_graph.parameter(param_index).name()); diff --git a/mindspore/core/load_mindir/load_model.h b/mindspore/core/load_mindir/load_model.h index d0dd08d50f4..68cfbb46a30 100644 --- a/mindspore/core/load_mindir/load_model.h +++ b/mindspore/core/load_mindir/load_model.h @@ -42,7 +42,7 @@ class MS_CORE_API MindIRLoader { void InitModelParser(MSANFModelParser *model_parser); FuncGraphPtr LoadMindIR(const void *buffer, const size_t &size); FuncGraphPtr LoadMindIR(const std::string &file_name); - std::vector LoadMindIRs(const std::vector file_names); + std::vector LoadMindIRs(const std::vector &file_names); std::vector LoadPreprocess(const std::string &file_name); private: diff --git a/mindspore/core/utils/anf_utils.cc b/mindspore/core/utils/anf_utils.cc index e97107dd05e..c4ee6538ac7 100644 --- a/mindspore/core/utils/anf_utils.cc +++ b/mindspore/core/utils/anf_utils.cc @@ -26,8 +26,6 @@ namespace mindspore { namespace { -const PrimitiveSet follow_first_input_prims = {prim::kPrimDepend, prim::kPrimLoad}; - class AbstractMutexManager { public: static AbstractMutexManager &GetInstance() { @@ -98,8 +96,7 @@ AnfNodePtr NewCustomActorNode(const CustomActorInfoPtr &actor_info, const FuncGr } } // namespace -AbstractScope::AbstractScope(std::recursive_mutex *mu) { - mu_ = mu; +AbstractScope::AbstractScope(std::recursive_mutex *mu) : mu_(mu) { if (mu_ != nullptr) { mu_->lock(); } @@ -397,6 +394,7 @@ int64_t AnfUtils::GetIntValue(const AnfNodePtr &anf_node) { std::pair AnfUtils::VisitKernel(const AnfNodePtr &anf_node, size_t index) { MS_EXCEPTION_IF_NULL(anf_node); + const PrimitiveSet follow_first_input_prims = {prim::kPrimDepend, prim::kPrimLoad}; if (anf_node->isa()) { return std::make_pair(anf_node, 0); } else if (anf_node->isa()) { diff --git a/mindspore/core/utils/check_convert_utils.cc b/mindspore/core/utils/check_convert_utils.cc index 4b1f30008c7..11399e66774 100644 --- a/mindspore/core/utils/check_convert_utils.cc +++ b/mindspore/core/utils/check_convert_utils.cc @@ -535,10 +535,10 @@ TypePtr CheckAndConvertUtils::CheckTensorTypeSame(const std::map order_set; for (auto const &valid_type : check_list) { if (valid_type->isa()) { - order_set.emplace(valid_type->ToString()); + (void)order_set.emplace(valid_type->ToString()); break; } else { - order_set.emplace("Tensor[" + valid_type->ToString() + "]"); + (void)order_set.emplace("Tensor[" + valid_type->ToString() + "]"); } } for (auto const &error_item : order_set) { @@ -592,7 +592,6 @@ TypePtr CheckAndConvertUtils::CheckSparseTensorTypeValid(const std::string &type MS_EXCEPTION(TypeError) << "For Primitive[" << prim_name << "], the input argument[" << type_name << "] cast to SparseTensorTypePtr failed! Get type : " << type->ToString() << "."; } - return nullptr; } ShapeVector CheckAndConvertUtils::CheckTensorIntValue(const std::string &type_name, const ValuePtr &value, @@ -645,16 +644,16 @@ TypePtr CheckAndConvertUtils::CheckTensorSubClass(const string &type_name, const if (is_mix) { for (const auto &item : template_types) { - order_set.emplace(item->ToString()); + (void)order_set.emplace(item->ToString()); } } for (const auto &item : template_types) { if (item->isa()) { - order_set.emplace(item->ToString()); + (void)order_set.emplace(item->ToString()); continue; } - order_set.emplace("Tensor[" + item->ToString() + "]"); + (void)order_set.emplace("Tensor[" + item->ToString() + "]"); } for (const auto &item : order_set) { @@ -692,7 +691,7 @@ TypePtr CheckAndConvertUtils::CheckSubClass(const std::string &type_name, const TypePtr CheckAndConvertUtils::CheckScalarOrTensorTypesSame(const std::map &args, const std::set &valid_values, - const std::string &prim_name, const bool allow_mix) { + const std::string &prim_name, bool allow_mix) { (void)_CheckTypeSame(args, prim_name, allow_mix); return CheckTensorSubClass(args.begin()->first, args.begin()->second, valid_values, prim_name, true); } diff --git a/mindspore/core/utils/check_convert_utils.h b/mindspore/core/utils/check_convert_utils.h index 277a376dc54..d7d42d41e30 100644 --- a/mindspore/core/utils/check_convert_utils.h +++ b/mindspore/core/utils/check_convert_utils.h @@ -26,7 +26,6 @@ #include "abstract/param_validator.h" #include "base/base.h" #include "ir/anf.h" -#include "ir/dtype/type_id.h" #include "include/api/format.h" #include "utils/log_adapter.h" #if __has_include("include/mindapi/base/types.h") @@ -301,12 +300,12 @@ class MS_CORE_API CheckAndConvertUtils { static void CheckSummaryParam(const AbstractBasePtr &name, const AbstractBasePtr &value, const std::string &class_name); static void CheckMode(const std::string &class_name); - static std::vector CheckIntOrTupleInt(const std::string &prim_name, const ValuePtr &attr, - const std::string &arg_name); - static std::vector CheckTupleInt(const std::string &prim_name, const ValuePtr &attr, - const std::string &arg_name); - static std::vector CheckListInt(const std::string &prim_name, const ValuePtr &attr, - const std::string &arg_name); + static std::vector CheckIntOrTupleInt(const std::string &arg_name, const ValuePtr &attr, + const std::string &prim_name); + static std::vector CheckTupleInt(const std::string &arg_name, const ValuePtr &attr, + const std::string &prim_name); + static std::vector CheckListInt(const std::string &arg_name, const ValuePtr &attr, + const std::string &prim_name); static void CheckMinMaxShape(const ShapeVector &shape, ShapeVector *min_shape, ShapeVector *max_shape); static int64_t GetAndCheckFormat(const ValuePtr &value); static size_t GetRemoveMonadAbsNum(const AbstractBasePtrList &abs_list); diff --git a/mindspore/core/utils/compact_set.h b/mindspore/core/utils/compact_set.h index 270ebf04848..5b104b55cad 100644 --- a/mindspore/core/utils/compact_set.h +++ b/mindspore/core/utils/compact_set.h @@ -77,7 +77,7 @@ class CompactSet { T pop() { T e = std::move(data_.front()); - data_.erase(data_.begin()); + (void)data_.erase(data_.begin()); return e; } diff --git a/mindspore/core/utils/info.cc b/mindspore/core/utils/info.cc index 3e69aa8ba48..4be9c6c42c2 100644 --- a/mindspore/core/utils/info.cc +++ b/mindspore/core/utils/info.cc @@ -15,10 +15,8 @@ */ #include "utils/info.h" -#include #include #include -#include #include "ir/anf.h" #include "ir/graph_utils.h" #include "ir/func_graph.h" diff --git a/mindspore/core/utils/label.h b/mindspore/core/utils/label.h index 904f05228c5..885db8b393b 100644 --- a/mindspore/core/utils/label.h +++ b/mindspore/core/utils/label.h @@ -19,7 +19,6 @@ #include #include #include -#include #include "utils/hash_map.h" #include "ir/anf.h" @@ -27,7 +26,8 @@ namespace mindspore { namespace label_manage { enum class TraceLabelType { kShortSymbol, kFullName, kWithUniqueId }; MS_CORE_API TraceLabelType GetGlobalTraceLabelType(); -MS_CORE_API std::string Label(const DebugInfoPtr &debug_info, TraceLabelType trace_type = TraceLabelType::kShortSymbol); +MS_CORE_API std::string Label(const DebugInfoPtr &debug_info, + TraceLabelType trace_label = TraceLabelType::kShortSymbol); } // namespace label_manage } // namespace mindspore diff --git a/mindspore/core/utils/log_adapter.h b/mindspore/core/utils/log_adapter.h index 18c6b02b02b..2bc03f3f3cb 100644 --- a/mindspore/core/utils/log_adapter.h +++ b/mindspore/core/utils/log_adapter.h @@ -17,8 +17,8 @@ #ifndef MINDSPORE_CORE_UTILS_LOG_ADAPTER_H_ #define MINDSPORE_CORE_UTILS_LOG_ADAPTER_H_ -#include -#include +#include +#include #include #include #include @@ -45,7 +45,6 @@ static constexpr size_t GetRelPathPos() noexcept { return sizeof(__FILE__) > sizeof(LOG_HDR_FILE_REL_PATH) ? sizeof(__FILE__) - sizeof(LOG_HDR_FILE_REL_PATH) : 0; } - namespace mindspore { /// \brief The handler map for ACL. MS_CORE_API extern std::map acl_handle_map; @@ -231,11 +230,7 @@ MS_EXPORT extern enum MsLogLevel this_thread_max_log_level; MS_EXPORT extern thread_local enum MsLogLevel this_thread_max_log_level; class TryCatchGuard { public: - TryCatchGuard() { - origin_log_level_ = this_thread_max_log_level; - this_thread_max_log_level = MsLogLevel::WARNING; - } - + TryCatchGuard() : origin_log_level_(this_thread_max_log_level) { this_thread_max_log_level = MsLogLevel::WARNING; } ~TryCatchGuard() { this_thread_max_log_level = origin_log_level_; } private: @@ -330,11 +325,11 @@ inline bool IS_OUTPUT_ON(enum MsLogLevel level) noexcept(true) { } \ } while (0) -#define MS_EXCEPTION_IF_ZERO(name, value) \ - do { \ - if (value == 0) { \ - MS_LOG(EXCEPTION) << ": The " << name << " is zero."; \ - } \ +#define MS_EXCEPTION_IF_ZERO(name, value) \ + do { \ + if ((value) == 0) { \ + MS_LOG(EXCEPTION) << ": The " << (name) << " is zero."; \ + } \ } while (0) #define MS_ERROR_IF_NULL(ptr) \ diff --git a/mindspore/core/utils/misc.h b/mindspore/core/utils/misc.h index 98aed94b5d9..915d5590986 100644 --- a/mindspore/core/utils/misc.h +++ b/mindspore/core/utils/misc.h @@ -17,7 +17,6 @@ #ifndef MINDSPORE_CORE_UTILS_MISC_H_ #define MINDSPORE_CORE_UTILS_MISC_H_ -#include #include #include #include diff --git a/mindspore/core/utils/ms_context.cc b/mindspore/core/utils/ms_context.cc index 61c6bac7a51..2c1d9e39484 100644 --- a/mindspore/core/utils/ms_context.cc +++ b/mindspore/core/utils/ms_context.cc @@ -15,11 +15,11 @@ */ #include "utils/ms_context.h" -#include #include #include #include #include +#include #include "ir/tensor.h" #include "utils/ms_utils.h" diff --git a/mindspore/core/utils/ms_context.h b/mindspore/core/utils/ms_context.h index d8513f2b1ab..908f8622d13 100644 --- a/mindspore/core/utils/ms_context.h +++ b/mindspore/core/utils/ms_context.h @@ -20,14 +20,11 @@ #include #include #include -#include #include -#include #include #include "utils/log_adapter.h" #include "utils/ms_utils.h" #ifdef ENABLE_TDTQUE -#include "pybind11/pybind11.h" #include "minddata/dataset/engine/device_queue_impl/tdt/tdt_handle.h" using mindspore::dataset::TdtHandle; #endif @@ -146,7 +143,7 @@ enum MsCtxParam : unsigned { class MS_CORE_API MsContext { public: - MsContext(const std::string &backend_policy, const std::string &target); + MsContext(const std::string &policy, const std::string &target); ~MsContext() = default; MsContext(const MsContext &) = delete; MsContext &operator=(const MsContext &) = delete; diff --git a/mindspore/core/utils/ordered_set.h b/mindspore/core/utils/ordered_set.h index 5f45c3ab889..158d11844d3 100644 --- a/mindspore/core/utils/ordered_set.h +++ b/mindspore/core/utils/ordered_set.h @@ -98,9 +98,9 @@ class OrderedSet { // insert an element to the end of OrderedSet. std::pair insert(const element_type &e) { return insert(ordered_data_.end(), e); } - void push_back(const element_type &e) { (void)insert(ordered_data_.end(), e); } + void push_back(const element_type &e) const { (void)insert(ordered_data_.end(), e); } - void push_front(const element_type &e) { (void)insert(ordered_data_.begin(), e); } + void push_front(const element_type &e) const { (void)insert(ordered_data_.begin(), e); } // Remove an element, if removed return true, otherwise return false bool erase(const element_type &e) { @@ -428,7 +428,7 @@ class OrderedSet> { const element_type &front() const { return ordered_data_.front(); } // Return true if there are no common elements. - bool is_disjoint(const OrderedSet &other) { + bool is_disjoint(const OrderedSet &other) const { return std::all_of(begin(), end(), [&other](const auto &e) { return !other.contains(e); }); } diff --git a/mindspore/core/utils/overload.h b/mindspore/core/utils/overload.h index 3b027263587..8d3e4d57325 100644 --- a/mindspore/core/utils/overload.h +++ b/mindspore/core/utils/overload.h @@ -34,7 +34,9 @@ std::ostream &operator<<(std::ostream &out, const std::vector &v) { size_t last = v.size() - 1; for (size_t i = 0; i < v.size(); ++i) { out << v[i]; - if (i != last) out << ", "; + if (i != last) { + out << ", "; + } } out << "]"; return out; diff --git a/mindspore/core/utils/profile.cc b/mindspore/core/utils/profile.cc index 52d0219d0df..6b5f86a8b93 100644 --- a/mindspore/core/utils/profile.cc +++ b/mindspore/core/utils/profile.cc @@ -192,9 +192,9 @@ void Profile::Pop(void) noexcept { ctx_ptr_ = ctx_ptr_->parent_; } -ProfContext::ProfContext(const std::string &name, ProfileBase *const prof) : name_(name), prof_(prof) { +ProfContext::ProfContext(const std::string &name, ProfileBase *const prof) + : name_(name), prof_(prof), time_info_(nullptr) { // Initialize a subcontext. - time_info_ = nullptr; if (prof == nullptr || IsTopContext()) { parent_ = nullptr; } else { diff --git a/mindspore/core/utils/profile.h b/mindspore/core/utils/profile.h index d302aa749bc..fcbf4543358 100644 --- a/mindspore/core/utils/profile.h +++ b/mindspore/core/utils/profile.h @@ -35,6 +35,7 @@ class ProfileBase; struct TimeInfo { explicit TimeInfo(double time = -1.0) : time_(time), dict_(nullptr), actionNum_(0) {} TimeInfo(const TimeInfo &) = delete; + TimeInfo &operator=(const TimeInfo &) = delete; ~TimeInfo(); double time_; @@ -49,7 +50,7 @@ class MS_CORE_API ProfContext { friend class ProfTransaction; public: - ProfContext(const std::string &name, ProfileBase *prof); + ProfContext(const std::string &name, ProfileBase *const prof); ~ProfContext(); ProfContext(const ProfContext &) = delete; @@ -103,6 +104,7 @@ class MS_CORE_API ProfTransaction { explicit ProfTransaction(const ProfileBase *prof); explicit ProfTransaction(ProfContext *const ctx) : ctx_(ctx) {} ProfTransaction(const ProfTransaction &) = delete; + ProfTransaction &operator=(const ProfTransaction &) = delete; ~ProfTransaction(); template @@ -146,7 +148,7 @@ class MS_CORE_API DumpTime { DumpTime &operator=(const DumpTime &) = delete; static DumpTime &GetInstance(); void set_file_path(const std::string &save_path) { file_path_ = save_path; } - void Record(const std::string &name, const double time, const bool is_start); + void Record(const std::string &step_name, const double time, const bool is_start); void Save(); private: @@ -157,10 +159,7 @@ class MS_CORE_API DumpTime { }; struct TimeStat { - TimeStat() { - time_ = 0.0; - count_ = 0; - } + TimeStat() : time_(0.0), count_(0) {} ~TimeStat() = default; void operator+=(double t) { diff --git a/mindspore/core/utils/signal.h b/mindspore/core/utils/signal.h index a47e54b1173..6937855e1a3 100644 --- a/mindspore/core/utils/signal.h +++ b/mindspore/core/utils/signal.h @@ -42,7 +42,7 @@ template class Signal { public: template - void operator()(Args &&... args) { + void operator()(Args &&... args) const { for (auto &slot : slots_) { if (slot->callback != nullptr) { slot->callback(std::forward(args)...); @@ -66,4 +66,4 @@ class Signal { }; } // namespace mindspore -#endif // MINDSPORE_CORE_UTILS_EVENT_H_ +#endif // MINDSPORE_CORE_UTILS_SIGNAL_H_ diff --git a/mindspore/core/utils/system/base.h b/mindspore/core/utils/system/base.h index d0a453be481..0d3f5a2c0bf 100644 --- a/mindspore/core/utils/system/base.h +++ b/mindspore/core/utils/system/base.h @@ -97,7 +97,7 @@ class Platform { // check the null point #define MS_EXCEPT_CHECK_NULL(value) \ do { \ - if (value == nullptr) { \ + if ((value) == nullptr) { \ MS_LOG(EXCEPTION) << "The value is null."; \ } \ } while (0) diff --git a/mindspore/core/utils/system/crc32c.h b/mindspore/core/utils/system/crc32c.h index 774a39f5c06..c676f31f72d 100644 --- a/mindspore/core/utils/system/crc32c.h +++ b/mindspore/core/utils/system/crc32c.h @@ -17,7 +17,7 @@ #ifndef MINDSPORE_CORE_UTILS_SYSTEM_CRC32C_H_ #define MINDSPORE_CORE_UTILS_SYSTEM_CRC32C_H_ -#include +#include #include #include "utils/system/base.h" #include "utils/system/env.h" @@ -26,7 +26,7 @@ namespace mindspore { namespace system { // Align n to (1 << m) byte boundary -#define MEM_ALIGN(n, m) ((n + ((1 << (m)) - 1)) & ~((1 << (m)) - 1)) +#define MEM_ALIGN(n, m) (((n) + ((1 << (m)) - 1)) & (~((1 << (m)) - 1))) // Masked for crc. static constexpr uint32 kMaskDelta = 0xa282ead8ul; diff --git a/mindspore/core/utils/system/file_system.h b/mindspore/core/utils/system/file_system.h index 938d1802ed3..516b8176fa8 100644 --- a/mindspore/core/utils/system/file_system.h +++ b/mindspore/core/utils/system/file_system.h @@ -17,8 +17,8 @@ #ifndef MINDSPORE_CORE_UTILS_SYSTEM_FILE_SYSTEM_H_ #define MINDSPORE_CORE_UTILS_SYSTEM_FILE_SYSTEM_H_ -#include #include +#include #include #include #include diff --git a/mindspore/core/utils/tensor_construct_utils.cc b/mindspore/core/utils/tensor_construct_utils.cc index e91da7c5eb5..eafc529116c 100644 --- a/mindspore/core/utils/tensor_construct_utils.cc +++ b/mindspore/core/utils/tensor_construct_utils.cc @@ -19,9 +19,9 @@ #include #include namespace mindspore { -tensor::TensorPtr TensorConstructUtils::CreateZerosTensor(const TypePtr &type_ptr, const std::vector &shape) { - MS_EXCEPTION_IF_NULL(type_ptr); - auto type_id = ExtractTypeId(type_ptr); +tensor::TensorPtr TensorConstructUtils::CreateZerosTensor(const TypePtr &type, const std::vector &shape) { + MS_EXCEPTION_IF_NULL(type); + auto type_id = ExtractTypeId(type); tensor::TensorPtr tensor = std::make_shared(type_id, shape); size_t mem_size = IntToSize(tensor->ElementsNum()); auto tensor_data = tensor->data_c(); @@ -32,9 +32,9 @@ tensor::TensorPtr TensorConstructUtils::CreateZerosTensor(const TypePtr &type_pt return tensor; } -tensor::TensorPtr TensorConstructUtils::CreateOnesTensor(const TypePtr &type_ptr, const std::vector &shape) { - MS_EXCEPTION_IF_NULL(type_ptr); - auto type_id = ExtractTypeId(type_ptr); +tensor::TensorPtr TensorConstructUtils::CreateOnesTensor(const TypePtr &type, const std::vector &shape) { + MS_EXCEPTION_IF_NULL(type); + auto type_id = ExtractTypeId(type); tensor::TensorPtr tensor = std::make_shared(type_id, shape); const size_t &mem_size = IntToSize(tensor->ElementsNum()); auto tensor_data = tensor->data_c(); @@ -65,30 +65,31 @@ tensor::TensorPtr TensorConstructUtils::CreateOnesTensor(const TypePtr &type_ptr }; const auto &tensor_type = tensor->data_type(); - if (!type_dict.count(tensor_type)) { + auto iter = type_dict.find(tensor_type); + if (iter == type_dict.end()) { MS_LOG(EXCEPTION) << "unsupported data type: " << tensor_type; } - type_dict[tensor_type](); + iter->second(); return tensor; } -tensor::TensorPtr TensorConstructUtils::CreateTensor(const TypePtr &type_ptr, const std::vector &shape, +tensor::TensorPtr TensorConstructUtils::CreateTensor(const TypePtr &type, const std::vector &shape, void *data) { - MS_EXCEPTION_IF_NULL(type_ptr); - auto type_id = ExtractTypeId(type_ptr); + MS_EXCEPTION_IF_NULL(type); + auto type_id = ExtractTypeId(type); tensor::TensorPtr tensor = std::make_shared(type_id, shape, data, type_id); return tensor; } -TypeId TensorConstructUtils::ExtractTypeId(const TypePtr &type_ptr) { - MS_EXCEPTION_IF_NULL(type_ptr); +TypeId TensorConstructUtils::ExtractTypeId(const TypePtr &type) { + MS_EXCEPTION_IF_NULL(type); TypeId type_id; - if (type_ptr->isa()) { - auto tensor_type = type_ptr->cast(); + if (type->isa()) { + auto tensor_type = type->cast(); MS_EXCEPTION_IF_NULL(tensor_type); type_id = tensor_type->element()->type_id(); } else { - type_id = type_ptr->type_id(); + type_id = type->type_id(); } return type_id; } diff --git a/mindspore/core/utils/trace_base.cc b/mindspore/core/utils/trace_base.cc index f14c32a54c4..6dd7a04e5a6 100644 --- a/mindspore/core/utils/trace_base.cc +++ b/mindspore/core/utils/trace_base.cc @@ -195,7 +195,7 @@ void GetFusedDebugInfos(const NodeDebugInfoSet &fused_debug_infos, std::vector debug_info_vec_str; GetSourceLineFromDebugInfo(debug_info, &debug_info_vec_str, kSectionPrefix); if (!debug_info_vec_str.empty()) { - (void)result->insert(result->end(), debug_info_vec_str.begin(), debug_info_vec_str.end()); + (void)result->insert(result->cend(), debug_info_vec_str.cbegin(), debug_info_vec_str.cend()); is_empty = false; } } @@ -215,7 +215,7 @@ void GetPrimalDebugInfos(const CNodePtr &cnode, std::vector *result std::vector debug_info_vec_str; GetSourceLineFromDebugInfo(primal_debug_info, &debug_info_vec_str, kSectionPrefix); if (!debug_info_vec_str.empty()) { - (void)result->insert(result->end(), debug_info_vec_str.begin(), debug_info_vec_str.end()); + (void)result->insert(result->cend(), debug_info_vec_str.cbegin(), debug_info_vec_str.cend()); } } } diff --git a/mindspore/core/utils/trace_base.h b/mindspore/core/utils/trace_base.h index ad9c97dfbda..b14d81ed371 100644 --- a/mindspore/core/utils/trace_base.h +++ b/mindspore/core/utils/trace_base.h @@ -20,8 +20,6 @@ #include #include #include -#include -#include #include "utils/info.h" #include "ir/anf.h" diff --git a/mindspore/core/utils/trace_info.h b/mindspore/core/utils/trace_info.h index 0b876b81cd4..aa0b807a007 100644 --- a/mindspore/core/utils/trace_info.h +++ b/mindspore/core/utils/trace_info.h @@ -19,7 +19,6 @@ #include #include -#include namespace mindspore { class TraceInfo; @@ -33,6 +32,7 @@ class TraceInfo { public: explicit TraceInfo(const DebugInfoPtr &info) : debug_info_(info) {} TraceInfo(const TraceInfo &other) = default; + TraceInfo &operator=(const TraceInfo &) = default; virtual ~TraceInfo() = default; virtual std::string name() const { return ""; } virtual std::string symbol() const { return ""; } @@ -66,6 +66,7 @@ class TracePhi : public TraceInfo { class TraceIfStmtTrueBranch : public TraceInfo { public: TraceIfStmtTrueBranch(const TraceIfStmtTrueBranch &) = default; + TraceIfStmtTrueBranch &operator=(const TraceIfStmtTrueBranch &) = default; explicit TraceIfStmtTrueBranch(const DebugInfoPtr &info) : TraceInfo(info) {} ~TraceIfStmtTrueBranch() override = default; MS_DECLARE_TRACE_NAME_SYMBOL("if_true", "✓"); @@ -75,6 +76,7 @@ class TraceIfStmtTrueBranch : public TraceInfo { class TraceIfStmtFalseBranch : public TraceInfo { public: TraceIfStmtFalseBranch(const TraceIfStmtFalseBranch &) = default; + TraceIfStmtFalseBranch &operator=(const TraceIfStmtFalseBranch &) = default; explicit TraceIfStmtFalseBranch(const DebugInfoPtr &info) : TraceInfo(info) {} ~TraceIfStmtFalseBranch() override = default; MS_DECLARE_TRACE_NAME_SYMBOL("if_false", "✗");