diff --git a/mindspore/ccsrc/backend/session/ascend_session.cc b/mindspore/ccsrc/backend/session/ascend_session.cc index cd2ecd784b4..3c43ab8d20d 100644 --- a/mindspore/ccsrc/backend/session/ascend_session.cc +++ b/mindspore/ccsrc/backend/session/ascend_session.cc @@ -984,6 +984,9 @@ void AscendSession::Execute(const std::shared_ptr &kernel_graph, bo #endif MS_LOG(EXCEPTION) << "run task error!"; } +#ifdef ENABLE_DUMP_IR + mindspore::RDR::ClearAll(); +#endif MS_LOG(INFO) << "Finish!"; } diff --git a/mindspore/ccsrc/debug/rdr/base_recorder.h b/mindspore/ccsrc/debug/rdr/base_recorder.h index fd9f5faeebe..61d25f3b726 100644 --- a/mindspore/ccsrc/debug/rdr/base_recorder.h +++ b/mindspore/ccsrc/debug/rdr/base_recorder.h @@ -57,7 +57,7 @@ class BaseRecorder { timestamp_ = ss.str(); } } - ~BaseRecorder() {} + virtual ~BaseRecorder() {} std::string GetModule() const { return module_; } std::string GetTag() const { return tag_; } diff --git a/mindspore/ccsrc/debug/rdr/recorder_manager.cc b/mindspore/ccsrc/debug/rdr/recorder_manager.cc index 44859ae8240..19f087c424b 100644 --- a/mindspore/ccsrc/debug/rdr/recorder_manager.cc +++ b/mindspore/ccsrc/debug/rdr/recorder_manager.cc @@ -52,4 +52,6 @@ void RecorderManager::TriggerAll() { MS_LOG(WARNING) << "There is no recorder to export."; } } + +void RecorderManager::ClearAll() { recorder_container_.clear(); } } // namespace mindspore diff --git a/mindspore/ccsrc/debug/rdr/recorder_manager.h b/mindspore/ccsrc/debug/rdr/recorder_manager.h index 4f4b9c5d383..a78c21da324 100644 --- a/mindspore/ccsrc/debug/rdr/recorder_manager.h +++ b/mindspore/ccsrc/debug/rdr/recorder_manager.h @@ -36,6 +36,7 @@ class RecorderManager { bool RecordObject(const BaseRecorderPtr &recorder); void TriggerAll(); + void ClearAll(); private: RecorderManager() {} diff --git a/mindspore/ccsrc/debug/rdr/running_data_recorder.cc b/mindspore/ccsrc/debug/rdr/running_data_recorder.cc index 07a4be4c43e..ef08b948082 100644 --- a/mindspore/ccsrc/debug/rdr/running_data_recorder.cc +++ b/mindspore/ccsrc/debug/rdr/running_data_recorder.cc @@ -87,6 +87,8 @@ bool RecordString(SubModuleId module, const std::string &tag, const std::string void TriggerAll() { mindspore::RecorderManager::Instance().TriggerAll(); } +void ClearAll() { mindspore::RecorderManager::Instance().ClearAll(); } + #else bool RecordAnfGraph(const SubModuleId module, const std::string &tag, const FuncGraphPtr &graph, bool full_name, const std::string &file_type, int graph_id) { diff --git a/mindspore/ccsrc/debug/rdr/running_data_recorder.h b/mindspore/ccsrc/debug/rdr/running_data_recorder.h index 483ec753ae5..0a768815c4e 100644 --- a/mindspore/ccsrc/debug/rdr/running_data_recorder.h +++ b/mindspore/ccsrc/debug/rdr/running_data_recorder.h @@ -34,6 +34,7 @@ bool RecordGraphExecOrder(const SubModuleId module, const std::string &tag, bool RecordString(SubModuleId module, const std::string &tag, const std::string &data, const std::string &filename = ""); void TriggerAll(); +void ClearAll(); } // namespace RDR } // namespace mindspore #endif // MINDSPORE_CCSRC_DEBUG_RDR_RUNNING_DATA_RECORDER_H_ diff --git a/mindspore/ccsrc/frontend/optimizer/optimizer.h b/mindspore/ccsrc/frontend/optimizer/optimizer.h index 17c381ec56c..60a7482ca1f 100644 --- a/mindspore/ccsrc/frontend/optimizer/optimizer.h +++ b/mindspore/ccsrc/frontend/optimizer/optimizer.h @@ -146,15 +146,22 @@ class Optimizer : public std::enable_shared_from_this { // Optimizer step counter; int64_t counter = 1; bool changes = true; + // If no changes since last renormalization, then no need to do the renormalization again. + // Set the initial value to true, so the renormalization can be executed once if it's the + // only pass. + bool changes_since_last_renorm = true; while (changes) { changes = false; - auto run_runc = [&counter, &func_graph, &changes, use_profile, this]() { + auto run_runc = [&counter, &func_graph, &changes, &changes_since_last_renorm, use_profile, this]() { for (size_t i = 0; i < passes_.size(); ++i) { const OptPass &opt = passes_[i]; CurPass_ = {counter, pass_names_[i]}; - auto opt_func = [&func_graph, &changes, &opt, this]() { + auto opt_func = [&func_graph, &changes, &opt, &changes_since_last_renorm, this]() { if (opt.is_renormalize()) { + if (!changes_since_last_renorm) { + return; + } auto resource_ptr = std::dynamic_pointer_cast(resource_); if (resource_ptr != nullptr) { // StepParallel may replace the AbstractValue of the parameters of func_graph, @@ -177,8 +184,10 @@ class Optimizer : public std::enable_shared_from_this { func_graph = pipeline::Renormalize(resource_ptr, func_graph, maybe_new_args_spec); } } + changes_since_last_renorm = false; } else if (opt(func_graph, shared_from_this())) { changes = true; + changes_since_last_renorm = true; } }; use_profile ? (WITH(MsProfile::GetProfile()->Step(pass_names_[i])) opt_func) : opt_func();