From 3496a346be25899c6a56e044aac82ed65a3bb4d1 Mon Sep 17 00:00:00 2001 From: limingqi107 Date: Fri, 18 Mar 2022 10:37:46 +0800 Subject: [PATCH] fix pclint of runtime device --- .../ccsrc/common/mem_reuse/mem_dynamic_allocator.h | 2 +- mindspore/ccsrc/debug/debugger/debugger.cc | 4 ++-- mindspore/ccsrc/debug/debugger/debugger_utils.cc | 6 +++--- .../device/ascend/hal/device/ascend_device_address.h | 2 +- .../ascend/hal/hardware/ascend_device_context.h | 2 +- .../device/cpu/hal/hardware/cpu_device_context.h | 2 +- .../plugin/device/gpu/hal/device/gpu_device_address.h | 2 +- .../device/gpu/hal/device/gpu_kernel_runtime.cc | 4 ++-- .../device/gpu/hal/hardware/gpu_device_context.h | 2 +- mindspore/ccsrc/runtime/device/device_address.h | 6 +++--- mindspore/ccsrc/runtime/device/memory_manager.cc | 4 ++-- .../ccsrc/runtime/device/memory_offload_strategy.cc | 8 ++++---- mindspore/ccsrc/runtime/device/memory_scheduler.cc | 11 ++++++----- mindspore/ccsrc/runtime/device/memory_scheduler.h | 4 ++-- mindspore/ccsrc/runtime/hardware/device_context.h | 2 +- 15 files changed, 31 insertions(+), 30 deletions(-) diff --git a/mindspore/ccsrc/common/mem_reuse/mem_dynamic_allocator.h b/mindspore/ccsrc/common/mem_reuse/mem_dynamic_allocator.h index c5c9a9d3e44..ca4e6cad5d5 100644 --- a/mindspore/ccsrc/common/mem_reuse/mem_dynamic_allocator.h +++ b/mindspore/ccsrc/common/mem_reuse/mem_dynamic_allocator.h @@ -124,7 +124,7 @@ struct MemStatusManager { std::vector mem_block_list_; // The map of all idle memory buf by size. SizeMapMemBuf idle_mem_buf_map_; - void clear() { + void clear() noexcept { mem_block_list_.clear(); idle_mem_buf_map_.clear(); } diff --git a/mindspore/ccsrc/debug/debugger/debugger.cc b/mindspore/ccsrc/debug/debugger/debugger.cc index 2fdb5f3a3d4..bbf561ceb5e 100644 --- a/mindspore/ccsrc/debug/debugger/debugger.cc +++ b/mindspore/ccsrc/debug/debugger/debugger.cc @@ -1544,7 +1544,7 @@ void Debugger::LoadSingleAnfnode(const AnfNodePtr &anf_node, const size_t output } else { keep_prev = false; } - bool ret = addr->LoadMemToHost(tensor_name, exec_order, format, int_shapes, type, 0, keep_prev, root_graph_id); + bool ret = addr->LoadMemToHost(tensor_name, exec_order, format, int_shapes, type, 0, keep_prev, root_graph_id, false); if (!ret) { MS_LOG(ERROR) << "LoadMemToHost:" << ", tensor_name:" << tensor_name << ", host_format:" << format << ".!"; @@ -1706,7 +1706,7 @@ void Debugger::LoadGraphOutputs() { auto format = kOpFormat_DEFAULT; string tensor_name = kernel_name + ':' + std::to_string(j); ShapeVector int_shapes = trans::GetRuntimePaddingShape(node, j); - auto ret = addr->LoadMemToHost(tensor_name, exec_order, format, int_shapes, type, j, false, root_graph_id); + auto ret = addr->LoadMemToHost(tensor_name, exec_order, format, int_shapes, type, j, false, root_graph_id, false); if (!ret) { MS_LOG(ERROR) << "LoadMemToHost:" << ", tensor_name:" << tensor_name << ", host_format:" << format << ".!"; diff --git a/mindspore/ccsrc/debug/debugger/debugger_utils.cc b/mindspore/ccsrc/debug/debugger/debugger_utils.cc index e5a927b10ed..1159c72305c 100644 --- a/mindspore/ccsrc/debug/debugger/debugger_utils.cc +++ b/mindspore/ccsrc/debug/debugger/debugger_utils.cc @@ -90,7 +90,7 @@ void LoadInputs(const CNodePtr &cnode, const KernelLaunchInfo *launch_info, uint string input_tensor_name = input_kernel_name + ':' + "0"; ShapeVector int_shapes = trans::GetRuntimePaddingShape(input_kernel, PARAMETER_OUTPUT_INDEX); auto ret = device_addr->LoadMemToHost(input_tensor_name, UintToInt(exec_order), format, int_shapes, type, 0, true, - root_graph_id); + root_graph_id, false); if (!ret) { MS_LOG(ERROR) << "LoadMemToHost:" << ", tensor_name:" << input_tensor_name << ", host_format:" << format << ".!"; @@ -125,8 +125,8 @@ void LoadOutputs(const CNodePtr &cnode, const KernelLaunchInfo *launch_info, uin auto device_addr = device_context->CreateDeviceAddress(addr->addr, addr->size, format, type, ShapeVector()); string tensor_name = kernel_name + ':' + std::to_string(j); ShapeVector int_shapes = trans::GetRuntimePaddingShape(cnode, j); - auto ret = - device_addr->LoadMemToHost(tensor_name, UintToInt(exec_order), format, int_shapes, type, j, false, root_graph_id); + auto ret = device_addr->LoadMemToHost(tensor_name, UintToInt(exec_order), format, int_shapes, type, j, false, + root_graph_id, false); if (!ret) { MS_LOG(ERROR) << "LoadMemToHost:" << ", tensor_name:" << tensor_name << ", host_format:" << format << ".!"; diff --git a/mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_device_address.h b/mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_device_address.h index 744d15c2c87..a25831317da 100644 --- a/mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_device_address.h +++ b/mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_device_address.h @@ -62,7 +62,7 @@ class AscendDeviceAddress : public DeviceAddress { #ifdef ENABLE_DEBUGGER bool LoadMemToHost(const std::string &tensor_name, int execution_order, const std::string &host_fmt, const ShapeVector &host_shape, TypeId host_type, size_t slot, bool keep_prev, - uint32_t root_graph_id = 0, bool force_update = 0) const override; + uint32_t root_graph_id, bool force_update) const override; #endif private: diff --git a/mindspore/ccsrc/plugin/device/ascend/hal/hardware/ascend_device_context.h b/mindspore/ccsrc/plugin/device/ascend/hal/hardware/ascend_device_context.h index 098952a5b10..1c127652111 100644 --- a/mindspore/ccsrc/plugin/device/ascend/hal/hardware/ascend_device_context.h +++ b/mindspore/ccsrc/plugin/device/ascend/hal/hardware/ascend_device_context.h @@ -103,7 +103,7 @@ class AscendDeviceContext : public DeviceContext { // Launch a kernel via 'KernelMod' of the kernel. bool LaunchKernel(const CNodePtr &kernel, const std::vector &inputs, const std::vector &workspace, const std::vector &outputs, - bool is_dynamic_shape = false) const override; + bool is_dynamic_shape) const override; bool LaunchCustomFunc(const AnfNodePtr &kernel) const override; diff --git a/mindspore/ccsrc/plugin/device/cpu/hal/hardware/cpu_device_context.h b/mindspore/ccsrc/plugin/device/cpu/hal/hardware/cpu_device_context.h index ac727e84836..4e94fc82321 100644 --- a/mindspore/ccsrc/plugin/device/cpu/hal/hardware/cpu_device_context.h +++ b/mindspore/ccsrc/plugin/device/cpu/hal/hardware/cpu_device_context.h @@ -58,7 +58,7 @@ class CPUDeviceContext : public DeviceContext { bool LaunchKernel(const CNodePtr &kernel, const std::vector &inputs, const std::vector &workspace, const std::vector &outputs, - bool is_dynamic_shape = false) const override; + bool is_dynamic_shape) const override; bool LoadCollectiveCommLib() override; diff --git a/mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_device_address.h b/mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_device_address.h index d0b862c198f..d99cdf43c74 100644 --- a/mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_device_address.h +++ b/mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_device_address.h @@ -56,7 +56,7 @@ class GPUDeviceAddress : public DeviceAddress { #ifdef ENABLE_DEBUGGER bool LoadMemToHost(const std::string &tensor_name, int execution_order, const std::string &host_fmt, const ShapeVector &host_shape, TypeId host_type, size_t slot, bool keep_prev, - uint32_t root_graph_id = 0, bool force_update = 0) const override; + uint32_t root_graph_id, bool force_update) const override; #endif private: diff --git a/mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_kernel_runtime.cc b/mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_kernel_runtime.cc index 332cb23279b..1b352c5b0b4 100644 --- a/mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_kernel_runtime.cc +++ b/mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_kernel_runtime.cc @@ -184,7 +184,7 @@ void LoadKernelData(Debugger *debugger, const CNodePtr &kernel, auto gpu_addr = std::make_unique(addr->addr, addr->size, format, type); string input_tensor_name = input_kernel_name + ':' + "0"; ShapeVector int_shapes = trans::GetRuntimePaddingShape(input_kernel, PARAMETER_OUTPUT_INDEX); - auto ret = gpu_addr->LoadMemToHost(input_tensor_name, exec_order, format, int_shapes, type, 0, true); + auto ret = gpu_addr->LoadMemToHost(input_tensor_name, exec_order, format, int_shapes, type, 0, true, 0, false); if (!ret) { MS_LOG(ERROR) << "LoadMemToHost:" << ", tensor_name:" << input_tensor_name << ", host_format:" << format << ".!"; @@ -211,7 +211,7 @@ void LoadKernelData(Debugger *debugger, const CNodePtr &kernel, auto gpu_addr = std::make_unique(addr->addr, addr->size, format, type); string tensor_name = kernel_name + ':' + std::to_string(j); ShapeVector int_shapes = trans::GetRuntimePaddingShape(kernel, j); - auto ret = gpu_addr->LoadMemToHost(tensor_name, exec_order, format, int_shapes, type, j, false); + auto ret = gpu_addr->LoadMemToHost(tensor_name, exec_order, format, int_shapes, type, j, false, 0, false); if (!ret) { MS_LOG(ERROR) << "LoadMemToHost:" << ", tensor_name:" << tensor_name << ", host_format:" << format << ".!"; diff --git a/mindspore/ccsrc/plugin/device/gpu/hal/hardware/gpu_device_context.h b/mindspore/ccsrc/plugin/device/gpu/hal/hardware/gpu_device_context.h index a764292f977..3bf546e6976 100644 --- a/mindspore/ccsrc/plugin/device/gpu/hal/hardware/gpu_device_context.h +++ b/mindspore/ccsrc/plugin/device/gpu/hal/hardware/gpu_device_context.h @@ -66,7 +66,7 @@ class GPUDeviceContext : public DeviceContext { bool LaunchKernel(const CNodePtr &kernel, const std::vector &inputs, const std::vector &workspace, const std::vector &outputs, - bool is_dynamic_shape = false) const override; + bool is_dynamic_shape) const override; bool SyncStream(size_t stream_id = 0) const override; diff --git a/mindspore/ccsrc/runtime/device/device_address.h b/mindspore/ccsrc/runtime/device/device_address.h index dfd5c56963c..5d1b25efdcd 100644 --- a/mindspore/ccsrc/runtime/device/device_address.h +++ b/mindspore/ccsrc/runtime/device/device_address.h @@ -122,7 +122,7 @@ class DeviceAddress : public mindspore::DeviceSync { int32_t dynamic_ref_count() const { return dynamic_ref_count_; } void IncreaseDynamicRefCount(const std::string &op_object) { if (dynamic_ref_count_ < INT32_MAX) { - dynamic_ref_count_++; + ++dynamic_ref_count_; MS_LOG(DEBUG) << op_object << " increases dynamic ref count to:" << dynamic_ref_count_ << " for ptr:" << ptr_; } } @@ -130,7 +130,7 @@ class DeviceAddress : public mindspore::DeviceSync { if (dynamic_ref_count_ <= 0) { MS_LOG(EXCEPTION) << "The dynamic reference count is invalid value:" << dynamic_ref_count_; } - dynamic_ref_count_--; + --dynamic_ref_count_; MS_LOG(DEBUG) << op_object << " decreases dynamic ref count to:" << dynamic_ref_count_ << " for ptr:" << ptr_; } @@ -141,7 +141,7 @@ class DeviceAddress : public mindspore::DeviceSync { #ifdef ENABLE_DEBUGGER virtual bool LoadMemToHost(const std::string &tensor_name, int execution_order, const std::string &host_fmt, const ShapeVector &host_shape, TypeId host_type, size_t slot, bool keep_prev, - uint32_t root_graph_id = 0, bool force_update = 0) const { + uint32_t root_graph_id, bool force_update) const { return true; } #endif diff --git a/mindspore/ccsrc/runtime/device/memory_manager.cc b/mindspore/ccsrc/runtime/device/memory_manager.cc index cc1b4e8971e..0103692ce4d 100644 --- a/mindspore/ccsrc/runtime/device/memory_manager.cc +++ b/mindspore/ccsrc/runtime/device/memory_manager.cc @@ -29,11 +29,11 @@ namespace device { constexpr size_t kAlignBytes = 32; size_t MemoryManager::GetCommonAlignSize(size_t input_size) { - return (input_size + kMemAlignSize + kAlignBytes - 1) / kMemAlignSize * kMemAlignSize; + return ((input_size + kMemAlignSize + kAlignBytes - 1) / kMemAlignSize) * kMemAlignSize; } size_t MemoryManager::GetCommunicationAlignSize(size_t input_size) { - return (input_size + kMemAlignSize - 1) / kMemAlignSize * kMemAlignSize + kTwiceMemAlignSize; + return ((input_size + kMemAlignSize - 1) / kMemAlignSize) * kMemAlignSize + kTwiceMemAlignSize; } void MemoryManager::MallocSomasDynamicMem(const session::KernelGraph &graph) { diff --git a/mindspore/ccsrc/runtime/device/memory_offload_strategy.cc b/mindspore/ccsrc/runtime/device/memory_offload_strategy.cc index 6be8da074e7..465676fe72b 100644 --- a/mindspore/ccsrc/runtime/device/memory_offload_strategy.cc +++ b/mindspore/ccsrc/runtime/device/memory_offload_strategy.cc @@ -207,7 +207,7 @@ void MemOffloadStrategy::GenComputeMemEvents() { first_event->index = first_get_event->index; } if ((first_event->type == kInit || first_event->type == kMalloc) && first_event->index < total_step_) { - pre_compute_events_[first_event->index].emplace_back(first_event); + (void)pre_compute_events_[first_event->index].emplace_back(first_event); } else { MS_LOG_EXCEPTION << "First event should be init or malloc!"; } @@ -226,7 +226,7 @@ void MemOffloadStrategy::GenComputeMemEvents() { auto free_or_swap_out_event = std::make_shared(event_type, pre_index); free_or_swap_out_event->key = item.first; free_or_swap_out_event->mem_size = first_event->mem_size; - post_compute_events_[pre_index].emplace_back(free_or_swap_out_event); + (void)post_compute_events_[pre_index].emplace_back(free_or_swap_out_event); // avoid swap-in-event follow init-event if (i != kFirstGetMemEventIndex || first_event->type != kInit) { auto swap_in_event = std::make_shared(kSwapIn, event->index); @@ -276,7 +276,7 @@ std::set MemOffloadStrategy::GetSwapOutEventIndex(const void *key, min_swap_index_before_update = i; } } else { - swap_out_event_index.insert(i); + (void)swap_out_event_index.insert(i); max_swap_out_step = mem_event->index; while (update_steps_index < update_steps.size() && update_steps[update_steps_index] < mem_event->index) { ++update_steps_index; @@ -284,7 +284,7 @@ std::set MemOffloadStrategy::GetSwapOutEventIndex(const void *key, } } if (max_swap_out_step <= update_steps[update_steps.size() - 1]) { - swap_out_event_index.insert(min_swap_index_before_update); + (void)swap_out_event_index.insert(min_swap_index_before_update); } return swap_out_event_index; } diff --git a/mindspore/ccsrc/runtime/device/memory_scheduler.cc b/mindspore/ccsrc/runtime/device/memory_scheduler.cc index 3f8655d6b99..ac76f4c43f2 100644 --- a/mindspore/ccsrc/runtime/device/memory_scheduler.cc +++ b/mindspore/ccsrc/runtime/device/memory_scheduler.cc @@ -23,6 +23,7 @@ #include #endif #include "utils/log_adapter.h" +#include "utils/convert_utils_base.h" namespace mindspore { namespace device { @@ -80,12 +81,12 @@ void MemScheduler::Record(const void *key, const MemEventType &event_type, size_ auto event = std::make_shared(event_type, current_step_); event->mem_size = mem_size; event->key = key; - mem_events_[key].emplace_back(event); + (void)mem_events_[key].emplace_back(event); if (step_keys_.size() < current_step_ + 1) { step_keys_.resize(current_step_ + 1); } if (event->type == kGet) { - step_keys_[current_step_].insert(event->key); + (void)step_keys_[current_step_].insert(event->key); } } @@ -181,7 +182,7 @@ bool MemScheduler::PreComputeGet(const std::shared_ptr &event, void *s if (iter != mem_result_.end()) { auto ptr = iter->second; MS_EXCEPTION_IF_NULL(ptr); - return ptr; + return true; } if (!optimized_ || stream == nullptr) { return false; @@ -195,7 +196,7 @@ bool MemScheduler::PreComputeGet(const std::shared_ptr &event, void *s auto device_ptr = MallocDevice(mem_size, stream); mem_handler_->SwapIn(host_ptr, device_ptr, mem_size, stream); if (!from_init) { - swap_host_ptr_.erase(host_ptr); + (void)swap_host_ptr_.erase(host_ptr); mem_handler_->FreeHost(host_ptr); } mem_result_[key] = device_ptr; @@ -278,7 +279,7 @@ void MemScheduler::OptMemUsage(float mem_used_factor) { } auto available_mem_size = mem_handler_->GetAvailableMemSize(); - available_mem_size = available_mem_size * mem_used_factor; + available_mem_size = FloatToSize(available_mem_size * mem_used_factor); strategy_->set_mem_size(available_mem_size); strategy_->Execute(); } diff --git a/mindspore/ccsrc/runtime/device/memory_scheduler.h b/mindspore/ccsrc/runtime/device/memory_scheduler.h index 4cefb3f40e2..01c0265d271 100644 --- a/mindspore/ccsrc/runtime/device/memory_scheduler.h +++ b/mindspore/ccsrc/runtime/device/memory_scheduler.h @@ -61,7 +61,7 @@ class MemScheduler { void UpdateHighPriorityMem(const void *key) { if (need_record_event_) { - high_priority_updated_step_[key].emplace_back(current_step_); + (void)high_priority_updated_step_[key].emplace_back(current_step_); } } @@ -84,7 +84,7 @@ class MemScheduler { void SetOffload(const void *key) { (void)manual_offload_keys_.insert(key); } - void AddMemNeedInit(const void *key) { high_priority_mem_need_init_.insert(key); } + void AddMemNeedInit(const void *key) { (void)high_priority_mem_need_init_.insert(key); } void ClearMemNeedInit() { high_priority_mem_need_init_.clear(); } diff --git a/mindspore/ccsrc/runtime/hardware/device_context.h b/mindspore/ccsrc/runtime/hardware/device_context.h index 0853d5971a9..6fae527318f 100644 --- a/mindspore/ccsrc/runtime/hardware/device_context.h +++ b/mindspore/ccsrc/runtime/hardware/device_context.h @@ -131,7 +131,7 @@ class DeviceContext { // Launch a kernel via 'KernelMod' of the kernel. virtual bool LaunchKernel(const CNodePtr &kernel, const std::vector &inputs, const std::vector &workspace, const std::vector &outputs, - bool is_dynamic_shape = false) const { + bool is_dynamic_shape) const { return true; }