Browse Source

fix error in dump ir

tags/v1.6.0
huanghui 4 years ago
parent
commit
e269eec5c0
6 changed files with 66 additions and 19 deletions
  1. +22
    -7
      mindspore/ccsrc/debug/anf_ir_dump.cc
  2. +5
    -2
      mindspore/ccsrc/debug/trace.cc
  3. +5
    -1
      mindspore/ccsrc/pipeline/jit/action.cc
  4. +17
    -5
      mindspore/core/utils/info.cc
  5. +16
    -2
      mindspore/core/utils/info.h
  6. +1
    -2
      mindspore/core/utils/trace_base.cc

+ 22
- 7
mindspore/ccsrc/debug/anf_ir_dump.cc View File

@@ -226,6 +226,7 @@ void DumpOperator(const AnfNodePtr &node, const std::shared_ptr<SubGraphIRInfo>
return;
}
AnfNodePtr op = cnode->input(0);
MS_EXCEPTION_IF_NULL(op);
if (IsValueNode<FuncGraph>(op)) {
FuncGraphPtr fg = GetValueNode<FuncGraphPtr>(op);
if (fg != nullptr) {
@@ -240,14 +241,17 @@ void DumpOperator(const AnfNodePtr &node, const std::shared_ptr<SubGraphIRInfo>
gsub->buffer << "$(@" << fg->ToString() << ":" << input->ToString() << ")";
}
} else if (op->isa<ValueNode>()) {
gsub->buffer << GetValueNode(op)->ToString();
auto value = GetValueNode(op);
if (value != nullptr) {
gsub->buffer << value->ToString();
}
} else {
// It's Parameter.
if (op->func_graph() != node->func_graph()) {
if (op->func_graph() != nullptr && op->func_graph() != node->func_graph()) {
gsub->buffer << "$(@" << op->func_graph()->ToString() << ":";
}
gsub->buffer << op->ToString();
if (op->func_graph() != node->func_graph()) {
if (op->func_graph() != nullptr && op->func_graph() != node->func_graph()) {
gsub->buffer << ")";
}
}
@@ -436,9 +440,16 @@ void DumpPrimalDebugInfos(const CNodePtr &node, const std::shared_ptr<SubGraphIR
MS_EXCEPTION_IF_NULL(node);
auto primal_debug_infos = node->primal_debug_infos();
if (!primal_debug_infos.empty()) {
gsub->buffer << " # Corresponding forward node candidate:\n";
std::string lines;
for (auto &primal_debug_info : primal_debug_infos) {
gsub->buffer << trace::GetDebugInfo(primal_debug_info, " # ", kSourceLineTipDiscard) << "\n";
auto debug_info_str = trace::GetDebugInfo(primal_debug_info, " # ", kSourceLineTipDiscard);
if (!debug_info_str.empty()) {
lines += debug_info_str + "\n";
}
}
if (!lines.empty()) {
gsub->buffer << " # Corresponding forward node candidate:\n";
gsub->buffer << lines;
}
}
}
@@ -449,13 +460,17 @@ void DumpDebugInfo(const CNodePtr &node, const std::shared_ptr<SubGraphIRInfo> &
if (dump_location == kTopStack) {
auto fused_debug_infos = node->fused_debug_infos();
if (!fused_debug_infos.empty()) {
gsub->buffer << " # Corresponding code candidate:\n";
std::string lines;
for (const auto &debug_info : fused_debug_infos) {
auto debug_info_str = trace::GetDebugInfo(debug_info, " # ", kSourceLineTipDiscard);
if (!debug_info_str.empty()) {
gsub->buffer << debug_info_str << "\n";
lines += debug_info_str + "\n";
}
}
if (!lines.empty()) {
gsub->buffer << " # Corresponding code candidate:\n";
gsub->buffer << lines;
}
} else {
auto debug_info_str = trace::GetDebugInfo(node->debug_info(), " # ", kSourceLineTipDiscard);
if (!debug_info_str.empty()) {


+ 5
- 2
mindspore/ccsrc/debug/trace.cc View File

@@ -475,8 +475,11 @@ void GetTraceStackInfo(std::ostringstream &oss) {
GetEvalStackInfo(trace_info);
if (trace_info.str().empty()) {
DebugInfoPtr debug_info = TraceManager::GetParseOrResolveDebugInfo();
if (debug_info != nullptr) {
oss << "\n\n# " << trace::GetDebugInfo(debug_info);
if (debug_info != nullptr && TraceManager::GetRecordDebugInfoFlag() == true) {
auto debug_str = trace::GetDebugInfo(debug_info);
if (!debug_str.empty()) {
oss << "\n\n# " << debug_str;
}
}
} else {
oss << trace_info.str();


+ 5
- 1
mindspore/ccsrc/pipeline/jit/action.cc View File

@@ -378,6 +378,7 @@ void CheckRootInputShapeAndType(const ResourcePtr &res, const FuncGraphPtr &load

bool ParseAction(const ResourcePtr &res) {
MS_EXCEPTION_IF_NULL(res);
TraceManager::OpenRecordDebugInfoFlag();
if (!res->source_input()) {
MS_LOG(EXCEPTION) << "Parse error";
}
@@ -645,7 +646,10 @@ bool VmOptimizeAction(const ResourcePtr &res) {
kVmPasses.push_back({"server_communication_op_fusion", ps::Util::FuseServerCommOps});
}
#endif
return OptimizeAction(res, kVmPasses);
auto ret = OptimizeAction(res, kVmPasses);
TraceManager::ClearParseOrResolveDebugInfo();
TraceManager::CloseRecordDebugInfoFlag();
return ret;
}

bool PynativeElimOpt(const ResourcePtr &res) {


+ 17
- 5
mindspore/core/utils/info.cc View File

@@ -144,7 +144,9 @@ void TraceManager::DebugTrace(const std::string &func_name, const LocationPtr &l
void TraceManager::DebugTrace(const LocationPtr &location) {
MS_EXCEPTION_IF_NULL(location);
(void)TraceManager::trace_context_stack_.emplace_back(location);
TraceManager::parse_or_resolve_debug_info_ = std::make_shared<DebugInfo>(location);
if (record_debug_info_flag_) {
TraceManager::record_debug_info_ = std::make_shared<DebugInfo>(location);
}
}

void TraceManager::DebugTrace(const TraceInfoPtr &trace_info) {
@@ -152,7 +154,9 @@ void TraceManager::DebugTrace(const TraceInfoPtr &trace_info) {
auto &debug_info = trace_info->debug_info();
MS_EXCEPTION_IF_NULL(debug_info);
(void)TraceManager::trace_context_stack_.emplace_back(trace_info);
TraceManager::parse_or_resolve_debug_info_ = debug_info;
if (record_debug_info_flag_) {
TraceManager::record_debug_info_ = debug_info;
}
}

void TraceManager::DebugTrace(const DebugInfoPtr &debug_info, const TraceInfoPtr &trace_info) {
@@ -163,13 +167,21 @@ void TraceManager::DebugTrace(const DebugInfoPtr &debug_info, const TraceInfoPtr
(void)TraceManager::trace_context_stack_.emplace_back(cloned_info);
}

DebugInfoPtr TraceManager::GetParseOrResolveDebugInfo() { return TraceManager::parse_or_resolve_debug_info_; }
DebugInfoPtr TraceManager::GetParseOrResolveDebugInfo() { return TraceManager::record_debug_info_; }

void TraceManager::ClearParseOrResolveDebugInfo() { TraceManager::record_debug_info_ = nullptr; }

void TraceManager::ClearParseOrResolveDebugInfo() { TraceManager::parse_or_resolve_debug_info_ = nullptr; }
void TraceManager::CloseRecordDebugInfoFlag() { record_debug_info_flag_ = false; }

void TraceManager::OpenRecordDebugInfoFlag() { record_debug_info_flag_ = true; }

bool TraceManager::GetRecordDebugInfoFlag() { return record_debug_info_flag_; }

thread_local std::vector<TraceContext> TraceManager::trace_context_stack_;

thread_local DebugInfoPtr TraceManager::parse_or_resolve_debug_info_ = nullptr;
thread_local DebugInfoPtr TraceManager::record_debug_info_ = nullptr;

thread_local bool TraceManager::record_debug_info_flag_ = false;

LocationPtr GetFirstLocation(const DebugInfoPtr &debug_info) {
auto tmp = debug_info;


+ 16
- 2
mindspore/core/utils/info.h View File

@@ -124,12 +124,26 @@ class MS_CORE_API TraceManager {
/// \return The debug info for parse or resolve.
static DebugInfoPtr GetParseOrResolveDebugInfo();

/// \brief Get the flag of recording a debug info.
///
/// \return A bool.
static bool GetRecordDebugInfoFlag();

/// \brief Set the flag to false for not recording a debug info.
static void CloseRecordDebugInfoFlag();

/// \brief Set the flag to true for recording a debug info.
static void OpenRecordDebugInfoFlag();

private:
/// \brief Trace context stack for current thread.
thread_local static std::vector<TraceContext> trace_context_stack_;

/// \brief Debug info for parse or resolve for current thread.
thread_local static DebugInfoPtr parse_or_resolve_debug_info_;
/// \brief Record a debug info for print.
thread_local static DebugInfoPtr record_debug_info_;

/// \brief A flag to decide whether record a debug info or not.
thread_local static bool record_debug_info_flag_;
};

class TraceGuard {


+ 1
- 2
mindspore/core/utils/trace_base.cc View File

@@ -132,8 +132,7 @@ std::string GetDebugInfo(const DebugInfoPtr &info, const std::string &prefix, So
return "";
}
if (tip == kSourceLineTipDiscard) {
std::replace(debug_info.begin(), debug_info.end(), '\r', '/');
std::replace(debug_info.begin(), debug_info.end(), '\n', '/');
ReplaceLinefeed(&debug_info);
}
std::ostringstream oss;
oss << prefix << debug_info;


Loading…
Cancel
Save