diff --git a/mindspore/ccsrc/backend/optimizer/graph_kernel/add_atomic_clean.cc b/mindspore/ccsrc/backend/optimizer/graph_kernel/add_atomic_clean.cc index 2767c5dae65..7fd644ff960 100644 --- a/mindspore/ccsrc/backend/optimizer/graph_kernel/add_atomic_clean.cc +++ b/mindspore/ccsrc/backend/optimizer/graph_kernel/add_atomic_clean.cc @@ -52,7 +52,7 @@ std::set GetUniqReduceAxes(const AnfNodePtr &node, bool is_ascend = fal auto axis_vec = GetReduceAxis(node); if (axis_vec.empty()) { for (size_t i = 0; i < src_shape_vec.size(); ++i) { - axis_vec.emplace_back(SizeToLong(i)); + (void)axis_vec.emplace_back(SizeToLong(i)); } } else { (void)std::transform(axis_vec.begin(), axis_vec.end(), axis_vec.begin(), [&src_shape_vec](int64_t axis) -> int64_t { diff --git a/mindspore/ccsrc/backend/optimizer/graph_kernel/parallel_fusion.cc b/mindspore/ccsrc/backend/optimizer/graph_kernel/parallel_fusion.cc index cdcb5aedc3c..dac055a3ecd 100644 --- a/mindspore/ccsrc/backend/optimizer/graph_kernel/parallel_fusion.cc +++ b/mindspore/ccsrc/backend/optimizer/graph_kernel/parallel_fusion.cc @@ -557,7 +557,7 @@ std::tuple, std::vector> ParallelOpFusion::Searc std::vector indices; for (size_t i = 0; i < cs.size(); ++i) { if (cs[i]) { - origin_indices.insert({cs[i], i}); + origin_indices.emplace(cs[i], i); indices.push_back(i); } } diff --git a/mindspore/ccsrc/utils/context/graph_kernel_flags.cc b/mindspore/ccsrc/utils/context/graph_kernel_flags.cc index e80b7d105f9..fab6f07feeb 100644 --- a/mindspore/ccsrc/utils/context/graph_kernel_flags.cc +++ b/mindspore/ccsrc/utils/context/graph_kernel_flags.cc @@ -32,11 +32,11 @@ std::vector GetTokens(const std::string &str, const std::string &de std::vector tokens; std::vector c_str(str.begin(), str.end()); c_str.push_back('\0'); - char *saveptr; + char *saveptr = nullptr; char *pch = strtok_r(&c_str[0], delim.c_str(), &saveptr); - while (pch != NULL) { + while (pch != nullptr) { tokens.emplace_back(pch); - pch = strtok_r(NULL, delim.c_str(), &saveptr); + pch = strtok_r(nullptr, delim.c_str(), &saveptr); } return tokens; } @@ -44,19 +44,19 @@ std::vector GetTokens(const std::string &str, const std::string &de // Parse flag string to key-value pair. // Flag format: "--key=value", bool flag's value can be implicit, the "--key" means "--key=true" std::pair ParseFlag(const std::string &flag) { - auto i = flag.find("--"); // check the string starts with "--". - constexpr size_t expected_size = 2; - if (i != 0 || flag.size() == expected_size) { + auto i = flag.find("--"); + constexpr size_t leading_size = 2; + if (flag.size() <= leading_size || i != 0) { return std::pair(); } - i += expected_size; + i += leading_size; auto j = flag.find('=', i + 1); // the key should not be empty, "--=" is invalid - if (j == std::string::npos) { + if (j >= flag.size()) { // no value, treated as bool flag. return std::make_pair(flag.substr(i), ""); - } else if (j + 1 != flag.size() && flag.find('=', j + 1) == std::string::npos) { + } else if (j + 1 < flag.size() && flag.find('=', j + 1) == std::string::npos) { // normal "--key=value" format return std::make_pair(flag.substr(i, j - i), flag.substr(j + 1)); } diff --git a/mindspore/ccsrc/utils/context/graph_kernel_flags.h b/mindspore/ccsrc/utils/context/graph_kernel_flags.h index d7a1f025016..f74fc2c0314 100644 --- a/mindspore/ccsrc/utils/context/graph_kernel_flags.h +++ b/mindspore/ccsrc/utils/context/graph_kernel_flags.h @@ -65,19 +65,19 @@ class GraphKernelFlags { * * Experimental feature, enabled by default when opt_level=3 */ - bool enable_stitch_fusion; + bool enable_stitch_fusion{false}; /** * Enable recompute fusion in graph kernel fusion strategy, enabled when op_level>=2. */ - bool enable_recompute_fusion; + bool enable_recompute_fusion{true}; /** * Enable parallel fusion in graph kernel fusion strategy. * * Experimental feature, enabled by default when opt_level=3 */ - bool enable_parallel_fusion; + bool enable_parallel_fusion{false}; /** * Optimization level, value from 0 to 3. @@ -88,7 +88,7 @@ class GraphKernelFlags { * The default value is OptLevel_2 when the context "enable_graph_kernel" is set, * but if it's also changed in "graph_kernel_flags", then the "graph_kernel_flags" will prevail. */ - unsigned int opt_level; // defaults 0 or 2 + unsigned int opt_level{0}; // defaults 0 or 2 /** * auto_tune, unsupported now.