diff --git a/mindspore/ccsrc/backend/session/ascend_session.cc b/mindspore/ccsrc/backend/session/ascend_session.cc index f8b021e7e9..5c7826e8d3 100644 --- a/mindspore/ccsrc/backend/session/ascend_session.cc +++ b/mindspore/ccsrc/backend/session/ascend_session.cc @@ -66,6 +66,7 @@ #ifdef ENABLE_DUMP_IR #include "debug/rdr/running_data_recorder.h" #include "debug/rdr/recorder_manager.h" +#include "debug/rdr/graph_recorder.h" #include "runtime/device/ascend/ascend_bucket.h" #endif #if ENABLE_CPU && ENABLE_D @@ -1011,7 +1012,8 @@ void AscendSession::DumpAllGraphs(const std::vector &all_graphs) for (auto &graph : all_graphs) { MS_EXCEPTION_IF_NULL(graph); std::string name = "graph_build." + std::to_string(graph->graph_id()); - mindspore::RDR::RecordAnfGraph(SUBMODULE_ID, name, graph, true, ".ir;.pb"); + DumpGraphParams dump_params = {true, static_cast(kWholeStack)}; + mindspore::RDR::RecordAnfGraph(SUBMODULE_ID, name, graph, dump_params, ".ir;.pb"); if (save_graphs) { std::string file_name = "graph_build_" + std::to_string(graph->graph_id()) + ".ir"; DumpIR(file_name, graph, true, kWholeStack); diff --git a/mindspore/ccsrc/backend/session/gpu_session.cc b/mindspore/ccsrc/backend/session/gpu_session.cc index 78a0db54e0..ac9e3a8050 100644 --- a/mindspore/ccsrc/backend/session/gpu_session.cc +++ b/mindspore/ccsrc/backend/session/gpu_session.cc @@ -374,7 +374,8 @@ GraphId GPUSession::CompileGraphImpl(KernelGraphPtr graph) { BuildKernel(graph); #ifdef ENABLE_DUMP_IR std::string name = "graph_build"; - mindspore::RDR::RecordAnfGraph(SubModuleId::SM_SESSION, name, graph, false, ".ir,.pb"); + DumpGraphParams dump_params = {true, static_cast(kWholeStack)}; + mindspore::RDR::RecordAnfGraph(SubModuleId::SM_SESSION, name, graph, dump_params, ".ir,.pb"); #endif // Get summary nodes. SetSummaryNodes(graph.get()); diff --git a/mindspore/ccsrc/debug/rdr/graph_recorder.cc b/mindspore/ccsrc/debug/rdr/graph_recorder.cc index d2b1607cdd..cd8a2d72d4 100644 --- a/mindspore/ccsrc/debug/rdr/graph_recorder.cc +++ b/mindspore/ccsrc/debug/rdr/graph_recorder.cc @@ -74,10 +74,13 @@ void GraphRecorder::Export() { if (graph_type_.find(".ir") != std::string::npos) { save_flag = true; std::string realpath_ir = realpath + ".ir"; - if (full_name_) { - DumpIRForRDR(realpath_ir, func_graph_, true, kTopStack); + if (dump_graph_info_.dump_mode <= static_cast(kWholeStack) && + dump_graph_info_.dump_mode >= static_cast(kOff)) { + LocDumpMode dump_mode = LocDumpMode(dump_graph_info_.dump_mode); + DumpIRForRDR(realpath_ir, func_graph_, dump_graph_info_.dump_full_name, dump_mode); } else { - DumpIRForRDR(realpath_ir, func_graph_, false, kWholeStack); + MS_LOG(WARNING) << "Unknown save graph LocDumoMode: " << dump_graph_info_.dump_mode + << ", it must be in the range [0,2]."; } } if (graph_type_.find(".pb") != std::string::npos) { diff --git a/mindspore/ccsrc/debug/rdr/graph_recorder.h b/mindspore/ccsrc/debug/rdr/graph_recorder.h index 5aa3a3172a..0e546c6d26 100644 --- a/mindspore/ccsrc/debug/rdr/graph_recorder.h +++ b/mindspore/ccsrc/debug/rdr/graph_recorder.h @@ -19,9 +19,13 @@ #include #include -#include "debug/anf_ir_utils.h" #include "debug/rdr/base_recorder.h" + namespace mindspore { +struct DumpGraphParams { + bool dump_full_name; + int dump_mode; +}; class FuncGraph; using FuncGraphPtr = std::shared_ptr; class GraphRecorder : public BaseRecorder { @@ -33,14 +37,14 @@ class GraphRecorder : public BaseRecorder { ~GraphRecorder() {} void SetGraphType(const std::string &file_type) { graph_type_ = file_type; } void SetFuncGraph(const FuncGraphPtr &func_graph) { func_graph_ = func_graph; } - void SetDumpFlag(bool full_name) { full_name_ = full_name; } + void SetDumpFlag(DumpGraphParams info) { dump_graph_info_ = info; } virtual void Export(); private: FuncGraphPtr func_graph_; std::string graph_type_; - bool full_name_{false}; + DumpGraphParams dump_graph_info_; }; using GraphRecorderPtr = std::shared_ptr; } // namespace mindspore diff --git a/mindspore/ccsrc/debug/rdr/running_data_recorder.cc b/mindspore/ccsrc/debug/rdr/running_data_recorder.cc index c180a27c58..d28d08ab6e 100644 --- a/mindspore/ccsrc/debug/rdr/running_data_recorder.cc +++ b/mindspore/ccsrc/debug/rdr/running_data_recorder.cc @@ -15,7 +15,7 @@ */ #include "debug/rdr/running_data_recorder.h" #include -#include "debug/rdr/graph_recorder.h" + #include "debug/rdr/graph_exec_order_recorder.h" #include "debug/rdr/recorder_manager.h" #include "debug/rdr/string_recorder.h" @@ -78,14 +78,14 @@ bool RecordTaskDebugInfo(SubModuleId module, const std::string &name, } #endif // ENABLE_D -bool RecordAnfGraph(const SubModuleId module, const std::string &name, const FuncGraphPtr &graph, bool full_name, - const std::string &file_type) { +bool RecordAnfGraph(const SubModuleId module, const std::string &name, const FuncGraphPtr &graph, + const DumpGraphParams &info, const std::string &file_type) { if (!mindspore::RecorderManager::Instance().RdrEnable()) { return false; } std::string submodule_name = std::string(GetSubModuleName(module)); GraphRecorderPtr graph_recorder = std::make_shared(submodule_name, name, graph, file_type); - graph_recorder->SetDumpFlag(full_name); + graph_recorder->SetDumpFlag(info); bool ans = mindspore::RecorderManager::Instance().RecordObject(std::move(graph_recorder)); return ans; } diff --git a/mindspore/ccsrc/debug/rdr/running_data_recorder.h b/mindspore/ccsrc/debug/rdr/running_data_recorder.h index 1aecf060ec..3d76c570c7 100644 --- a/mindspore/ccsrc/debug/rdr/running_data_recorder.h +++ b/mindspore/ccsrc/debug/rdr/running_data_recorder.h @@ -20,6 +20,8 @@ #include #include "mindspore/core/utils/log_adapter.h" +#include "debug/rdr/graph_recorder.h" + namespace mindspore { class FuncGraph; class CNode; @@ -44,8 +46,8 @@ using TaskDebugInfoPtr = std::shared_ptr &final_exec_order); bool RecordString(SubModuleId module, const std::string &name, const std::string &data); diff --git a/mindspore/ccsrc/pipeline/jit/pipeline.cc b/mindspore/ccsrc/pipeline/jit/pipeline.cc index 9bb41a09de..5a768184a3 100644 --- a/mindspore/ccsrc/pipeline/jit/pipeline.cc +++ b/mindspore/ccsrc/pipeline/jit/pipeline.cc @@ -741,7 +741,11 @@ void Pipeline::Run() { if (graph != nullptr) { auto graph_clone = BasicClone(graph); if (graph_clone != nullptr) { - mindspore::RDR::RecordAnfGraph(SUBMODULE_ID, name, graph_clone, false, ".ir"); + DumpGraphParams dump_params = {false, static_cast(kTopStack)}; + if (i == actions_.size()) { + dump_params.dump_mode = static_cast(kWholeStack); + } + mindspore::RDR::RecordAnfGraph(SUBMODULE_ID, name, graph_clone, dump_params, ".ir"); } else { MS_LOG(WARNING) << "Clone FuncGraph failed in pipeline, no FuncGraph recording in RDR."; }