From 9801866dfc58f65826f4651a76bcd14d725f4efd Mon Sep 17 00:00:00 2001 From: lichun Date: Mon, 30 Nov 2020 12:15:11 +0800 Subject: [PATCH] Fix the error of unexpected executor type --- ge/hybrid/model/hybrid_model_builder.cc | 34 +++++++++++++++++++------------- ge/hybrid/model/hybrid_model_builder.h | 1 + ge/hybrid/node_executor/node_executor.cc | 18 ++++++++--------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/ge/hybrid/model/hybrid_model_builder.cc b/ge/hybrid/model/hybrid_model_builder.cc index 2be38897..a44efb4f 100755 --- a/ge/hybrid/model/hybrid_model_builder.cc +++ b/ge/hybrid/model/hybrid_model_builder.cc @@ -39,15 +39,6 @@ const uint32_t kAlignment = 32; const int kBytes = 8; const char *const kOwnerGraphIsUnknown = "OwnerGraphIsUnknown"; -bool IsGraphUnknown(ComputeGraph &graph) { - for (const auto &node : graph.GetDirectNode()) { - bool is_unknown_shape = false; - (void)AttrUtils::GetBool(node->GetOpDesc(), kOwnerGraphIsUnknown, is_unknown_shape); - return is_unknown_shape; - } - return false; -} - int64_t CalcVarSizeInBytes(const GeTensorDesc &desc) { int64_t var_size = 0; auto data_type = desc.GetDataType(); @@ -111,6 +102,7 @@ Status HybridModelBuilder::Build() { hybrid_model_.model_name_ = ge_root_model_->GetRootGraph()->GetName(); GELOGI("[%s] Start to build hybrid model.", GetGraphName()); GE_CHK_STATUS_RET(InitRuntimeParams(), "[%s] Failed to InitRuntimeParams", GetGraphName()); + GE_CHK_STATUS_RET(RecoverGraphUnknownFlag(), "[%s] Failed to RecoverGraphUnknownFlag", GetGraphName()); GE_CHK_STATUS_RET(IndexSpecialNodes(), "[%s] Failed to index nodes", GetGraphName()); GE_CHK_STATUS_RET(IndexTaskDefs(), "[%s] Failed to index task defs", GetGraphName()); GE_CHK_STATUS_RET(LoadGraph(), "[%s] Failed to load graph", GetGraphName()); @@ -566,7 +558,7 @@ Status HybridModelBuilder::UnfoldSubgraphs(ComputeGraph &root_graph, ComputeGrap auto subgraph = NodeUtils::GetSubgraph(*node, kSubgraphIndex); GE_CHECK_NOTNULL(subgraph); - bool is_unknown_shape = IsGraphUnknown(*subgraph); + bool is_unknown_shape = subgraph->GetGraphUnknownFlag(); if (!is_unknown_shape) { merged_graph->AddNode(node); GELOGD("[%s] Known shape partitioned call added to merged graph.", op_desc->GetName().c_str()); @@ -613,7 +605,7 @@ Status HybridModelBuilder::UnfoldSubgraph(ComputeGraph &root_graph, if (sub_op_type == PARTITIONEDCALL) { auto sub_sub_graph = NodeUtils::GetSubgraph(*sub_node, kSubgraphIndex); GE_CHECK_NOTNULL(sub_sub_graph); - if (IsGraphUnknown(*sub_sub_graph)) { + if (sub_sub_graph->GetGraphUnknownFlag()) { GE_CHK_STATUS_RET(UnfoldSubgraph(root_graph, parent_graph, *sub_sub_graph), "[%s] Failed to merge subgraph", sub_sub_graph->GetName().c_str()); @@ -703,7 +695,7 @@ Status HybridModelBuilder::LoadGraph() { continue; } - if (IsGraphUnknown(*sub_graph)) { + if (sub_graph->GetGraphUnknownFlag()) { GE_CHK_STATUS_RET(LoadDynamicSubgraph(*sub_graph, false), "Failed to load subgraph: [%s]", sub_graph->GetName().c_str()); @@ -957,7 +949,7 @@ Status HybridModelBuilder::IndexTaskDefs() { continue; } - bool is_unknown_shape = IsGraphUnknown(*sub_graph); + bool is_unknown_shape = sub_graph->GetGraphUnknownFlag(); if (!is_unknown_shape) { GE_CHK_STATUS_RET_NOLOG(LoadGeModel(*sub_graph, ge_model)); continue; @@ -1208,7 +1200,7 @@ Status HybridModelBuilder::IdentifySameInputs(NodeItem &node_item) { in_data_anchor->GetIdx(), it->second, src_node->GetName().c_str(), - out_data_anchor->GetIdx()); + out_data_anchor->GetIdx()); node_item.reuse_outputs.emplace(in_data_anchor->GetIdx(), it->second); } } @@ -1421,6 +1413,20 @@ Status HybridModelBuilder::LoadKnownShapedSubgraph(ComputeGraph &graph, NodeItem return SUCCESS; } +Status HybridModelBuilder::RecoverGraphUnknownFlag() { + const auto &root_graph = ge_root_model_->GetRootGraph(); + for (auto &sub_graph : root_graph->GetAllSubgraphs()) { + GE_CHECK_NOTNULL(sub_graph); + for (const auto &node : sub_graph->GetDirectNode()) { + bool is_unknown_shape = false; + (void)AttrUtils::GetBool(node->GetOpDesc(), kOwnerGraphIsUnknown, is_unknown_shape); + sub_graph->SetGraphUnknownFlag(is_unknown_shape); + break; + } + } + return SUCCESS; +} + Status HybridModelBuilder::LoadDynamicSubgraph(ComputeGraph &graph, bool is_root_graph) { GELOGD("Start to load subgraph [%s]", graph.GetName().c_str()); // for known partitioned call, load all nodes diff --git a/ge/hybrid/model/hybrid_model_builder.h b/ge/hybrid/model/hybrid_model_builder.h index 86e5ec01..b90ec982 100644 --- a/ge/hybrid/model/hybrid_model_builder.h +++ b/ge/hybrid/model/hybrid_model_builder.h @@ -77,6 +77,7 @@ class HybridModelBuilder { Status LoadDynamicSubgraph(ComputeGraph &graph, bool is_root_graph); Status ParseVarOutputs(NodeItem &node_item); Status LoadKnownShapedSubgraph(ComputeGraph &graph, NodeItem *parent_node_item); + Status RecoverGraphUnknownFlag(); const char* GetGraphName() const { return hybrid_model_.model_name_.c_str(); diff --git a/ge/hybrid/node_executor/node_executor.cc b/ge/hybrid/node_executor/node_executor.cc index 4055ec4d..c8f426c8 100755 --- a/ge/hybrid/node_executor/node_executor.cc +++ b/ge/hybrid/node_executor/node_executor.cc @@ -82,17 +82,15 @@ NodeExecutorManager::ExecutorType NodeExecutorManager::ResolveExecutorType(Node auto op_type = node.GetType(); if (op_type == PARTITIONEDCALL) { const auto &subgraph = NodeUtils::GetSubgraph(node, 0); - if (subgraph != nullptr) { - for (const auto &node : subgraph->GetDirectNode()) { - bool is_unknown_shape = false; - (void)AttrUtils::GetBool(node->GetOpDesc(), kOwnerGraphIsUnknown, is_unknown_shape); - if (is_unknown_shape) { - return ExecutorType::DYNAMIC_SUBGRAPH; - } else { - return ExecutorType::COMPILED_SUBGRAPH; - } - } + if (subgraph != nullptr && subgraph->GetGraphUnknownFlag()) { + return ExecutorType::DYNAMIC_SUBGRAPH; + } + bool is_dynamic = false; + (void)NodeUtils::GetNodeUnknownShapeStatus(node, is_dynamic); + if (is_dynamic) { + return ExecutorType::DYNAMIC_SUBGRAPH; } + return ExecutorType::COMPILED_SUBGRAPH; } // rts kernel store is assigned to NetOutput