diff --git a/ge/graph/passes/subgraph_const_migration_pass.cc b/ge/graph/passes/subgraph_const_migration_pass.cc index f131942c..d2effd44 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,30 @@ Status SubgraphConstMigrationPass::ClassifyGraphNodes(const ComputeGraphPtr &gra peer_name_list.insert(fixed_name + ":" + std::to_string(in_anchor->GetIdx())); } + if (peer_name_list.empty()) { + GELOGI("%s, Const: %s, no data output", subgraph->GetName().c_str(), node->GetName().c_str()); + const auto in_all_nodes = node->GetInAllNodes(); + if (in_all_nodes.empty() || std::all_of(in_all_nodes.begin(), in_all_nodes.end(), + [](const NodePtr &n) { return n->GetType() == DATA; })) { + ctrl_only_const_nodes.insert(node); + } + 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 +368,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 +431,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"); @@ -442,7 +460,8 @@ Status SubgraphConstMigrationPass::MoveNodeToParent(const ComputeGraphPtr &graph const map> &all_data_nodes, const string &node_key, uint32_t parent_index) { if (node_key.empty() || parent_index == kInvalidParent) { - GELOGE(FAILED, "Graph: %s, inputs is empty", graph->GetName().c_str()); + GELOGE(FAILED, "Graph: %s, node key: %s, parent index: %u invalid", + graph->GetName().c_str(), node_key.c_str(), parent_index); return FAILED; } @@ -472,7 +491,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()); }