From 4b1702dce5672136018df2323aac2390222e6fc8 Mon Sep 17 00:00:00 2001 From: wqtshg Date: Sat, 29 May 2021 15:04:13 +0800 Subject: [PATCH 1/5] 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(), From 7b049a7da719f9b678b92e6dd04ae2cfaf411a2e Mon Sep 17 00:00:00 2001 From: wqtshg Date: Sat, 29 May 2021 15:59:43 +0800 Subject: [PATCH 2/5] Zero copy nodes are not allocated memory in the known subgraph --- ge/graph/load/model_manager/davinci_model.cc | 20 +++++++++++++++++++- ge/graph/load/model_manager/davinci_model.h | 13 +++++++------ ge/graph/load/model_manager/task_info/task_info.h | 2 +- .../compiledsubgraph/known_node_executor.cc | 14 ++++++++------ 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/ge/graph/load/model_manager/davinci_model.cc b/ge/graph/load/model_manager/davinci_model.cc index cc6af8d2..35808a1f 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 ? value : 0; GELOGI("InitRuntimeParams(), %s.", runtime_param_.ToString().c_str()); } @@ -4507,4 +4507,22 @@ void DavinciModel::UpdateOpIOAddrs(uint32_t task_id, uint32_t stream_id, const s op_desc_info->output_addrs = output_addrs; GELOGD("[Update][OpIOAddrs] Op [%s] update input output addr success.", op_desc_info->op_name.c_str()); } + +/// +/// @ingroup ge +/// @brief Get total useful size, in known subgraph, no need to allocate zero copy memory during initialization. +/// @param [in] total_useful_size: total mem size - zero copy size. +/// @return Status +/// +Status DavinciModel::GetTotalMemSizeExcludeZeroCopy(int64_t &total_useful_size) { + if (runtime_param_.mem_size < runtime_param_.zero_copy_size) { + REPORT_CALL_ERROR("E19999", "total mem size[%lu] is less than zero copy size[%ld] ", runtime_param_.mem_size, + runtime_param_.zero_copy_size); + GELOGE(FAILED, "[Check][TotalMemSizeExcludeZeroCopy] failed, total mem size[%lu] is less than zero copy size[%ld]", + runtime_param_.mem_size, runtime_param_.zero_copy_size); + return FAILED; + } + total_useful_size = runtime_param_.mem_size - runtime_param_.zero_copy_size; + return SUCCESS; +} } // namespace ge diff --git a/ge/graph/load/model_manager/davinci_model.h b/ge/graph/load/model_manager/davinci_model.h index 47e5a6f6..6a03fca4 100755 --- a/ge/graph/load/model_manager/davinci_model.h +++ b/ge/graph/load/model_manager/davinci_model.h @@ -248,12 +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; - } + /// + /// @ingroup ge + /// @brief Get total useful size, in known subgraph, no need to allocate zero copy memory during initialization. + /// @param [in] total_useful_size: total mem size - zero copy size. + /// @return Status + /// + status GetTotalMemSizeExcludeZeroCopy(int64_t &total_useful_size); // 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 4109871a..9f849b20 100644 --- a/ge/graph/load/model_manager/task_info/task_info.h +++ b/ge/graph/load/model_manager/task_info/task_info.h @@ -65,7 +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; + int64_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 ebb1f6d8..8ee5718e 100755 --- a/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc +++ b/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc @@ -101,18 +101,20 @@ 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_->TotalMemSizeExcludeZeroCopy != 0) { + int64_t total_useful_size = 0; + GE_CHK_STATUS_RET(davinci_model_.GetTotalMemSizeExcludeZeroCopy(total_useful_size), + "[Get][TotalMemSizeExcludeZeroCopy] failed."); + if (total_useful_size != 0) { RECORD_EXECUTION_EVENT(context.GetExecutionContext(), context.GetNodeName(), "[KnownNodeTask_AllocateWorkspace] Start"); - GE_CHK_STATUS_RET(context.AllocateWorkspace(davinci_model_->TotalMemSizeExcludeZeroCopy(), &buffer, - davinci_model_->GetRuntimeParam().mem_base), + GE_CHK_STATUS_RET(context.AllocateWorkspace(total_useful_size, &buffer, davinci_model_->GetRuntimeParam().mem_base), "[Allocate][Workspace] failed for %s.", context.GetNodeName()); RECORD_EXECUTION_EVENT(context.GetExecutionContext(), context.GetNodeName(), - "[KnownNodeTask_AllocateWorkspace] End, size %zu", davinci_model_->TotalMemSize()); + "[KnownNodeTask_AllocateWorkspace] End, size %ld", total_useful_size); // update mem base davinci_model_->UpdateMemBase(static_cast(buffer)); - GELOGI("KnownNodeTask::Init mem base is %p, size %lu.", - davinci_model_->GetRuntimeParam().mem_base, davinci_model_->GetRuntimeParam().mem_size); + GELOGI("KnownNodeTask::Init mem base is %p, size %ld.", + davinci_model_->GetRuntimeParam().mem_base, total_useful_size); } GE_CHK_STATUS_RET(ModelManager::GetInstance()->DestroyAicpuKernel(davinci_model_->GetSessionId(), davinci_model_->Id(), From 5d012c05b7b74ecf809e9ce516be36333b48fde4 Mon Sep 17 00:00:00 2001 From: wqtshg Date: Sat, 29 May 2021 18:57:24 +0800 Subject: [PATCH 3/5] 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 | 2 +- ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ge/graph/load/model_manager/davinci_model.cc b/ge/graph/load/model_manager/davinci_model.cc index 35808a1f..05c50a58 100755 --- a/ge/graph/load/model_manager/davinci_model.cc +++ b/ge/graph/load/model_manager/davinci_model.cc @@ -4515,7 +4515,7 @@ void DavinciModel::UpdateOpIOAddrs(uint32_t task_id, uint32_t stream_id, const s /// @return Status /// Status DavinciModel::GetTotalMemSizeExcludeZeroCopy(int64_t &total_useful_size) { - if (runtime_param_.mem_size < runtime_param_.zero_copy_size) { + if (runtime_param_.mem_size < static_cast(runtime_param_.zero_copy_size)) { REPORT_CALL_ERROR("E19999", "total mem size[%lu] is less than zero copy size[%ld] ", runtime_param_.mem_size, runtime_param_.zero_copy_size); GELOGE(FAILED, "[Check][TotalMemSizeExcludeZeroCopy] failed, total mem size[%lu] is less than zero copy size[%ld]", diff --git a/ge/graph/load/model_manager/davinci_model.h b/ge/graph/load/model_manager/davinci_model.h index 6a03fca4..8a8fb35e 100755 --- a/ge/graph/load/model_manager/davinci_model.h +++ b/ge/graph/load/model_manager/davinci_model.h @@ -254,7 +254,7 @@ class DavinciModel { /// @param [in] total_useful_size: total mem size - zero copy size. /// @return Status /// - status GetTotalMemSizeExcludeZeroCopy(int64_t &total_useful_size); + Status GetTotalMemSizeExcludeZeroCopy(int64_t &total_useful_size); // model name string Name() const { return name_; } diff --git a/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc b/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc index 8ee5718e..679ad298 100755 --- a/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc +++ b/ge/hybrid/node_executor/compiledsubgraph/known_node_executor.cc @@ -102,7 +102,7 @@ Status KnownNodeTask::Init(TaskContext &context) { // allocate mem base void *buffer = nullptr; int64_t total_useful_size = 0; - GE_CHK_STATUS_RET(davinci_model_.GetTotalMemSizeExcludeZeroCopy(total_useful_size), + GE_CHK_STATUS_RET(davinci_model_->GetTotalMemSizeExcludeZeroCopy(total_useful_size), "[Get][TotalMemSizeExcludeZeroCopy] failed."); if (total_useful_size != 0) { RECORD_EXECUTION_EVENT(context.GetExecutionContext(), context.GetNodeName(), From 26d1960dc1a7b69aefed9ecd9b78d04634bf7e38 Mon Sep 17 00:00:00 2001 From: wqtshg Date: Mon, 31 May 2021 15:19:55 +0800 Subject: [PATCH 4/5] Zero copy nodes are not allocated memory in the known subgraph --- tests/ut/ge/graph/load/davinci_model_unittest.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/ut/ge/graph/load/davinci_model_unittest.cc b/tests/ut/ge/graph/load/davinci_model_unittest.cc index 4771ca8d..3f9cc850 100644 --- a/tests/ut/ge/graph/load/davinci_model_unittest.cc +++ b/tests/ut/ge/graph/load/davinci_model_unittest.cc @@ -1048,4 +1048,15 @@ TEST_F(UtestDavinciModel, update_io_addr_success) { vector io_addr = {nullptr, nullptr}; model.UpdateOpIOAddrs(task_id, stream_id, io_addr); } +TEST_F(UtestDavinciModel, get_total_memsize_exclude_zero_copy) { + DavinciModel model(0, nullptr); + model.runtime_param_.mem_size = 1024; + model.runtime_param_.zero_copy_size = 2048; + int64_t total_useful_size = 0; + EXPECT_EQ(model.GetTotalMemSizeExcludeZeroCopy(total_useful_size), FAILED); + EXPECT_EQ(total_useful_size, 0); + model.runtime_param_.zero_copy_size = 512; + EXPECT_EQ(model.GetTotalMemSizeExcludeZeroCopy(total_useful_size), SUCCESS); + EXPECT_EQ(total_useful_size, 512); +} } // namespace ge From b05f85c47468451aa89cd3adafa5179d7b903111 Mon Sep 17 00:00:00 2001 From: wqtshg Date: Mon, 31 May 2021 19:48:29 +0800 Subject: [PATCH 5/5] Zero copy nodes are not allocated memory in the known subgraph --- scripts/{cov => coverage}/ge_cov.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{cov => coverage}/ge_cov.sh (100%) mode change 100755 => 100644 diff --git a/scripts/cov/ge_cov.sh b/scripts/coverage/ge_cov.sh old mode 100755 new mode 100644 similarity index 100% rename from scripts/cov/ge_cov.sh rename to scripts/coverage/ge_cov.sh