Browse Source

!31491 fix pclint of runtime device

Merge pull request !31491 from limingqi107/bug_fix4
r1.7
i-robot Gitee 4 years ago
parent
commit
d71a9a088b
No known key found for this signature in database GPG Key ID: 173E9B9CA92EEF8F
15 changed files with 31 additions and 30 deletions
  1. +1
    -1
      mindspore/ccsrc/common/mem_reuse/mem_dynamic_allocator.h
  2. +2
    -2
      mindspore/ccsrc/debug/debugger/debugger.cc
  3. +3
    -3
      mindspore/ccsrc/debug/debugger/debugger_utils.cc
  4. +1
    -1
      mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_device_address.h
  5. +1
    -1
      mindspore/ccsrc/plugin/device/ascend/hal/hardware/ascend_device_context.h
  6. +1
    -1
      mindspore/ccsrc/plugin/device/cpu/hal/hardware/cpu_device_context.h
  7. +1
    -1
      mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_device_address.h
  8. +2
    -2
      mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_kernel_runtime.cc
  9. +1
    -1
      mindspore/ccsrc/plugin/device/gpu/hal/hardware/gpu_device_context.h
  10. +3
    -3
      mindspore/ccsrc/runtime/device/device_address.h
  11. +2
    -2
      mindspore/ccsrc/runtime/device/memory_manager.cc
  12. +4
    -4
      mindspore/ccsrc/runtime/device/memory_offload_strategy.cc
  13. +6
    -5
      mindspore/ccsrc/runtime/device/memory_scheduler.cc
  14. +2
    -2
      mindspore/ccsrc/runtime/device/memory_scheduler.h
  15. +1
    -1
      mindspore/ccsrc/runtime/hardware/device_context.h

+ 1
- 1
mindspore/ccsrc/common/mem_reuse/mem_dynamic_allocator.h View File

@@ -124,7 +124,7 @@ struct MemStatusManager {
std::vector<DynamicMemBlockPtr> 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();
}


+ 2
- 2
mindspore/ccsrc/debug/debugger/debugger.cc View File

@@ -1542,7 +1542,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 << ".!";
@@ -1704,7 +1704,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 << ".!";


+ 3
- 3
mindspore/ccsrc/debug/debugger/debugger_utils.cc View File

@@ -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 << ".!";


+ 1
- 1
mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_device_address.h View File

@@ -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:


+ 1
- 1
mindspore/ccsrc/plugin/device/ascend/hal/hardware/ascend_device_context.h View File

@@ -103,7 +103,7 @@ class AscendDeviceContext : public DeviceContext {
// Launch a kernel via 'KernelMod' of the kernel.
bool LaunchKernel(const CNodePtr &kernel, const std::vector<AddressPtr> &inputs,
const std::vector<AddressPtr> &workspace, const std::vector<AddressPtr> &outputs,
bool is_dynamic_shape = false) const override;
bool is_dynamic_shape) const override;

bool LaunchCustomFunc(const AnfNodePtr &kernel) const override;



+ 1
- 1
mindspore/ccsrc/plugin/device/cpu/hal/hardware/cpu_device_context.h View File

@@ -58,7 +58,7 @@ class CPUDeviceContext : public DeviceContext {

bool LaunchKernel(const CNodePtr &kernel, const std::vector<AddressPtr> &inputs,
const std::vector<AddressPtr> &workspace, const std::vector<AddressPtr> &outputs,
bool is_dynamic_shape = false) const override;
bool is_dynamic_shape) const override;

bool LoadCollectiveCommLib() override;



+ 1
- 1
mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_device_address.h View File

@@ -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:


+ 2
- 2
mindspore/ccsrc/plugin/device/gpu/hal/device/gpu_kernel_runtime.cc View File

@@ -183,7 +183,7 @@ void LoadKernelData(Debugger *debugger, const CNodePtr &kernel,
auto gpu_addr = std::make_unique<GPUDeviceAddress>(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 << ".!";
@@ -210,7 +210,7 @@ void LoadKernelData(Debugger *debugger, const CNodePtr &kernel,
auto gpu_addr = std::make_unique<GPUDeviceAddress>(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 << ".!";


+ 1
- 1
mindspore/ccsrc/plugin/device/gpu/hal/hardware/gpu_device_context.h View File

@@ -66,7 +66,7 @@ class GPUDeviceContext : public DeviceContext {

bool LaunchKernel(const CNodePtr &kernel, const std::vector<AddressPtr> &inputs,
const std::vector<AddressPtr> &workspace, const std::vector<AddressPtr> &outputs,
bool is_dynamic_shape = false) const override;
bool is_dynamic_shape) const override;

bool SyncStream(size_t stream_id = 0) const override;



+ 3
- 3
mindspore/ccsrc/runtime/device/device_address.h View File

@@ -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


+ 2
- 2
mindspore/ccsrc/runtime/device/memory_manager.cc View File

@@ -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) {


+ 4
- 4
mindspore/ccsrc/runtime/device/memory_offload_strategy.cc View File

@@ -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<MemEvent>(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<MemEvent>(kSwapIn, event->index);
@@ -276,7 +276,7 @@ std::set<size_t> 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<size_t> 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;
}


+ 6
- 5
mindspore/ccsrc/runtime/device/memory_scheduler.cc View File

@@ -23,6 +23,7 @@
#include <sys/time.h>
#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<MemEvent>(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<MemEvent> &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<MemEvent> &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();
}


+ 2
- 2
mindspore/ccsrc/runtime/device/memory_scheduler.h View File

@@ -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(); }



+ 1
- 1
mindspore/ccsrc/runtime/hardware/device_context.h View File

@@ -131,7 +131,7 @@ class DeviceContext {
// Launch a kernel via 'KernelMod' of the kernel.
virtual bool LaunchKernel(const CNodePtr &kernel, const std::vector<AddressPtr> &inputs,
const std::vector<AddressPtr> &workspace, const std::vector<AddressPtr> &outputs,
bool is_dynamic_shape = false) const {
bool is_dynamic_shape) const {
return true;
}



Loading…
Cancel
Save