From dbafeb85315b939efad473d26b5595e7111d7fe9 Mon Sep 17 00:00:00 2001 From: "gengchao4@huawei.com" Date: Tue, 6 Apr 2021 15:17:53 +0800 Subject: [PATCH 1/2] add netoupt alwways --- ge/graph/build/task_generator.cc | 4 +++- ge/graph/passes/net_output_pass.cc | 12 +++++++++--- ge/host_cpu_engine/ops_kernel_store/op/host_op.cc | 1 + .../node_executor/host_cpu/kernel/no_op_kernel.cc | 1 + 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ge/graph/build/task_generator.cc b/ge/graph/build/task_generator.cc index 28101426..25095d75 100755 --- a/ge/graph/build/task_generator.cc +++ b/ge/graph/build/task_generator.cc @@ -795,7 +795,9 @@ uint32_t TaskGenerator::FindLastBpFromBpNode(const ComputeGraphPtr &graph, const GELOGI("bp_op_desc is %s, id is %ld", bp_op_desc->GetName().c_str(), bp_op_desc->GetId()); } - GE_CHECK_NOTNULL(bp_op_desc); + if (bp_op_desc == nullptr) { + return last_bp; + } uint32_t current_idx = 0; for (auto &node : graph->GetNodes(graph->GetGraphUnknownFlag())) { OpDescPtr op_desc = node->GetOpDesc(); diff --git a/ge/graph/passes/net_output_pass.cc b/ge/graph/passes/net_output_pass.cc index b203438e..100e73cd 100644 --- a/ge/graph/passes/net_output_pass.cc +++ b/ge/graph/passes/net_output_pass.cc @@ -40,6 +40,7 @@ static std::map output_type_str_to_datatype = { // the size of user defined output datatype or format string after split by ":". const size_t kUserDefinedElementCount = 2; +const size_t kNodesCount = 2; Status NetOutputPass::GetRetvalOutputInfo(const ge::NodePtr &node, std::map &retval_node_index_map) { @@ -424,11 +425,13 @@ Status NetOutputPass::AddCtrlEdgesBetweenLeafAndNetOutput(const ge::ComputeGraph GELOGI("No need to add ctrl edge to netoutput because user out nodes have been set."); return SUCCESS; } + bool graph_has_only_one_node_except_netoutput = (graph->GetDirectNodesSize() == kNodesCount); for (const auto &node : graph->GetDirectNode()) { if (node == nullptr || node->GetOpDesc() == nullptr || node->GetOpDesc()->GetType() == NETOUTPUT) { continue; } - if ((node->GetInControlNodes().size() != 0 || node->GetInDataNodes().size() != 0) && + if ((node->GetInControlNodes().size() != 0 || node->GetInDataNodes().size() != 0 || + graph_has_only_one_node_except_netoutput) && node->GetOutDataNodesSize() == 0 && node->GetOutControlNodes().size() == 0) { GE_CHK_STATUS_RET(GraphUtils::AddEdge(node->GetOutControlAnchor(), net_out_node->GetInControlAnchor()), "add edge failed"); @@ -493,10 +496,13 @@ Status NetOutputPass::AddNetOutputNodeToGraph(const ge::ComputeGraphPtr &graph, } GELOGI("[NETOUTPUT PASS] OutNodesInfo size:%zu, Targets Size:%zu, is_include_special_node_:%d", graph->GetGraphOutNodesInfo().size(), graph->GetGraphTargetNodesInfo().size(), is_include_special_node_); - // If user does not set out nodes and targets and no retval node, return false + // If user does not set out nodes and targets and no retval node, also add netoutput node if ((graph->GetGraphOutNodesInfo().empty()) && (graph->GetGraphTargetNodesInfo().empty()) && !is_include_special_node_) { - GELOGI("[NETOUTPUT PASS] output_nodes and target_nodes and special nodes is empty!It means no need netoutput!"); + GELOGI("[NETOUTPUT PASS] output_nodes and target_nodes and special nodes is empty!Add netoutput!"); + output_node = graph->AddNode(net_output_desc); + GE_CHK_STATUS_RET(AddCtrlEdgesBetweenLeafAndNetOutput(graph, output_node), + "add ctrl edge between leaf and netoutput failed"); return SUCCESS; } GELOGI("[NETOUTPUT PASS] Output node size:%lu.", output_nodes_info.size()); diff --git a/ge/host_cpu_engine/ops_kernel_store/op/host_op.cc b/ge/host_cpu_engine/ops_kernel_store/op/host_op.cc index 7f709f03..3e619635 100644 --- a/ge/host_cpu_engine/ops_kernel_store/op/host_op.cc +++ b/ge/host_cpu_engine/ops_kernel_store/op/host_op.cc @@ -35,5 +35,6 @@ REGISTER_OP_CREATOR(Mul, HostOp); REGISTER_OP_CREATOR(ConcatV2, HostOp); REGISTER_OP_CREATOR(Data, HostOp); REGISTER_OP_CREATOR(Fill, HostOp); +REGISTER_OP_CREATOR(NetOutput, HostOp); } // namespace host_cpu } // namespace ge diff --git a/ge/hybrid/node_executor/host_cpu/kernel/no_op_kernel.cc b/ge/hybrid/node_executor/host_cpu/kernel/no_op_kernel.cc index b1b4e68c..1d450166 100644 --- a/ge/hybrid/node_executor/host_cpu/kernel/no_op_kernel.cc +++ b/ge/hybrid/node_executor/host_cpu/kernel/no_op_kernel.cc @@ -28,6 +28,7 @@ Status NoOpKernel::Compute(TaskContext& context) { } REGISTER_KERNEL_CREATOR(NoOp, NoOpKernel); +REGISTER_KERNEL_CREATOR(NetOutput, NoOpKernel); } // namespace host_cpu } // namespace hybrid } // namespace ge From aeb0621113b2278cb1dc8d711612cb5f8f0bdc31 Mon Sep 17 00:00:00 2001 From: "gengchao4@huawei.com" Date: Tue, 6 Apr 2021 16:41:18 +0800 Subject: [PATCH 2/2] add netoupt alwways --- .../ge/graph/build/task_generator_unittest.cc | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/ut/ge/graph/build/task_generator_unittest.cc b/tests/ut/ge/graph/build/task_generator_unittest.cc index 95e75eb7..7e996cf1 100644 --- a/tests/ut/ge/graph/build/task_generator_unittest.cc +++ b/tests/ut/ge/graph/build/task_generator_unittest.cc @@ -51,6 +51,18 @@ class UtestTaskGeneratorTest : public testing::Test { builder.AddDataEdge(addn1, 0, netoutput, 0); return builder.GetGraph(); } + ge::ComputeGraphPtr BuildGraphBpProfiling() { + ge::ut::GraphBuilder builder("graph"); + auto data = builder.AddNode("data", "phony", 1, 1); + auto addn1 = builder.AddNode("addn1", "AddN", 1, 1); + auto netoutput = builder.AddNode("netoutput", "NetOutput", 2, 0); + auto op_desc = data->GetOpDesc(); + (void)AttrUtils::SetStr(op_desc, ATTR_NAME_FRAMEWORK_ORIGINAL_TYPE, "IteratorV2"); + op_desc->SetOpKernelLibName("GE"); + builder.AddDataEdge(data, 0, addn1, 0); + builder.AddControlEdge(addn1, netoutput); + return builder.GetGraph(); + } protected: void SetUp() {} @@ -66,3 +78,11 @@ TEST_F(UtestTaskGeneratorTest, AutoFindFpOpIndex) { // addn1 is fp EXPECT_EQ(profiling_point.fp_index, 2); } + +TEST_F(UtestTaskGeneratorTest, FindLastBpFromBpNode) { + auto graph = BuildGraphBpProfiling(); + TaskGenerator task_generator(nullptr, 0); + auto net_output = graph->FindNode("netoutput"); + // netoutput has no data input, return default value 0 + EXPECT_EQ(task_generator.FindLastBpFromBpNode(graph, net_output), 0); +}