Browse Source

improve dumpIR

tags/v1.1.0
Bairong 5 years ago
parent
commit
2368955eeb
4 changed files with 21 additions and 9 deletions
  1. +12
    -5
      mindspore/ccsrc/debug/anf_ir_dump.cc
  2. +2
    -1
      mindspore/ccsrc/debug/anf_ir_dump.h
  3. +6
    -2
      mindspore/ccsrc/pipeline/jit/pipeline.cc
  4. +1
    -1
      mindspore/core/utils/info.cc

+ 12
- 5
mindspore/ccsrc/debug/anf_ir_dump.cc View File

@@ -30,6 +30,7 @@
#include "pipeline/jit/base.h" #include "pipeline/jit/base.h"
#include "debug/common.h" #include "debug/common.h"
#include "debug/trace.h" #include "debug/trace.h"
#include "utils/trace_base.h"


namespace mindspore { namespace mindspore {
const std::string ToShortString(const TypeId &typeId) { const std::string ToShortString(const TypeId &typeId) {
@@ -344,7 +345,8 @@ void DumpShape(const AnfNodePtr &nd, const FuncGraphPtr &sub_graph, const std::s
} }


void DumpCNode(const CNodePtr &nd, const FuncGraphPtr &sub_graph, OrderedMap<AnfNodePtr, int32_t> *const para_map, void DumpCNode(const CNodePtr &nd, const FuncGraphPtr &sub_graph, OrderedMap<AnfNodePtr, int32_t> *const para_map,
const std::shared_ptr<SubGraphIRInfo> &gsub, bool dump_full_name = false, bool dump_location = false) {
const std::shared_ptr<SubGraphIRInfo> &gsub, bool dump_full_name = false,
LocDumpMode dump_location = kOff) {
if (nd == nullptr || sub_graph == nullptr || para_map == nullptr || gsub == nullptr) { if (nd == nullptr || sub_graph == nullptr || para_map == nullptr || gsub == nullptr) {
return; return;
} }
@@ -383,19 +385,24 @@ void DumpCNode(const CNodePtr &nd, const FuncGraphPtr &sub_graph, OrderedMap<Anf
if (dump_full_name) { if (dump_full_name) {
gsub->buffer << " : (" << nd->fullname_with_scope() << ")" << std::endl; gsub->buffer << " : (" << nd->fullname_with_scope() << ")" << std::endl;
} }
if (dump_location) {
if (dump_location == kTopStack) {
if (label_manage::GetGlobalTraceLabelType() == label_manage::TraceLabelType::kWithUniqueId) { if (label_manage::GetGlobalTraceLabelType() == label_manage::TraceLabelType::kWithUniqueId) {
gsub->buffer << trace::GetDebugInfo(nd->debug_info(), " # ", kSourceLineTipDiscard) << "#" gsub->buffer << trace::GetDebugInfo(nd->debug_info(), " # ", kSourceLineTipDiscard) << "#"
<< label_manage::Label(nd->debug_info()) << "\n"; << label_manage::Label(nd->debug_info()) << "\n";
} else { } else {
gsub->buffer << trace::GetDebugInfo(nd->debug_info(), " # ", kSourceLineTipDiscard) << "\n"; gsub->buffer << trace::GetDebugInfo(nd->debug_info(), " # ", kSourceLineTipDiscard) << "\n";
} }
} else if (dump_location == kWholeStack) {
auto traces = mindspore::trace::GetSourceLineList(nd);
for (auto &trace : traces) {
gsub->buffer << " # " << trace;
}
} }
} }


void DumpIRInSubgraph(const std::vector<AnfNodePtr> &nodes, OrderedMap<AnfNodePtr, int32_t> *para_map, void DumpIRInSubgraph(const std::vector<AnfNodePtr> &nodes, OrderedMap<AnfNodePtr, int32_t> *para_map,
OrderedMap<FuncGraphPtr, std::shared_ptr<SubGraphIRInfo>> *const sub_graphs, OrderedMap<FuncGraphPtr, std::shared_ptr<SubGraphIRInfo>> *const sub_graphs,
bool dump_full_name = false, bool dump_location = false) {
bool dump_full_name = false, LocDumpMode dump_location = kOff) {
if (para_map == nullptr || sub_graphs == nullptr) { if (para_map == nullptr || sub_graphs == nullptr) {
return; return;
} }
@@ -489,7 +496,7 @@ std::string AddGlobalId(const std::string &filename) {
} }


#ifdef ENABLE_DUMP_IR #ifdef ENABLE_DUMP_IR
void DumpIR(const std::string &filename, const FuncGraphPtr &graph, bool dump_full_name, bool dump_location) {
void DumpIR(const std::string &filename, const FuncGraphPtr &graph, bool dump_full_name, LocDumpMode dump_location) {
if (graph == nullptr) { if (graph == nullptr) {
return; return;
} }
@@ -529,7 +536,7 @@ void DumpIR(const std::string &filename, const FuncGraphPtr &graph, bool dump_fu
ChangeFileMode(realpath.value(), S_IRUSR); ChangeFileMode(realpath.value(), S_IRUSR);
} }
#else #else
void DumpIR(const std::string &, const FuncGraphPtr &, bool, bool) {
void DumpIR(const std::string &, const FuncGraphPtr &, bool, LocDumpMode) {
static bool already_printed = false; static bool already_printed = false;
if (already_printed) { if (already_printed) {
return; return;


+ 2
- 1
mindspore/ccsrc/debug/anf_ir_dump.h View File

@@ -22,9 +22,10 @@
#include "ir/anf.h" #include "ir/anf.h"


namespace mindspore { namespace mindspore {
enum LocDumpMode { kOff = 0, kTopStack = 1, kWholeStack = 2 };
constexpr char PARALLEL_STRATEGY[] = "strategy"; constexpr char PARALLEL_STRATEGY[] = "strategy";
void DumpIR(const std::string &filename, const FuncGraphPtr &func_graph, bool dump_full_name = false, void DumpIR(const std::string &filename, const FuncGraphPtr &func_graph, bool dump_full_name = false,
bool dump_location = false);
LocDumpMode dump_location = kOff);
void PrintInputAndOutputInferType(std::ostringstream &buffer, const AnfNodePtr &nd); void PrintInputAndOutputInferType(std::ostringstream &buffer, const AnfNodePtr &nd);
const std::string ToShortString(const TypeId &typeId); const std::string ToShortString(const TypeId &typeId);
} // namespace mindspore } // namespace mindspore


+ 6
- 2
mindspore/ccsrc/pipeline/jit/pipeline.cc View File

@@ -644,7 +644,7 @@ void Pipeline::Run() {
FuncGraphPtr user_graph = nullptr; FuncGraphPtr user_graph = nullptr;


WITH(MsProfile::GetProfile())[&user_graph, this]() { WITH(MsProfile::GetProfile())[&user_graph, this]() {
int64_t i = 0;
size_t i = 0;
for (auto &action : actions_) { for (auto &action : actions_) {
#ifdef ENABLE_TIMELINE #ifdef ENABLE_TIMELINE
DumpTime &dump_time = DumpTime::GetInstance(); DumpTime &dump_time = DumpTime::GetInstance();
@@ -687,7 +687,11 @@ void Pipeline::Run() {
// generate IR file in dot format, which can be converted to svg file using graphviz dot command // generate IR file in dot format, which can be converted to svg file using graphviz dot command
draw::Draw(base_name + ".dot", graph); draw::Draw(base_name + ".dot", graph);
// generate IR file in human readable format // generate IR file in human readable format
DumpIR(base_name + ".ir", graph);
if (i == actions_.size() - 1) {
DumpIR(base_name + ".ir", graph, false, kWholeStack);
} else {
DumpIR(base_name + ".ir", graph, false, kTopStack);
}
// generate IR file in a heavily commented format, which can also be reloaded // generate IR file in a heavily commented format, which can also be reloaded
ExportIR(base_name + ".dat", std::to_string(i), graph); ExportIR(base_name + ".dat", std::to_string(i), graph);
} }


+ 1
- 1
mindspore/core/utils/info.cc View File

@@ -47,7 +47,7 @@ std::string HighLightLine(const std::string &line, int col_begin, int col_end, S
// print the file name, line no and column no, and part of the content // print the file name, line no and column no, and part of the content
std::string Location::ToString(SourceLineTip tip) { std::string Location::ToString(SourceLineTip tip) {
std::stringstream debug_info_ss; std::stringstream debug_info_ss;
debug_info_ss << " In file " << file_name_ << "(" << line_ << ")" << std::endl;
debug_info_ss << "In file " << file_name_ << "(" << line_ << ")" << std::endl;
if (line_ <= 0) { if (line_ <= 0) {
return debug_info_ss.str(); return debug_info_ss.str();
} }


Loading…
Cancel
Save