From d34effbc86eee99cbcee14034a1101472197a508 Mon Sep 17 00:00:00 2001 From: wqtshg Date: Mon, 17 May 2021 15:32:09 +0800 Subject: [PATCH 1/2] Zero copy nodes are not allocated memory in the known subgraph --- ge/graph/load/model_manager/davinci_model.cc | 3 +++ ge/graph/load/model_manager/davinci_model.h | 3 +++ ge/graph/load/model_manager/task_info/task_info.h | 3 ++- ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc | 6 ++++-- metadef | 2 +- parser | 2 +- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ge/graph/load/model_manager/davinci_model.cc b/ge/graph/load/model_manager/davinci_model.cc index b52796c8..c8dc483c 100755 --- a/ge/graph/load/model_manager/davinci_model.cc +++ b/ge/graph/load/model_manager/davinci_model.cc @@ -488,6 +488,9 @@ 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..e362acfa 100755 --- a/ge/graph/load/model_manager/davinci_model.h +++ b/ge/graph/load/model_manager/davinci_model.h @@ -265,6 +265,9 @@ class DavinciModel { size_t TotalVarMemSize() const { return runtime_param_.var_size; } + // get total zero copy size + size_t TotalZeroCopySize() const { return runtime_param_.zero_copy_size; } + // get base memory address uint8_t *MemBase() { return mem_base_; } 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..5a101f0d 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; + size_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..3c111f55 100755 --- a/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc +++ b/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc @@ -101,10 +101,12 @@ 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) { + size_t total_mem_size = davinci_model_->TotalMemSize(); + size_t total_zero_copy_size = davinci_model_->TotalZeroCopySize(); + if (total_mem_size != 0 && total_mem_size > total_zero_copy_size) { 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(total_mem_size - total_zero_copy_size, &buffer, davinci_model_->GetRuntimeParam().mem_base), "[Allocate][Workspace] failed for %s.", context.GetNodeName()); RECORD_EXECUTION_EVENT(context.GetExecutionContext(), context.GetNodeName(), diff --git a/metadef b/metadef index 1aa10c59..7cb171b9 160000 --- a/metadef +++ b/metadef @@ -1 +1 @@ -Subproject commit 1aa10c59b4e11564c2db76c2ba0039474d38df26 +Subproject commit 7cb171b9c511fec57ccc0ad746ef2126267fe18b diff --git a/parser b/parser index 7773435b..8d44bebf 160000 --- a/parser +++ b/parser @@ -1 +1 @@ -Subproject commit 7773435b776fb37231abcef2bbcf972814b01dd1 +Subproject commit 8d44bebfeeb71b793bc7325acc95345090789e19 From 8ba6f74e98bdb34bf6d953fc8609d573a81caece Mon Sep 17 00:00:00 2001 From: wqtshg Date: Mon, 17 May 2021 20:09:49 +0800 Subject: [PATCH 2/2] Zero copy nodes are not allocated memory in the known subgraph --- ge/graph/load/model_manager/davinci_model.cc | 2 +- ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ge/graph/load/model_manager/davinci_model.cc b/ge/graph/load/model_manager/davinci_model.cc index c8dc483c..4fac7b28 100755 --- a/ge/graph/load/model_manager/davinci_model.cc +++ b/ge/graph/load/model_manager/davinci_model.cc @@ -489,7 +489,7 @@ void DavinciModel::InitRuntimeParams() { 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; + runtime_param_.zero_copy_size = ret ? static_castvalue : 0; GELOGI("InitRuntimeParams(), %s.", runtime_param_.ToString().c_str()); } diff --git a/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc b/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc index 3c111f55..1c666230 100755 --- a/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc +++ b/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc @@ -103,6 +103,8 @@ Status KnownNodeTask::Init(TaskContext &context) { void *buffer = nullptr; size_t total_mem_size = davinci_model_->TotalMemSize(); size_t total_zero_copy_size = davinci_model_->TotalZeroCopySize(); + GELOGI("####KnownNodeTask::Init total mem size is %lu, total zero size is %lu.", + total_mem_size, total_zero_copy_size); if (total_mem_size != 0 && total_mem_size > total_zero_copy_size) { RECORD_EXECUTION_EVENT(context.GetExecutionContext(), context.GetNodeName(), "[KnownNodeTask_AllocateWorkspace] Start");