From 72e567d06b6a32dbb55310ece52f2fdc3a5cc7dc Mon Sep 17 00:00:00 2001 From: louei5 Date: Thu, 4 Feb 2021 14:16:22 +0800 Subject: [PATCH] change saving filename in RDR module --- .../ascend/ascend_backend_optimization.cc | 4 +- mindspore/ccsrc/backend/session/executor.cc | 5 -- mindspore/ccsrc/debug/rdr/base_recorder.h | 2 +- .../debug/rdr/graph_exec_order_recorder.cc | 5 +- mindspore/ccsrc/debug/rdr/graph_recorder.cc | 63 +++++++------------ 5 files changed, 30 insertions(+), 49 deletions(-) diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ascend_backend_optimization.cc b/mindspore/ccsrc/backend/optimizer/ascend/ascend_backend_optimization.cc index 3908ed00d3f..f153fa74732 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ascend_backend_optimization.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ascend_backend_optimization.cc @@ -266,7 +266,7 @@ void AscendBackendIRFusionOptimization(const std::shared_ptrget_param(MS_CTX_SAVE_GRAPHS_FLAG); #ifdef ENABLE_DUMP_IR - std::string tag = "before_hwopt"; + std::string tag = "hwopt_before_graph"; mindspore::RDR::RecordAnfGraph(SubModuleId::SM_OPTIMIZER, tag, kernel_graph, false, ".ir;.pb"); #endif if (save_graphs) { @@ -389,7 +389,7 @@ void AscendBackendOptimization(const std::shared_ptr &kern (void)optimizer2->Optimize(kernel_graph); kernel_graph->SetExecOrderByDefault(); #ifdef ENABLE_DUMP_IR - std::string tag = "hwopt_d_end"; + std::string tag = "hwopt_after_graph"; mindspore::RDR::RecordAnfGraph(SubModuleId::SM_OPTIMIZER, tag, kernel_graph, true, ".ir;.pb"); const std::vector &exec_order = kernel_graph->execution_order(); std::vector graph_exec_order(exec_order); diff --git a/mindspore/ccsrc/backend/session/executor.cc b/mindspore/ccsrc/backend/session/executor.cc index 8fc9eeb4a9b..7c3d8ad323c 100644 --- a/mindspore/ccsrc/backend/session/executor.cc +++ b/mindspore/ccsrc/backend/session/executor.cc @@ -117,11 +117,6 @@ void RunGraphTask::Run() { MS_LOG(ERROR) << "Invalid graph id " << graph_id_; return; } -#ifdef ENABLE_DUMP_IR - std::string tag = "run_graph"; - std::string file_type = ".ir;.pb"; - mindspore::RDR::RecordAnfGraph(SubModuleId::SM_SESSION, tag, graph, false, file_type); -#endif graph->ResetGraphRunningStatus(); try { session_->RunGraphImpl(graph_id_, input_tensors_, &outputs_); diff --git a/mindspore/ccsrc/debug/rdr/base_recorder.h b/mindspore/ccsrc/debug/rdr/base_recorder.h index 5d3da0348d6..9f16c3c7eb5 100644 --- a/mindspore/ccsrc/debug/rdr/base_recorder.h +++ b/mindspore/ccsrc/debug/rdr/base_recorder.h @@ -49,7 +49,7 @@ class BaseRecorder { std::string GetTimeStamp() const { return timestamp_; } void SetDirectory(const std::string &directory) { directory_ = directory; } - + std::string GetDirectory() const { return directory_; } virtual void Export() {} protected: diff --git a/mindspore/ccsrc/debug/rdr/graph_exec_order_recorder.cc b/mindspore/ccsrc/debug/rdr/graph_exec_order_recorder.cc index c52fbf1f772..a1d093b18e6 100644 --- a/mindspore/ccsrc/debug/rdr/graph_exec_order_recorder.cc +++ b/mindspore/ccsrc/debug/rdr/graph_exec_order_recorder.cc @@ -47,8 +47,9 @@ bool DumpGraphExeOrder(const std::string &filename, const std::vector void GraphExecOrderRecorder::Export() { if (filename_.empty()) { - filename_ = directory_ + module_ + "_" + tag_ + "_" + timestamp_ + ".txt"; + filename_ = module_ + "_" + tag_ + "_" + timestamp_; } - DumpGraphExeOrder(filename_, exec_order_); + std::string filename = directory_ + filename_ + ".txt"; + DumpGraphExeOrder(filename, exec_order_); } } // namespace mindspore diff --git a/mindspore/ccsrc/debug/rdr/graph_recorder.cc b/mindspore/ccsrc/debug/rdr/graph_recorder.cc index e02b64957e4..c509356acb4 100644 --- a/mindspore/ccsrc/debug/rdr/graph_recorder.cc +++ b/mindspore/ccsrc/debug/rdr/graph_recorder.cc @@ -20,9 +20,10 @@ #include "debug/anf_ir_dump.h" #include "debug/anf_ir_utils.h" #include "debug/dump_proto.h" +#include "debug/common.h" namespace mindspore { -namespace dumper { +namespace protobuf { #ifdef ENABLE_DUMP_IR void DumpIRProto(const std::string &filename, const FuncGraphPtr &func_graph) { if (func_graph == nullptr) { @@ -34,36 +35,26 @@ void DumpIRProto(const std::string &filename, const FuncGraphPtr &func_graph) { MS_LOG(ERROR) << "File path " << filename << " is too long."; return; } - char real_path[PATH_MAX] = {0}; - char *real_path_ret = nullptr; -#if defined(_WIN32) || defined(_WIN64) - real_path_ret = _fullpath(real_path, filename.c_str(), PATH_MAX); -#else - real_path_ret = realpath(filename.c_str(), real_path); -#endif - if (nullptr == real_path_ret) { - MS_LOG(DEBUG) << "dir " << filename << " does not exit."; - } else { - std::string path_string = real_path; - if (chmod(common::SafeCStr(path_string), S_IRUSR | S_IWUSR) == -1) { - MS_LOG(ERROR) << "Modify file:" << real_path << " to rw fail."; - return; - } - } + auto real_path = Common::GetRealPath(filename); + if (!real_path.has_value()) { + MS_LOG(ERROR) << "Get real path failed. path=" << filename; + return; + } + ChangeFileMode(real_path.value(), S_IRWXU); // write to pb file - std::ofstream ofs(real_path); + std::ofstream ofs(real_path.value()); if (!ofs.is_open()) { - MS_LOG(ERROR) << "Open file '" << real_path << "' failed!"; + MS_LOG(ERROR) << "Open file '" << real_path.value() << "' failed!"; return; } ofs << GetFuncGraphProtoString(func_graph); ofs.close(); // set file mode to read only by user - ChangeFileMode(real_path, S_IRUSR); + ChangeFileMode(real_path.value(), S_IRUSR); } #else -void DumpIRProto(const FuncGraphPtr &, const std::string &) { +void DumpIRProto(const std::string &, const FuncGraphPtr &) { static bool already_printed = false; if (already_printed) { return; @@ -73,41 +64,35 @@ void DumpIRProto(const FuncGraphPtr &, const std::string &) { << "please recompile source to enable it. See help of building script."; } #endif -} // namespace dumper +} // namespace protobuf void GraphRecorder::Export() { bool save_flag = false; if (filename_.empty()) { filename_ = module_ + "_" + tag_ + "_" + timestamp_; } - if (filename_.length() > 255) { // 255: filename maximum length - filename_ = filename_.substr(0, 255); - } - filename_ = directory_ + filename_; - if (filename_.size() + 3 > PATH_MAX) { // 3: file format length - MS_LOG(ERROR) << "File path " << filename_ << " is too long."; - return; - } - + std::string file_path = directory_ + filename_ + std::to_string(id_); if (graph_type_.find(".dat") != std::string::npos) { save_flag = true; - AnfExporter exporter(std::to_string(id_)); - std::string filename = filename_ + ".dat"; - ChangeFileMode(filename, S_IRWXU); - exporter.ExportFuncGraph(filename, func_graph_); - ChangeFileMode(filename, S_IRUSR); + AnfExporter exporter(""); + std::string real_path = file_path + ".dat"; + ChangeFileMode(real_path, S_IRWXU); + exporter.ExportFuncGraph(real_path, func_graph_); + ChangeFileMode(real_path, S_IRUSR); } if (graph_type_.find(".ir") != std::string::npos) { save_flag = true; + std::string real_path = file_path + ".ir"; if (full_name_) { - DumpIRForRDR(filename_ + ".ir", func_graph_, true, kTopStack); + DumpIRForRDR(real_path, func_graph_, true, kTopStack); } else { - DumpIRForRDR(filename_ + ".ir", func_graph_, false, kOff); + DumpIRForRDR(real_path, func_graph_, false, kOff); } } if (graph_type_.find(".pb") != std::string::npos) { save_flag = true; - dumper::DumpIRProto(filename_ + ".pb", func_graph_); // save *.pb file + std::string real_path = file_path + ".pb"; + protobuf::DumpIRProto(real_path, func_graph_); // save *.pb file } if (!save_flag) { MS_LOG(WARNING) << "Unknown save graph type: " << graph_type_;