Browse Source

!11356 clear parse or resolve debug info

From: @zhangbuxue
Reviewed-by: 
Signed-off-by:
tags/v1.2.0-rc1
mindspore-ci-bot Gitee 4 years ago
parent
commit
cf87c0304d
6 changed files with 31 additions and 20 deletions
  1. +1
    -1
      mindspore/ccsrc/debug/trace.cc
  2. +2
    -0
      mindspore/ccsrc/pipeline/jit/parse/parse.cc
  3. +2
    -4
      mindspore/ccsrc/pipeline/jit/parse/resolve.cc
  4. +17
    -9
      mindspore/ccsrc/pipeline/jit/pipeline.cc
  5. +6
    -4
      mindspore/core/utils/info.cc
  6. +3
    -2
      mindspore/core/utils/info.h

+ 1
- 1
mindspore/ccsrc/debug/trace.cc View File

@@ -570,7 +570,7 @@ struct TraceProviderRegister {
std::ostringstream trace_info;
GetEvalStackInfo(trace_info);
if (trace_info.str().empty()) {
DebugInfoPtr debug_info = TraceManager::GetDebugInfoPtr();
DebugInfoPtr debug_info = TraceManager::GetParseOrResolveDebugInfo();
if (debug_info != nullptr) {
oss << "\n\n# " << trace::GetDebugInfo(debug_info);
}


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

@@ -373,6 +373,7 @@ FunctionBlockPtr Parser::ParseStatement(const FunctionBlockPtr &block, const py:
MS_LOG(DEBUG) << "Ast node is " << node_name;
if (stmt_method_map_.count(node_name)) {
auto stmt_block = (this->*stmt_method_map_[node_name])(block, node);
TraceManager::ClearParseOrResolveDebugInfo();
return stmt_block;
} else {
errcode_ = PARSE_NODE_METHOD_UNSUPPORTED;
@@ -396,6 +397,7 @@ AnfNodePtr Parser::ParseExprNode(const FunctionBlockPtr &block, const py::object
MS_LOG(DEBUG) << "Ast node is " << node_name;
if (expr_method_map_.count(node_name)) {
auto expr_node = (this->*expr_method_map_[node_name])(block, node);
TraceManager::ClearParseOrResolveDebugInfo();
return expr_node;
} else {
errcode_ = PARSE_NODE_METHOD_UNSUPPORTED;


+ 2
- 4
mindspore/ccsrc/pipeline/jit/parse/resolve.cc View File

@@ -252,9 +252,8 @@ AnfNodePtr ResolveSymbol(const FuncGraphManagerPtr &manager, const NameSpacePtr
}

py::object obj = symbol_resolver.result();

AnfNodePtr resolved_node = ResolveObjectAndAddToManager(manager, obj, node);
TraceManager::ClearParseOrResolveDebugInfo();
return resolved_node;
}

@@ -275,9 +274,8 @@ AnfNodePtr ResolveCellwithAttr(const FuncGraphManagerPtr &manager, const NameSpa
return nullptr;
}
py::object obj_attr = obj.attr(attr.c_str());

AnfNodePtr resolved_node = ResolveObjectAndAddToManager(manager, obj_attr, node);
TraceManager::ClearParseOrResolveDebugInfo();
return resolved_node;
}



+ 17
- 9
mindspore/ccsrc/pipeline/jit/pipeline.cc View File

@@ -102,6 +102,20 @@ AbstractBasePtr ArgsToAbstract(const ValuePtr &value) {
bool broaden = value->isa<MetaTensor>();
return abstract::FromValue(value, broaden);
}

std::string GetCompileExceptionInfo() {
std::ostringstream oss;
trace::TraceGraphEval();
trace::GetEvalStackInfo(oss);
if (oss.str().empty()) {
DebugInfoPtr debug_info = TraceManager::GetParseOrResolveDebugInfo();
if (debug_info != nullptr) {
oss << "\n\n# " << trace::GetDebugInfo(debug_info);
}
}
return oss.str();
}

} // namespace

py::tuple GenerateKey(const std::string &name, const std::unordered_map<std::string, py::object> &defaults) {
@@ -540,16 +554,10 @@ bool ExecutorPy::Compile(const py::object &obj, const py::tuple &args, const py:
ret_value = CompileInner(obj, args, phase, use_vm);
} catch (const py::error_already_set &ex) {
// print function call stack info before release
std::ostringstream oss;
trace::TraceGraphEval();
trace::GetEvalStackInfo(oss);
if (oss.str().empty()) {
DebugInfoPtr debug_info = TraceManager::GetDebugInfoPtr();
if (debug_info != nullptr) {
oss << "\n\n# " << trace::GetDebugInfo(debug_info);
}
std::string exception_info = GetCompileExceptionInfo();
if (!exception_info.empty()) {
MS_LOG(ERROR) << exception_info;
}
MS_LOG(ERROR) << oss.str();
ReleaseResource(phase);

// re-throw this exception to Python interpreter to handle it


+ 6
- 4
mindspore/core/utils/info.cc View File

@@ -190,7 +190,7 @@ void TraceManager::DebugTrace(const std::string &func_name, const LocationPtr &l
void TraceManager::DebugTrace(const LocationPtr &location) {
TraceContextPtr context = std::make_shared<TraceContext>(location);
TraceManager::trace_context_stack_.push(context);
TraceManager::debug_info_ = std::make_shared<DebugInfo>(location);
TraceManager::parse_or_resolve_debug_info_ = std::make_shared<DebugInfo>(location);
}

void TraceManager::DebugTrace(const TraceInfoPtr &trace_info) {
@@ -202,7 +202,7 @@ void TraceManager::DebugTrace(const TraceInfoPtr &trace_info) {
MS_LOG(EXCEPTION) << "Trace debug info is null";
}
TraceManager::trace_context_stack_.push(context);
TraceManager::debug_info_ = trace_info->debug_info();
TraceManager::parse_or_resolve_debug_info_ = trace_info->debug_info();
}

void TraceManager::DebugTrace(const DebugInfoPtr &debug_info, const TraceInfoPtr &trace_info) {
@@ -220,9 +220,11 @@ void TraceManager::DebugTrace(const DebugInfoPtr &debug_info, const TraceInfoPtr

void TraceManager::EndTrace() { TraceManager::trace_context_stack_.pop(); }

DebugInfoPtr TraceManager::GetDebugInfoPtr() { return TraceManager::debug_info_; }
DebugInfoPtr TraceManager::GetParseOrResolveDebugInfo() { return TraceManager::parse_or_resolve_debug_info_; }

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

std::stack<TraceContextPtr> TraceManager::trace_context_stack_;

DebugInfoPtr TraceManager::debug_info_ = nullptr;
DebugInfoPtr TraceManager::parse_or_resolve_debug_info_ = nullptr;
} // namespace mindspore

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

@@ -76,10 +76,11 @@ class TraceManager {
static void DebugTrace(const DebugInfoPtr &debug_info, const TraceInfoPtr &trace_info);
static void EndTrace();

static DebugInfoPtr GetDebugInfoPtr();
static void ClearParseOrResolveDebugInfo();
static DebugInfoPtr GetParseOrResolveDebugInfo();

static std::stack<TraceContextPtr> trace_context_stack_;
static DebugInfoPtr debug_info_;
static DebugInfoPtr parse_or_resolve_debug_info_;
};

class TraceGuard {


Loading…
Cancel
Save