diff --git a/mindspore/ccsrc/session/ascend_session.cc b/mindspore/ccsrc/session/ascend_session.cc index 9c92749e4b0ca473b9c516c44a0d4d876df6262b..397ed8f94a92132e6d21f79b6728345b76101eda 100644 --- a/mindspore/ccsrc/session/ascend_session.cc +++ b/mindspore/ccsrc/session/ascend_session.cc @@ -289,22 +289,6 @@ static void RecurseToUpdateCallRealInput(NotNull graph, // this action should from bottom to top graph->UpdateCallRealInput(); } - -void InsertMakeTupleForEmptyGraph(NotNull graph) { - auto return_node = graph->get_return(); - MS_EXCEPTION_IF_NULL(return_node); - if (return_node->size() <= kReturnDataIndex) { - return; - } - auto origin_output = return_node->input(kReturnDataIndex); - MS_EXCEPTION_IF_NULL(origin_output); - std::vector make_tuple_input{ - std::make_shared(std::make_shared(prim::kPrimMakeTuple->name())), origin_output}; - auto new_outputs = graph->NewCNode(make_tuple_input); - MS_EXCEPTION_IF_NULL(new_outputs); - new_outputs->set_abstract(origin_output->abstract()); - return_node->set_input(kReturnDataIndex, new_outputs); -} } // namespace GraphId AscendSession::CompileGraph(const AnfNodePtrList &lst, const AnfNodePtrList &outputs) { @@ -321,17 +305,15 @@ GraphId AscendSession::CompileGraph(NotNull func_graph) { std::vector all_graphs; auto root_graph = ConstructKernelGraph(func_graph, &all_graphs); BackendOptimization(all_graphs); + // split switch + SplitGraphs(NOT_NULL(root_graph)); // empty graph dont entry to backend - if (std::none_of(root_graph->execution_order().begin(), root_graph->execution_order().end(), - [](const CNodePtr &cnode) -> bool { return AnfAlgo::IsRealKernel(cnode); })) { + if (root_graph->execution_order().empty()) { MS_LOG(INFO) << root_graph->ToString() << " is empty graph."; - InsertMakeTupleForEmptyGraph(NOT_NULL(root_graph)); root_graph->set_executable(false); InitRuntimeResource(); return root_graph->graph_id(); } - // split switch - SplitGraphs(NOT_NULL(root_graph)); // insert goto labels and label_sets LinkChildGraphs(NOT_NULL(root_graph)); // resource initialize @@ -1649,6 +1631,10 @@ void AscendSession::BackendOptimization(const std::vector &all_g void AscendSession::SplitGraphs(NotNull root_graph) { std::set memo; + // if output of graph is nullptr,no need insert maketuple at the end of graph + if (root_graph->output() == nullptr) { + return; + } // if root graph output is a call node ,the root graph is condition graph of 'if' sentence auto root_graph_output = AnfAlgo::VisitKernelWithReturnType(root_graph->output(), 0).first; if (AnfAlgo::CheckPrimitiveType(root_graph_output, prim::kPrimCall)) {