From a2114f29eba88d89a9a1fb0db09be379886fa260 Mon Sep 17 00:00:00 2001 From: zhoufeng Date: Thu, 27 May 2021 17:38:44 +0800 Subject: [PATCH] code clean Signed-off-by: zhoufeng --- .../kernel_compiler/hccl/hccl_kernel.cc | 2 +- .../host/dynamic_shape_kernel.cc | 2 +- .../kernel_compiler/host/host_kernel_mod.cc | 6 ++-- mindspore/ccsrc/common/duplex_pipe.cc | 12 ++++---- mindspore/ccsrc/common/duplex_pipe.h | 8 ++--- mindspore/ccsrc/common/duplex_pipe_win.cc | 8 ++--- .../profiling/profiling_callback_register.cc | 23 ++++++++------- .../ascend/profiling/profiling_manager.cc | 29 +++++++++---------- .../ascend/profiling/profiling_utils.cc | 5 ++-- .../profiling/reporter/task_desc_reporter.cc | 2 +- .../profiling/reporter/task_desc_reporter.h | 2 +- 11 files changed, 50 insertions(+), 49 deletions(-) diff --git a/mindspore/ccsrc/backend/kernel_compiler/hccl/hccl_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/hccl/hccl_kernel.cc index 3e443990438..c32bd58e6a5 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/hccl/hccl_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/hccl/hccl_kernel.cc @@ -60,7 +60,7 @@ std::shared_ptr HcclKernelFactory::Get(const std::string &name) { } HcclKernelFactory &HcclKernelFactory::Get() { - static HcclKernelFactory _this; + static HcclKernelFactory _this{}; return _this; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/host/dynamic_shape_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/host/dynamic_shape_kernel.cc index 07d8cab3bd2..770d1582afb 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/host/dynamic_shape_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/host/dynamic_shape_kernel.cc @@ -37,7 +37,7 @@ void DynamicShapeKernel::Execute() { auto data_ptr = static_cast(output_tensor_for_sync->data_c()); for (size_t i = 0; i < prev_output_shape.size(); ++i) { MS_LOG(INFO) << "DEBUG prev_output_shape[" << i << "]:" << prev_output_shape[i]; - *(data_ptr + i) = prev_output_shape[i]; + *(data_ptr + i) = SizeToLong(prev_output_shape[i]); } auto output_addr = AnfAlgo::GetOutputAddr(cnode, 0); diff --git a/mindspore/ccsrc/backend/kernel_compiler/host/host_kernel_mod.cc b/mindspore/ccsrc/backend/kernel_compiler/host/host_kernel_mod.cc index 7989a1fc22d..31744508ab9 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/host/host_kernel_mod.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/host/host_kernel_mod.cc @@ -42,7 +42,7 @@ std::shared_ptr HostKernelFactory::Get(const std::string &name) { } HostKernelFactory &HostKernelFactory::Get() { - static HostKernelFactory instance; + static HostKernelFactory instance{}; return instance; } @@ -76,8 +76,8 @@ bool HostKernelMod::Init(const AnfNodePtr &anf_node) { } return true; } -bool HostKernelMod::Launch(const std::vector &inputs, const std::vector &workspace, - const std::vector &outputs, void *stream_ptr) { +bool HostKernelMod::Launch(const std::vector &, const std::vector &, + const std::vector &, void *) { return true; } std::vector HostKernelMod::GenTask(const std::vector &, const std::vector &, diff --git a/mindspore/ccsrc/common/duplex_pipe.cc b/mindspore/ccsrc/common/duplex_pipe.cc index 7c6b8a64786..33db75a3504 100644 --- a/mindspore/ccsrc/common/duplex_pipe.cc +++ b/mindspore/ccsrc/common/duplex_pipe.cc @@ -20,6 +20,7 @@ #include #include #include +#include "utils/convert_utils_base.h" namespace mindspore { DuplexPipe::~DuplexPipe() { @@ -29,7 +30,7 @@ DuplexPipe::~DuplexPipe() { } } -int DuplexPipe::Open(std::initializer_list arg_list, bool append_fds) { +int DuplexPipe::Open(const std::initializer_list &arg_list, bool append_fds) { if (pipe(fd1_) == -1) { DP_EXCEPTION << "pipe 1 failed, errno: " << errno; } @@ -80,7 +81,7 @@ int DuplexPipe::Open(std::initializer_list arg_list, bool append_fd return 0; } -void DuplexPipe::Write(const std::string &buf, bool flush) { +void DuplexPipe::Write(const std::string &buf, bool flush) const { // Write the string into pipe if (write(fd1_[1], buf.data(), buf.size()) == -1) { DP_ERROR << "write failed, errno: " << errno; @@ -108,7 +109,7 @@ std::string DuplexPipe::Read() { } CancelTimeOut(); bool line_end = c_buf_[size - 1] == '\n'; - buf.append(c_buf_, line_end ? size - 1 : size); // Copy without the last '\n' + buf.append(c_buf_, LongToSize(line_end ? size - 1 : size)); // Copy without the last '\n' if (line_end) { break; } @@ -166,12 +167,12 @@ DuplexPipe::SignalHandler::SignalHandler(const std::weak_ptr &dp, pi DuplexPipe::SignalHandler::~SignalHandler() {} -void DuplexPipe::SignalHandler::SetAlarm(unsigned int interval_secs) { +void DuplexPipe::SignalHandler::SetAlarm(unsigned int interval_secs) const { signal(SIGALRM, SigAlarmHandler); alarm(interval_secs); } -void DuplexPipe::SignalHandler::CancelAlarm() { alarm(0); } +void DuplexPipe::SignalHandler::CancelAlarm() const { alarm(0); } void DuplexPipe::SignalHandler::SigAlarmHandler(int sig) { DP_INFO << "Signal: " << sig << ", child_pid_: " << child_pid_; @@ -196,6 +197,7 @@ void DuplexPipe::SignalHandler::SigPipeHandler(int sig) { } void DuplexPipe::SignalHandler::SigChildHandler(int sig) { + DP_INFO << "Signal: " << sig << ", child_pid_: " << child_pid_; int status; if (child_pid_ != nullptr) { (void)waitpid(*child_pid_, &status, WNOHANG | WUNTRACED); diff --git a/mindspore/ccsrc/common/duplex_pipe.h b/mindspore/ccsrc/common/duplex_pipe.h index d18f0b5a3c7..3615a73e326 100644 --- a/mindspore/ccsrc/common/duplex_pipe.h +++ b/mindspore/ccsrc/common/duplex_pipe.h @@ -42,14 +42,14 @@ class DuplexPipe : public std::enable_shared_from_this { ~DuplexPipe(); // Create a subprocess and open a duplex pipe between local and remote - int Open(std::initializer_list arg_list, bool append_fds = false); + int Open(const std::initializer_list &arg_list, bool append_fds = false); void Close(); void SetTimeOutSeconds(unsigned int secs) { time_out_secs_ = secs; } void SetTimeOutCallback(const std::shared_ptr> cb) { time_out_callback_ = cb; } void SetFinalizeCallback(const std::shared_ptr> cb) { finalize_callback_ = cb; } // Write the 'buf' to remote stdin - void Write(const std::string &buf, bool flush = true); + void Write(const std::string &buf, bool flush = true) const; // Read from remote stdout/stderr into 'c_buf_' std::string Read(); @@ -108,8 +108,8 @@ class DuplexPipe : public std::enable_shared_from_this { SignalHandler(const std::weak_ptr &dp, pid_t *pid); ~SignalHandler(); - void SetAlarm(unsigned int interval_secs); - void CancelAlarm(); + void SetAlarm(unsigned int interval_secs) const; + void CancelAlarm() const; private: static void SigAlarmHandler(int sig); diff --git a/mindspore/ccsrc/common/duplex_pipe_win.cc b/mindspore/ccsrc/common/duplex_pipe_win.cc index 9482f468bb1..d84e530e826 100644 --- a/mindspore/ccsrc/common/duplex_pipe_win.cc +++ b/mindspore/ccsrc/common/duplex_pipe_win.cc @@ -20,11 +20,11 @@ #include namespace mindspore { -int DuplexPipe::Open(std::initializer_list arg_list, bool append_fds) { +int DuplexPipe::Open(const std::initializer_list &arg_list, bool append_fds) { DP_EXCEPTION << "Not support for Windows by now."; } -void DuplexPipe::Write(const std::string &buf, bool flush) { DP_EXCEPTION << "Not support for Windows by now."; } +void DuplexPipe::Write(const std::string &buf, bool flush) const { DP_EXCEPTION << "Not support for Windows by now."; } std::string DuplexPipe::Read() { DP_EXCEPTION << "Not support for Windows by now."; } @@ -40,9 +40,9 @@ DuplexPipe &DuplexPipe::operator>>(std::string &buf) { DP_EXCEPTION << "Not supp void DuplexPipe::Close() { DP_EXCEPTION << "Not support for Windows by now."; } -void DuplexPipe::SignalHandler::SetAlarm(unsigned int interval_secs) { +void DuplexPipe::SignalHandler::SetAlarm(unsigned int interval_secs) const { DP_EXCEPTION << "Not support for Windows by now."; } -void DuplexPipe::SignalHandler::CancelAlarm() { DP_EXCEPTION << "Not support for Windows by now."; } +void DuplexPipe::SignalHandler::CancelAlarm() const { DP_EXCEPTION << "Not support for Windows by now."; } } // namespace mindspore diff --git a/mindspore/ccsrc/runtime/device/ascend/profiling/profiling_callback_register.cc b/mindspore/ccsrc/runtime/device/ascend/profiling/profiling_callback_register.cc index 1a821e3b7a6..c8b5de22f08 100644 --- a/mindspore/ccsrc/runtime/device/ascend/profiling/profiling_callback_register.cc +++ b/mindspore/ccsrc/runtime/device/ascend/profiling/profiling_callback_register.cc @@ -15,7 +15,7 @@ */ #include "runtime/device/ascend/profiling/profiling_callback_register.h" -#include "runtime/base.h" +#include "utils/convert_utils_base.h" namespace Analysis { namespace Dvvp { @@ -30,39 +30,40 @@ constexpr Status PROF_SUCCESS = 0; constexpr Status PROF_FAILED = 0xFFFFFFFF; } // namespace -int32_t _aclprofGetDeviceByModelId(uint32_t modelId, uint32_t &deviceId) { return 0; } +int32_t _aclprofGetDeviceByModelId(uint32_t, uint32_t &) { return 0; } bool _aclprofGetInitFlag() { return true; } int32_t _aclprofRegisterCtrlCallback(MsprofCtrlCallback callback) { if (VMCallbackRegister::GetInstance().registered()) { - return VMCallbackRegister::GetInstance().DoRegProfCtrlCallback(callback); + return mindspore::UintToInt(VMCallbackRegister::GetInstance().DoRegProfCtrlCallback(callback)); } else { - return PROF_SUCCESS; + return mindspore::UintToInt(PROF_SUCCESS); } } int32_t _aclprofRegisterSetDeviceCallback(MsprofSetDeviceCallback callback) { if (VMCallbackRegister::GetInstance().registered()) { - return VMCallbackRegister::GetInstance().DoRegProfSetDeviceCallback(callback); + return mindspore::UintToInt(VMCallbackRegister::GetInstance().DoRegProfSetDeviceCallback(callback)); } else { - return PROF_SUCCESS; + return mindspore::UintToInt(PROF_SUCCESS); } } int32_t _aclprofRegisterReporterCallback(MsprofReporterCallback callback) { if (VMCallbackRegister::GetInstance().registered()) { - return VMCallbackRegister::GetInstance().DoRegProfReporterCallback(callback); + return mindspore::UintToInt(VMCallbackRegister::GetInstance().DoRegProfReporterCallback(callback)); } else { - return PROF_SUCCESS; + return mindspore::UintToInt(PROF_SUCCESS); } } int32_t _aclprofCommandHandle(uint32_t type, void *data, uint32_t len) { if (VMCallbackRegister::GetInstance().registered()) { - return VMCallbackRegister::GetInstance().DoProfCommandHandle((ProfCommandHandleType)type, data, len); + return mindspore::UintToInt( + VMCallbackRegister::GetInstance().DoProfCommandHandle((ProfCommandHandleType)type, data, len)); } else { - return PROF_SUCCESS; + return mindspore::UintToInt(PROF_SUCCESS); } } @@ -101,7 +102,7 @@ Status ProfCommandHandle(ProfCommandHandleType type, void *data, uint32_t len) { bool IsInitialize() { return true; } VMCallbackRegister &VMCallbackRegister::GetInstance() { - static VMCallbackRegister instance; + static VMCallbackRegister instance{}; return instance; } diff --git a/mindspore/ccsrc/runtime/device/ascend/profiling/profiling_manager.cc b/mindspore/ccsrc/runtime/device/ascend/profiling/profiling_manager.cc index b73ba58c208..11d6e2c576f 100644 --- a/mindspore/ccsrc/runtime/device/ascend/profiling/profiling_manager.cc +++ b/mindspore/ccsrc/runtime/device/ascend/profiling/profiling_manager.cc @@ -28,7 +28,7 @@ #include "runtime/device/ascend/profiling/profiling_callback_register.h" namespace { -constexpr uint32_t kProfilingDeviceNum = 1; +constexpr int32_t kProfilingDeviceNum = 1; constexpr auto kRtSetDeviceRegName = "profiling"; constexpr Status PROF_SUCCESS = 0; constexpr Status PROF_FAILED = 0xFFFFFFFF; @@ -38,7 +38,7 @@ namespace mindspore { namespace device { namespace ascend { ProfilingManager &ProfilingManager::GetInstance() { - static ProfilingManager inst; + static ProfilingManager inst{}; return inst; } @@ -93,9 +93,8 @@ Status ProfilingManager::PluginInit() const { MS_LOG(ERROR) << "MsprofReporterCallback callback is nullptr."; return PROF_FAILED; } - return prof_cb_.msprofReporterCallback(static_cast(MsprofReporterModuleId::MSPROF_MODULE_FRAMEWORK), - static_cast(MsprofReporterCallbackType::MSPROF_REPORTER_INIT), - nullptr, 0); + return prof_cb_.msprofReporterCallback(IntToUint(MsprofReporterModuleId::MSPROF_MODULE_FRAMEWORK), + IntToUint(MsprofReporterCallbackType::MSPROF_REPORTER_INIT), nullptr, 0); } void ProfilingManager::PluginUnInit() const { @@ -180,7 +179,7 @@ bool ProfilingManager::ProfStartUp(const NotNull prof_conf) c int32_t cb_ret = prof_cb_.msprofCtrlCallback(static_cast(MsprofCtrlCallbackType::MSPROF_CTRL_INIT_GE_OPTIONS), static_cast(prof_conf.get()), sizeof(MsprofGeOptions)); - if (cb_ret != PROF_SUCCESS) { + if (cb_ret != UintToInt(PROF_SUCCESS)) { MS_LOG(ERROR) << "Call msprofCtrlCallback failed, ret: " << cb_ret; return false; } @@ -203,7 +202,7 @@ bool ProfilingManager::StopProfiling() { uint32_t device_ids[kProfilingDeviceNum] = {GetCurrentDeviceId()}; auto rt_ret = rtProfilerStop(module, kProfilingDeviceNum, device_ids); - if (rt_ret != RT_ERROR_NONE) { + if (rt_ret != UintToInt(RT_ERROR_NONE)) { MS_LOG(ERROR) << "Call rtProfilerStop failed"; return false; } @@ -228,8 +227,8 @@ Status ProfilingManager::CallMsprofReport(const NotNull reporter MS_LOG(ERROR) << "MsprofReporterCallback callback is nullptr."; return PROF_FAILED; } - return prof_cb_.msprofReporterCallback(static_cast(MsprofReporterModuleId::MSPROF_MODULE_FRAMEWORK), - static_cast(MsprofReporterCallbackType::MSPROF_REPORTER_REPORT), + return prof_cb_.msprofReporterCallback(IntToUint(MsprofReporterModuleId::MSPROF_MODULE_FRAMEWORK), + IntToUint(MsprofReporterCallbackType::MSPROF_REPORTER_REPORT), static_cast(reporter_data.get()), sizeof(ReporterData)); } @@ -255,10 +254,10 @@ Status RegProfSetDeviceCallback(MsprofSetDeviceCallback func) { ProfilingManager::GetInstance().SetMsprofSetDeviceCallback(func); // Pass MsprofSetDeviceCallback to runtime MS_LOG(INFO) << "GE pass setdevice callback to runtime."; - Status rt_ret = rtRegDeviceStateCallback(kRtSetDeviceRegName, static_cast(func)); - if (rt_ret != PROF_SUCCESS) { + rtError_t rt_ret = rtRegDeviceStateCallback(kRtSetDeviceRegName, static_cast(func)); + if (rt_ret != UintToInt(PROF_SUCCESS)) { MS_LOG(WARNING) << "Pass MsprofSetDeviceCallback to runtime failed."; - return rt_ret; + return IntToUint(rt_ret); } return PROF_SUCCESS; } @@ -274,10 +273,10 @@ Status RegProfReporterCallback(MsprofReporterCallback func) { MS_LOG(INFO) << "GE register Msprof reporter callback."; ProfilingManager::GetInstance().SetMsprofReporterCallback(func); // Pass MsprofReporterCallback to runtime - Status rt_ret = rtSetMsprofReporterCallback(func); - if (rt_ret != PROF_SUCCESS) { + rtError_t rt_ret = rtSetMsprofReporterCallback(func); + if (rt_ret != UintToInt(PROF_SUCCESS)) { MS_LOG(WARNING) << "Pass MsprofReporterCallback to runtime failed, ret: " << rt_ret; - return rt_ret; + return IntToUint(rt_ret); } // Pass MsprofReporterCallback to hccl } diff --git a/mindspore/ccsrc/runtime/device/ascend/profiling/profiling_utils.cc b/mindspore/ccsrc/runtime/device/ascend/profiling/profiling_utils.cc index cf13fb9634a..7570cb0732b 100644 --- a/mindspore/ccsrc/runtime/device/ascend/profiling/profiling_utils.cc +++ b/mindspore/ccsrc/runtime/device/ascend/profiling/profiling_utils.cc @@ -93,7 +93,7 @@ void ProfilingUtils::GetTraceCustomNode(ProfilingTraceInfo *trace_info) { break; } MS_LOG(INFO) << "Get custom profiling node:" << node_full_name; - trace_info->trace_custom_node.insert(node_full_name); + trace_info->trace_custom_node.emplace(node_full_name); } } @@ -285,8 +285,7 @@ void ProfilingUtils::SaveProfilingPoint(uint32_t graph_id, const std::string &no std::shared_ptr prof_desc_ptr = std::make_shared(node_name, point_id); auto iter = graph_point_.find(graph_id); if (iter == graph_point_.end()) { - std::vector> tmp_vect = {prof_desc_ptr}; - graph_point_.insert({graph_id, tmp_vect}); + graph_point_.emplace(graph_id, std::vector>{prof_desc_ptr}); } else { iter->second.emplace_back(prof_desc_ptr); } diff --git a/mindspore/ccsrc/runtime/device/ascend/profiling/reporter/task_desc_reporter.cc b/mindspore/ccsrc/runtime/device/ascend/profiling/reporter/task_desc_reporter.cc index df2fc91de2b..656884323c4 100644 --- a/mindspore/ccsrc/runtime/device/ascend/profiling/reporter/task_desc_reporter.cc +++ b/mindspore/ccsrc/runtime/device/ascend/profiling/reporter/task_desc_reporter.cc @@ -50,7 +50,7 @@ void TaskDescReporter::ReportData() { ReportAllLine(); } -void TaskDescReporter::CheckStreamTaskValid(uint32_t task_id, uint32_t stream_id) { +void TaskDescReporter::CheckStreamTaskValid(size_t task_id, size_t stream_id) const { if (task_id >= task_ids_.size() || stream_id >= stream_ids_.size()) { MS_LOG(EXCEPTION) << "Index invalid. task_id:" << task_id << ", task_ids.size:" << task_ids_.size() << ", stream_id:" << stream_id << ", stream_ids.size:" << stream_ids_.size(); diff --git a/mindspore/ccsrc/runtime/device/ascend/profiling/reporter/task_desc_reporter.h b/mindspore/ccsrc/runtime/device/ascend/profiling/reporter/task_desc_reporter.h index a92aa1cb30f..30a3b7e662c 100644 --- a/mindspore/ccsrc/runtime/device/ascend/profiling/reporter/task_desc_reporter.h +++ b/mindspore/ccsrc/runtime/device/ascend/profiling/reporter/task_desc_reporter.h @@ -37,7 +37,7 @@ class TaskDescReporter : public DescReporter { private: std::vector task_ids_; std::vector stream_ids_; - void CheckStreamTaskValid(uint32_t task_id, uint32_t stream_id); + void CheckStreamTaskValid(size_t task_id, size_t stream_id) const; std::vector cnode_list_; }; } // namespace ascend