From bb3dc9c718c13b02609258e69b0741f851f95fd6 Mon Sep 17 00:00:00 2001 From: chenyemeng Date: Mon, 4 Jan 2021 16:30:55 +0800 Subject: [PATCH 1/4] add ge_tensor after const_folding --- ge/ge_local_engine/engine/host_cpu_engine.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ge/ge_local_engine/engine/host_cpu_engine.cc b/ge/ge_local_engine/engine/host_cpu_engine.cc index 35ecfb2d..5b190cdb 100755 --- a/ge/ge_local_engine/engine/host_cpu_engine.cc +++ b/ge/ge_local_engine/engine/host_cpu_engine.cc @@ -36,7 +36,6 @@ namespace { GELOGD("node:%s allocate output %zu success, size=%lld", op_desc->GetName().c_str(), i, size); \ ge_tensor->MutableTensorDesc().SetDataType(out_desc.GetDataType()); \ ge_tensor->MutableTensorDesc().SetShape(out_desc.GetShape()); \ - outputs.emplace_back(ge_tensor); \ } else { \ ge_tensor = outputs[i]; \ GE_CHECK_NOTNULL(ge_tensor); \ @@ -224,15 +223,26 @@ Status HostCpuEngine::Run(NodePtr &node, const vector &inputs, GE_CHK_STATUS_RET_NOLOG(FindOpKernel(node, op_kernel)); std::map named_inputs; - std::vector tmp_outputs; - tmp_outputs.swap(outputs); std::map named_outputs; auto op_desc = node->GetOpDesc(); GE_CHK_STATUS_RET_NOLOG(PrepareInputs(op_desc, inputs, named_inputs)); - GE_CHK_STATUS_RET_NOLOG(PrepareOutputs(op_desc, tmp_outputs, named_outputs)); + GE_CHK_STATUS_RET_NOLOG(PrepareOutputs(op_desc, outputs, named_outputs)); GE_CHK_STATUS_RET_NOLOG(RunInternal(op_desc, *op_kernel, named_inputs, named_outputs)); GELOGD("Run node by host cpu engine successfully. name node = %s", node->GetName().c_str()); + std::vector tmp_outputs; + for (size_t i = 0; i < op_desc->GetOutputsSize(); i++) { + auto tensor_name = op_desc->GetOutputNameByIndex(i); + GE_RETURN_WITH_LOG_IF_TRUE(tensor_name.empty(), "Failed to get output name. node = %s, index = %zu", + op_desc->GetName().c_str(), i); + auto iter = named_outputs.find(tensor_name); + GE_RETURN_WITH_LOG_IF_TRUE(iter == named_outputs.end(), + "Failed to get output tensor. node = %s, index = %zu, tensor_name = %s", + op_desc->GetName().c_str(), i, tensor_name.c_str()); + auto ge_tensor = MakeShared(TensorAdapter::AsGeTensor(iter->second)); + GE_CHECK_NOTNULL(ge_tensor); + tmp_outputs.emplace_back(ge_tensor); + } outputs.swap(tmp_outputs); return SUCCESS; } From 3d359b01da381de9133b33d608d2d8c314889864 Mon Sep 17 00:00:00 2001 From: chenyemeng Date: Mon, 4 Jan 2021 19:57:21 +0800 Subject: [PATCH 2/4] add tensor after fold --- ge/ge_local_engine/engine/host_cpu_engine.cc | 14 ++++++++++++-- ge/graph/build/model_builder.cc | 4 ++++ ge/graph/passes/assign_remove_pass.cc | 12 ++++++------ ge/graph/passes/inplace_support_check_pass.cc | 10 +++++----- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/ge/ge_local_engine/engine/host_cpu_engine.cc b/ge/ge_local_engine/engine/host_cpu_engine.cc index 5b190cdb..1197f466 100755 --- a/ge/ge_local_engine/engine/host_cpu_engine.cc +++ b/ge/ge_local_engine/engine/host_cpu_engine.cc @@ -221,7 +221,7 @@ Status HostCpuEngine::Run(NodePtr &node, const vector &inputs, GELOGD("Run node by host cpu engine. node name = %s", node->GetName().c_str()); std::unique_ptr op_kernel; GE_CHK_STATUS_RET_NOLOG(FindOpKernel(node, op_kernel)); - +#ifndef ONLY_COMPILE_OPEN_SRC std::map named_inputs; std::map named_outputs; auto op_desc = node->GetOpDesc(); @@ -229,7 +229,6 @@ Status HostCpuEngine::Run(NodePtr &node, const vector &inputs, GE_CHK_STATUS_RET_NOLOG(PrepareOutputs(op_desc, outputs, named_outputs)); GE_CHK_STATUS_RET_NOLOG(RunInternal(op_desc, *op_kernel, named_inputs, named_outputs)); - GELOGD("Run node by host cpu engine successfully. name node = %s", node->GetName().c_str()); std::vector tmp_outputs; for (size_t i = 0; i < op_desc->GetOutputsSize(); i++) { auto tensor_name = op_desc->GetOutputNameByIndex(i); @@ -243,6 +242,17 @@ Status HostCpuEngine::Run(NodePtr &node, const vector &inputs, GE_CHECK_NOTNULL(ge_tensor); tmp_outputs.emplace_back(ge_tensor); } +#else + std::map named_inputs; + std::vector tmp_outputs; + tmp_outputs.swap(outputs); + std::map named_outputs; + auto op_desc = node->GetOpDesc(); + GE_CHK_STATUS_RET_NOLOG(PrepareInputs(op_desc, inputs, named_inputs)); + GE_CHK_STATUS_RET_NOLOG(PrepareOutputs(op_desc, tmp_outputs, named_outputs)); + GE_CHK_STATUS_RET_NOLOG(RunInternal(op_desc, *op_kernel, named_inputs, named_outputs)); +#endif + GELOGD("Run node by host cpu engine successfully. name node = %s", node->GetName().c_str()); outputs.swap(tmp_outputs); return SUCCESS; } diff --git a/ge/graph/build/model_builder.cc b/ge/graph/build/model_builder.cc index de586275..0639322d 100755 --- a/ge/graph/build/model_builder.cc +++ b/ge/graph/build/model_builder.cc @@ -569,7 +569,11 @@ Status ModelBuilder::MergeWeights() { return FAILED; } } +#ifndef ONLY_COMPILE_OPEN_SRC + weight->ClearData(); +#else weight_data.clear(); +#endif } return SUCCESS; diff --git a/ge/graph/passes/assign_remove_pass.cc b/ge/graph/passes/assign_remove_pass.cc index e198c2db..fc971cc0 100644 --- a/ge/graph/passes/assign_remove_pass.cc +++ b/ge/graph/passes/assign_remove_pass.cc @@ -21,12 +21,12 @@ namespace ge { namespace { -constexpr uint32_t kValidInputNodeOutputNum = 1; -constexpr int32_t kAssignRefInputIndex = 0; -constexpr int32_t kAssignValueInputIndex = 1; -static const std::set kNoTaskNodeTypes = { ge::DATA, ge::ANN_DATA, ge::AIPPDATA, - ge::CONSTANT, ge::CONSTANTOP, - ge::VARIABLE, ge::VARIABLEV2 }; + constexpr uint32_t kValidInputNodeOutputNum = 1; + constexpr int32_t kAssignRefInputIndex = 0; + constexpr int32_t kAssignValueInputIndex = 1; + static const std::set kNoTaskNodeTypes = { ge::DATA, ge::ANN_DATA, ge::AIPPDATA, + ge::CONSTANT, ge::CONSTANTOP, + ge::VARIABLE, ge::VARIABLEV2 }; } Status AssignRemovePass::Run(NodePtr &node) { diff --git a/ge/graph/passes/inplace_support_check_pass.cc b/ge/graph/passes/inplace_support_check_pass.cc index 44ad8361..9f683751 100644 --- a/ge/graph/passes/inplace_support_check_pass.cc +++ b/ge/graph/passes/inplace_support_check_pass.cc @@ -21,11 +21,11 @@ namespace ge { namespace { -constexpr uint32_t kInplaceSupportOutputIndex = 0; -constexpr uint32_t kInplaceSupportOutputNum = 1; -static const std::set kSrcNodeTypes = { ge::DATA, ge::ANN_DATA, ge::AIPPDATA, - ge::CONSTANT, ge::CONSTANTOP, - ge::VARIABLE, ge::VARIABLEV2 }; + constexpr uint32_t kInplaceSupportOutputIndex = 0; + constexpr uint32_t kInplaceSupportOutputNum = 1; + static const std::set kSrcNodeTypes = { ge::DATA, ge::ANN_DATA, ge::AIPPDATA, + ge::CONSTANT, ge::CONSTANTOP, + ge::VARIABLE, ge::VARIABLEV2 }; } Status InplaceSupportCheckPass::Run(NodePtr &node) { GELOGD("InplaceSupportCheckPass running"); From fbc543626c0a17c78ed5d8074daa73ba50ad71e5 Mon Sep 17 00:00:00 2001 From: chenyemeng Date: Tue, 5 Jan 2021 15:18:03 +0800 Subject: [PATCH 3/4] add tensor after fold --- ge/ge_local_engine/engine/host_cpu_engine.cc | 14 +++++++++----- ge/graph/passes/assign_remove_pass.cc | 12 ++++++------ ge/graph/passes/inplace_support_check_pass.cc | 10 +++++----- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/ge/ge_local_engine/engine/host_cpu_engine.cc b/ge/ge_local_engine/engine/host_cpu_engine.cc index 1197f466..99ee8794 100755 --- a/ge/ge_local_engine/engine/host_cpu_engine.cc +++ b/ge/ge_local_engine/engine/host_cpu_engine.cc @@ -232,12 +232,16 @@ Status HostCpuEngine::Run(NodePtr &node, const vector &inputs, std::vector tmp_outputs; for (size_t i = 0; i < op_desc->GetOutputsSize(); i++) { auto tensor_name = op_desc->GetOutputNameByIndex(i); - GE_RETURN_WITH_LOG_IF_TRUE(tensor_name.empty(), "Failed to get output name. node = %s, index = %zu", - op_desc->GetName().c_str(), i); + if (tensor_name.empty()) { + GELOGE(INTERNAL_ERROR, "Failed to get output name. node = %s, index = %zu", op_desc->GetName().c_str(), i); + return INTERNAL_ERROR; + } auto iter = named_outputs.find(tensor_name); - GE_RETURN_WITH_LOG_IF_TRUE(iter == named_outputs.end(), - "Failed to get output tensor. node = %s, index = %zu, tensor_name = %s", - op_desc->GetName().c_str(), i, tensor_name.c_str()); + if (iter == named_outputs.end()) { + GELOGE(INTERNAL_ERROR, "Failed to get output tensor. node = %s, index = %zu, tensor_name = %s", + op_desc->GetName().c_str(), i, tensor_name.c_str()); + return INTERNAL_ERROR; + } auto ge_tensor = MakeShared(TensorAdapter::AsGeTensor(iter->second)); GE_CHECK_NOTNULL(ge_tensor); tmp_outputs.emplace_back(ge_tensor); diff --git a/ge/graph/passes/assign_remove_pass.cc b/ge/graph/passes/assign_remove_pass.cc index fc971cc0..e198c2db 100644 --- a/ge/graph/passes/assign_remove_pass.cc +++ b/ge/graph/passes/assign_remove_pass.cc @@ -21,12 +21,12 @@ namespace ge { namespace { - constexpr uint32_t kValidInputNodeOutputNum = 1; - constexpr int32_t kAssignRefInputIndex = 0; - constexpr int32_t kAssignValueInputIndex = 1; - static const std::set kNoTaskNodeTypes = { ge::DATA, ge::ANN_DATA, ge::AIPPDATA, - ge::CONSTANT, ge::CONSTANTOP, - ge::VARIABLE, ge::VARIABLEV2 }; +constexpr uint32_t kValidInputNodeOutputNum = 1; +constexpr int32_t kAssignRefInputIndex = 0; +constexpr int32_t kAssignValueInputIndex = 1; +static const std::set kNoTaskNodeTypes = { ge::DATA, ge::ANN_DATA, ge::AIPPDATA, + ge::CONSTANT, ge::CONSTANTOP, + ge::VARIABLE, ge::VARIABLEV2 }; } Status AssignRemovePass::Run(NodePtr &node) { diff --git a/ge/graph/passes/inplace_support_check_pass.cc b/ge/graph/passes/inplace_support_check_pass.cc index 9f683751..44ad8361 100644 --- a/ge/graph/passes/inplace_support_check_pass.cc +++ b/ge/graph/passes/inplace_support_check_pass.cc @@ -21,11 +21,11 @@ namespace ge { namespace { - constexpr uint32_t kInplaceSupportOutputIndex = 0; - constexpr uint32_t kInplaceSupportOutputNum = 1; - static const std::set kSrcNodeTypes = { ge::DATA, ge::ANN_DATA, ge::AIPPDATA, - ge::CONSTANT, ge::CONSTANTOP, - ge::VARIABLE, ge::VARIABLEV2 }; +constexpr uint32_t kInplaceSupportOutputIndex = 0; +constexpr uint32_t kInplaceSupportOutputNum = 1; +static const std::set kSrcNodeTypes = { ge::DATA, ge::ANN_DATA, ge::AIPPDATA, + ge::CONSTANT, ge::CONSTANTOP, + ge::VARIABLE, ge::VARIABLEV2 }; } Status InplaceSupportCheckPass::Run(NodePtr &node) { GELOGD("InplaceSupportCheckPass running"); From 78047f46cfcbbb10ce1d182e2f06bce792f3e5c4 Mon Sep 17 00:00:00 2001 From: chenyemeng Date: Wed, 6 Jan 2021 13:52:59 +0800 Subject: [PATCH 4/4] add tensor after fold --- ge/ge_local_engine/engine/host_cpu_engine.cc | 11 ----------- ge/graph/build/model_builder.cc | 4 ---- 2 files changed, 15 deletions(-) diff --git a/ge/ge_local_engine/engine/host_cpu_engine.cc b/ge/ge_local_engine/engine/host_cpu_engine.cc index 99ee8794..06dc2b96 100755 --- a/ge/ge_local_engine/engine/host_cpu_engine.cc +++ b/ge/ge_local_engine/engine/host_cpu_engine.cc @@ -221,7 +221,6 @@ Status HostCpuEngine::Run(NodePtr &node, const vector &inputs, GELOGD("Run node by host cpu engine. node name = %s", node->GetName().c_str()); std::unique_ptr op_kernel; GE_CHK_STATUS_RET_NOLOG(FindOpKernel(node, op_kernel)); -#ifndef ONLY_COMPILE_OPEN_SRC std::map named_inputs; std::map named_outputs; auto op_desc = node->GetOpDesc(); @@ -246,16 +245,6 @@ Status HostCpuEngine::Run(NodePtr &node, const vector &inputs, GE_CHECK_NOTNULL(ge_tensor); tmp_outputs.emplace_back(ge_tensor); } -#else - std::map named_inputs; - std::vector tmp_outputs; - tmp_outputs.swap(outputs); - std::map named_outputs; - auto op_desc = node->GetOpDesc(); - GE_CHK_STATUS_RET_NOLOG(PrepareInputs(op_desc, inputs, named_inputs)); - GE_CHK_STATUS_RET_NOLOG(PrepareOutputs(op_desc, tmp_outputs, named_outputs)); - GE_CHK_STATUS_RET_NOLOG(RunInternal(op_desc, *op_kernel, named_inputs, named_outputs)); -#endif GELOGD("Run node by host cpu engine successfully. name node = %s", node->GetName().c_str()); outputs.swap(tmp_outputs); return SUCCESS; diff --git a/ge/graph/build/model_builder.cc b/ge/graph/build/model_builder.cc index 0639322d..a2729c57 100755 --- a/ge/graph/build/model_builder.cc +++ b/ge/graph/build/model_builder.cc @@ -569,11 +569,7 @@ Status ModelBuilder::MergeWeights() { return FAILED; } } -#ifndef ONLY_COMPILE_OPEN_SRC weight->ClearData(); -#else - weight_data.clear(); -#endif } return SUCCESS;