From 4b1702dce5672136018df2323aac2390222e6fc8 Mon Sep 17 00:00:00 2001 From: wqtshg Date: Sat, 29 May 2021 15:04:13 +0800 Subject: [PATCH] Zero copy nodes are not allocated memory in the known subgraph --- ge/graph/load/model_manager/davinci_model.cc | 2 ++ ge/graph/load/model_manager/davinci_model.h | 7 +++++++ ge/graph/load/model_manager/task_info/task_info.h | 3 ++- ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc | 4 ++-- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ge/graph/load/model_manager/davinci_model.cc b/ge/graph/load/model_manager/davinci_model.cc index b52796c8..cc6af8d2 100755 --- a/ge/graph/load/model_manager/davinci_model.cc +++ b/ge/graph/load/model_manager/davinci_model.cc @@ -488,6 +488,8 @@ void DavinciModel::InitRuntimeParams() { session_scope_mem_info.memory_size = static_cast(ret ? value : 0); runtime_param_.memory_infos[kSessionScopeMemory | RT_MEMORY_HBM] = std::move(session_scope_mem_info); + ret = ge::AttrUtils::GetInt(ge_model_, ATTR_MODEL_ZERO_COPY_MEMORY_SIZE, value); + runtime_param_.zero_copy_size = ret ? (uint64_t)value : 0; GELOGI("InitRuntimeParams(), %s.", runtime_param_.ToString().c_str()); } diff --git a/ge/graph/load/model_manager/davinci_model.h b/ge/graph/load/model_manager/davinci_model.h index e4898dec..47e5a6f6 100755 --- a/ge/graph/load/model_manager/davinci_model.h +++ b/ge/graph/load/model_manager/davinci_model.h @@ -248,6 +248,13 @@ class DavinciModel { // get total mem size size_t TotalMemSize() const { return runtime_param_.mem_size; } + // get total useful size: total mem size - zero copy size; + // In known subgraph, no need to allocate zero copy memory during initialization + size_t TotalMemSizeExcludeZeroCopy() const { + return runtime_param_.mem_size > runtime_param_.zero_copy_size + ? runtime_param_.mem_size - runtime_param_.zero_copy_size : 0; + } + // model name string Name() const { return name_; } diff --git a/ge/graph/load/model_manager/task_info/task_info.h b/ge/graph/load/model_manager/task_info/task_info.h index 5657f003..4109871a 100644 --- a/ge/graph/load/model_manager/task_info/task_info.h +++ b/ge/graph/load/model_manager/task_info/task_info.h @@ -49,7 +49,7 @@ struct RuntimeParam { << ", label_num:" << label_num << ", logic_mem_base:" << logic_mem_base << ", logic_weight_base:" << logic_weight_base << ", logic_var_base:" << logic_var_base << ", memory_size:" << mem_size << ", weight_size:" << weight_size << ", var_size:" << var_size - << ", ex_memory_info:"; + << ", zero_copy_size:" << zero_copy_size << ", ex_memory_info:"; for (auto it : memory_infos) { ss << "[memory_type:" << it.first << ", memory_size:" << it.second.memory_size << "]"; } @@ -65,6 +65,7 @@ struct RuntimeParam { uint64_t var_size = 0; uint64_t logic_var_base = 0; uint8_t *var_base = nullptr; + uint64_t zero_copy_size = 0; std::map memory_infos; uint32_t batch_num = 0; uint32_t stream_num = 0; diff --git a/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc b/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc index c800e93d..ebb1f6d8 100755 --- a/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc +++ b/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc @@ -101,10 +101,10 @@ Status KnownNodeTask::Init(TaskContext &context) { GE_CHK_STATUS_RET(context.AllocateOutputs(), "[Allocate][Outputs] failed for %s.", context.GetNodeName()); // allocate mem base void *buffer = nullptr; - if (davinci_model_->TotalMemSize() != 0) { + if (davinci_model_->TotalMemSizeExcludeZeroCopy != 0) { RECORD_EXECUTION_EVENT(context.GetExecutionContext(), context.GetNodeName(), "[KnownNodeTask_AllocateWorkspace] Start"); - GE_CHK_STATUS_RET(context.AllocateWorkspace(davinci_model_->TotalMemSize(), &buffer, + GE_CHK_STATUS_RET(context.AllocateWorkspace(davinci_model_->TotalMemSizeExcludeZeroCopy(), &buffer, davinci_model_->GetRuntimeParam().mem_base), "[Allocate][Workspace] failed for %s.", context.GetNodeName()); RECORD_EXECUTION_EVENT(context.GetExecutionContext(), context.GetNodeName(),