!9852 improve functionalility of dumpir

From: @bairongz
Reviewed-by: 
Signed-off-by:
This commit is contained in:
mindspore-ci-bot 2020-12-14 21:01:04 +08:00 committed by Gitee
commit 2c13468772
4 changed files with 21 additions and 9 deletions

View File

@ -30,6 +30,7 @@
#include "pipeline/jit/base.h"
#include "debug/common.h"
#include "debug/trace.h"
#include "utils/trace_base.h"
namespace mindspore {
const std::string ToShortString(const TypeId &typeId) {
@ -354,7 +355,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,
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) {
return;
}
@ -393,19 +395,24 @@ void DumpCNode(const CNodePtr &nd, const FuncGraphPtr &sub_graph, OrderedMap<Anf
if (dump_full_name) {
gsub->buffer << " : (" << nd->fullname_with_scope() << ")" << std::endl;
}
if (dump_location) {
if (dump_location == kTopStack) {
if (label_manage::GetGlobalTraceLabelType() == label_manage::TraceLabelType::kWithUniqueId) {
gsub->buffer << trace::GetDebugInfo(nd->debug_info(), " # ", kSourceLineTipDiscard) << "#"
<< label_manage::Label(nd->debug_info()) << "\n";
} else {
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,
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) {
return;
}
@ -499,7 +506,7 @@ std::string AddGlobalId(const std::string &filename) {
}
#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) {
return;
}
@ -539,7 +546,7 @@ void DumpIR(const std::string &filename, const FuncGraphPtr &graph, bool dump_fu
ChangeFileMode(realpath.value(), S_IRUSR);
}
#else
void DumpIR(const std::string &, const FuncGraphPtr &, bool, bool) {
void DumpIR(const std::string &, const FuncGraphPtr &, bool, LocDumpMode) {
static bool already_printed = false;
if (already_printed) {
return;

View File

@ -22,9 +22,10 @@
#include "ir/anf.h"
namespace mindspore {
enum LocDumpMode { kOff = 0, kTopStack = 1, kWholeStack = 2 };
constexpr char PARALLEL_STRATEGY[] = "strategy";
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);
const std::string ToShortString(const TypeId &typeId);
} // namespace mindspore

View File

@ -644,7 +644,7 @@ void Pipeline::Run() {
FuncGraphPtr user_graph = nullptr;
WITH(MsProfile::GetProfile())[&user_graph, this]() {
int64_t i = 0;
size_t i = 0;
for (auto &action : actions_) {
#ifdef ENABLE_TIMELINE
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
draw::Draw(base_name + ".dot", graph);
// 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
ExportIR(base_name + ".dat", std::to_string(i), graph);
}

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
std::string Location::ToString(SourceLineTip tip) {
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) {
return debug_info_ss.str();
}