diff --git a/mindspore/ccsrc/debug/anf_ir_utils.cc b/mindspore/ccsrc/debug/anf_ir_utils.cc index 74f53c8e075..7130fbc7b83 100644 --- a/mindspore/ccsrc/debug/anf_ir_utils.cc +++ b/mindspore/ccsrc/debug/anf_ir_utils.cc @@ -45,7 +45,6 @@ using mindspore::tensor::TensorPy; namespace mindspore { - std::string GetKernelNodeName(const AnfNodePtr &anf_node) { std::string kernel_name = anf_node->fullname_with_scope(); if (kernel_name.empty()) { diff --git a/mindspore/ccsrc/debug/data_dump/dump_utils.cc b/mindspore/ccsrc/debug/data_dump/dump_utils.cc index a33c989d0e0..30735eeb890 100644 --- a/mindspore/ccsrc/debug/data_dump/dump_utils.cc +++ b/mindspore/ccsrc/debug/data_dump/dump_utils.cc @@ -132,10 +132,11 @@ uint64_t GetTimeStamp() { } std::string GetOpNameWithoutScope(const std::string &fullname_with_scope) { - std::size_t found = fullname_with_scope.rfind("--"); + const std::string separator("--"); + std::size_t found = fullname_with_scope.rfind(separator); std::string op_name; if (found != std::string::npos) { - op_name = fullname_with_scope.substr(found + 2); + op_name = fullname_with_scope.substr(found + separator.length()); } return op_name; } diff --git a/mindspore/ccsrc/debug/debug_services.cc b/mindspore/ccsrc/debug/debug_services.cc index c3528b1fc65..4b0c6adcb9c 100644 --- a/mindspore/ccsrc/debug/debug_services.cc +++ b/mindspore/ccsrc/debug/debug_services.cc @@ -474,8 +474,7 @@ void DebugServices::ConvertToHostFormat(const std::map backend_name, std: continue; } std::size_t found = stripped_file_name.rfind(prefix_dump_file_name, 0); - if (found != 0) { continue; } @@ -907,7 +905,6 @@ std::vector> DebugServices::ReadNeededDumpedTensors( continue; } std::size_t found = stripped_file_name.rfind(dump_name, 0); - if (found == 0) { size_t slot = std::stoul(stripped_file_name.substr(dump_name.length() + 1)); std::vector shape; diff --git a/mindspore/ccsrc/frontend/operator/composite/composite.cc b/mindspore/ccsrc/frontend/operator/composite/composite.cc index 401c12a4c6a..c517ac56efc 100644 --- a/mindspore/ccsrc/frontend/operator/composite/composite.cc +++ b/mindspore/ccsrc/frontend/operator/composite/composite.cc @@ -305,7 +305,7 @@ AnfNodePtr HyperMap::FullMake(const std::shared_ptr &type, const FuncGrap auto call_node = func_graph->NewCNodeInOrder(inputs2); if (reverse_) { - inputs.insert(inputs.begin() + 2, call_node); + inputs.insert(inputs.begin() + kPrimAndTypeLen, call_node); } else { inputs.emplace_back(call_node); } diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/updatestate_eliminate.cc b/mindspore/ccsrc/frontend/optimizer/irpass/updatestate_eliminate.cc index cbeb5ddf22e..6d06dd52a9c 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/updatestate_eliminate.cc +++ b/mindspore/ccsrc/frontend/optimizer/irpass/updatestate_eliminate.cc @@ -70,8 +70,9 @@ bool OnlyUsedByTwoNode(const AnfNodePtr &be_used_node, const AnfNodePtr &first_n if (iter == node_users.end()) { return false; } + constexpr size_t partial_users_cnt = 2; auto &partial_users = iter->second; - if (partial_users.size() != 2) { + if (partial_users.size() != partial_users_cnt) { return false; } const auto &first_user = partial_users.front().first; diff --git a/mindspore/ccsrc/pipeline/jit/prim_bprop_optimizer.cc b/mindspore/ccsrc/pipeline/jit/prim_bprop_optimizer.cc index b73e7ef383e..e3425820390 100644 --- a/mindspore/ccsrc/pipeline/jit/prim_bprop_optimizer.cc +++ b/mindspore/ccsrc/pipeline/jit/prim_bprop_optimizer.cc @@ -355,6 +355,5 @@ abstract::AbstractBasePtrList PrimBpropOptimizer::AddOutToAbsList(const ValuePtr new_abs_list.emplace_back(out_abs); return new_abs_list; } - } // namespace pipeline } // namespace mindspore diff --git a/mindspore/core/abstract/prim_arrays.cc b/mindspore/core/abstract/prim_arrays.cc index 2ebd4fb39cb..60d3963cd5a 100644 --- a/mindspore/core/abstract/prim_arrays.cc +++ b/mindspore/core/abstract/prim_arrays.cc @@ -1222,6 +1222,5 @@ AbstractBasePtr InferImplTensorCopySlices(const AnalysisEnginePtr &, const Primi AbstractTensorPtr input = CheckArg(op_name, args_spec_list, 0); return std::make_shared(input->element(), input->shape()); } - } // namespace abstract } // namespace mindspore diff --git a/mindspore/core/gvar/log_adapter_common.cc b/mindspore/core/gvar/log_adapter_common.cc index 2967285e8ff..24f69ff8207 100644 --- a/mindspore/core/gvar/log_adapter_common.cc +++ b/mindspore/core/gvar/log_adapter_common.cc @@ -63,27 +63,19 @@ std::string GetTimeString() { time_t time_seconds = time(0); struct tm now_time; localtime_s(&now_time, &time_seconds); - sprintf_s(buf, BUFLEN, "%d-%d-%d %d:%d:%d", now_time.tm_year + 1900, now_time.tm_mon + 1, now_time.tm_mday, - now_time.tm_hour, now_time.tm_min, now_time.tm_sec); + snprintf(buf, BUFLEN, "%d-%d-%d %d:%d:%d", now_time.tm_year + 1900, now_time.tm_mon + 1, now_time.tm_mday, + now_time.tm_hour, now_time.tm_min, now_time.tm_sec); #else struct timeval cur_time; (void)gettimeofday(&cur_time, nullptr); struct tm now; + constexpr size_t time_str_len = 19; + constexpr int64_t time_convert_unit = 1000; (void)localtime_r(&cur_time.tv_sec, &now); (void)strftime(buf, BUFLEN, "%Y-%m-%d-%H:%M:%S", &now); // format date and time - // set micro-second - buf[27] = '\0'; - int idx = 26; - auto num = cur_time.tv_usec; - constexpr int interval_number = 3; - for (int i = 5; i >= 0; i--) { - buf[idx--] = static_cast(num % 10 + '0'); - num /= 10; - if (i % interval_number == 0) { - buf[idx--] = '.'; - } - } + snprintf(buf + time_str_len, BUFLEN - time_str_len, ".%03ld.%03ld", cur_time.tv_usec / time_convert_unit, + cur_time.tv_usec % time_convert_unit); #endif return std::string(buf); }