From c4496510d07241045db35abe5d6a3ecc4ff24403 Mon Sep 17 00:00:00 2001 From: zhangxiaokun Date: Mon, 11 Jan 2021 16:56:11 +0800 Subject: [PATCH] Remove subgraph control only const --- .../passes/subgraph_const_migration_pass.cc | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/ge/graph/passes/subgraph_const_migration_pass.cc b/ge/graph/passes/subgraph_const_migration_pass.cc index f131942c..864fcec1 100644 --- a/ge/graph/passes/subgraph_const_migration_pass.cc +++ b/ge/graph/passes/subgraph_const_migration_pass.cc @@ -145,6 +145,7 @@ Status SubgraphConstMigrationPass::ClassifyGraphNodes(const ComputeGraphPtr &gra return GE_GRAPH_EMPTY_SUBGRAPH; } + set ctrl_only_const_nodes; auto &data_nodes = all_data_nodes[subgraph]; auto &const_nodes = all_const_nodes[subgraph]; for (auto &node : subgraph->GetDirectNode()) { @@ -178,15 +179,26 @@ Status SubgraphConstMigrationPass::ClassifyGraphNodes(const ComputeGraphPtr &gra peer_name_list.insert(fixed_name + ":" + std::to_string(in_anchor->GetIdx())); } + if (peer_name_list.empty()) { + ctrl_only_const_nodes.insert(node); + GELOGI("%s, Const: %s, no data link will removed", subgraph->GetName().c_str(), node->GetName().c_str()); + continue; + } + string key_of_const; for (const string &name : peer_name_list) { key_of_const += (key_of_const.empty() ? name : "_" + name); } const_nodes[key_of_const] = node; - GELOGD("%s, Key: %s, Const: %s", subgraph->GetName().c_str(), key_of_const.c_str(), node->GetName().c_str()); + GELOGD("%s, Const: %s, Key: %s", subgraph->GetName().c_str(), node->GetName().c_str(), key_of_const.c_str()); } } + + for (auto &node : ctrl_only_const_nodes) { + GE_CHK_GRAPH_STATUS_RET(GraphUtils::RemoveNodeWithoutRelink(subgraph, node), + "Remove node without relink failed, node: %s", node->GetName().c_str()); + } } return SUCCESS; @@ -352,7 +364,8 @@ Status SubgraphConstMigrationPass::DetachParallelNode(const ComputeGraphPtr &gra const auto owner_node = out_anchor->GetOwnerNode(); GELOGI("Remove Edge: %s %s", owner_node->GetName().c_str(), const_node->GetName().c_str()); if (owner_node->GetInAllNodes().empty() && owner_node->GetOutAllNodes().empty() && owner_node != data_node) { - graph->RemoveNode(owner_node); + GE_CHK_GRAPH_STATUS_RET(GraphUtils::RemoveNodeWithoutRelink(graph, owner_node), + "Remove node without relink failed, node: %s", owner_node->GetName().c_str()); } } @@ -414,7 +427,8 @@ Status SubgraphConstMigrationPass::AttachParallelNode(const ComputeGraphPtr &gra const auto owner_node = out_anchor->GetOwnerNode(); GELOGI("Remove Edge: %s %s", owner_node->GetName().c_str(), func_node->GetName().c_str()); if (owner_node->GetInAllNodes().empty() && owner_node->GetOutAllNodes().empty()) { - graph->RemoveNode(owner_node); + GE_CHK_GRAPH_STATUS_RET(GraphUtils::RemoveNodeWithoutRelink(graph, owner_node), + "Remove node without relink failed, node: %s", owner_node->GetName().c_str()); } } GE_CHK_GRAPH_STATUS_RET(GraphUtils::AddEdge(const_node->GetOutDataAnchor(kZeroIndex), in_anchor), "Add edge failed"); @@ -472,7 +486,8 @@ Status SubgraphConstMigrationPass::MoveNodeToParent(const ComputeGraphPtr &graph return FAILED; } - GE_CHK_GRAPH_STATUS_RET(subgraph->RemoveNode(move_node), "Remove node failed"); + GE_CHK_GRAPH_STATUS_RET(GraphUtils::RemoveNodeWithoutRelink(subgraph, move_node), + "Remove node without relink failed, node: %s", move_node->GetName().c_str()); GELOGI("Remove Node: %s %s", subgraph->GetName().c_str(), move_node->GetName().c_str()); }