From 3df40b73a5251e101279fc8d9f5134bfe3100448 Mon Sep 17 00:00:00 2001 From: buxue Date: Mon, 18 Jan 2021 09:10:33 +0800 Subject: [PATCH] clear parse or resolve debug info --- mindspore/ccsrc/debug/trace.cc | 2 +- mindspore/ccsrc/pipeline/jit/parse/parse.cc | 2 ++ mindspore/ccsrc/pipeline/jit/parse/resolve.cc | 6 ++--- mindspore/ccsrc/pipeline/jit/pipeline.cc | 26 ++++++++++++------- mindspore/core/utils/info.cc | 10 ++++--- mindspore/core/utils/info.h | 5 ++-- 6 files changed, 31 insertions(+), 20 deletions(-) diff --git a/mindspore/ccsrc/debug/trace.cc b/mindspore/ccsrc/debug/trace.cc index 5530fe6e2b0..878c34b3cd2 100644 --- a/mindspore/ccsrc/debug/trace.cc +++ b/mindspore/ccsrc/debug/trace.cc @@ -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); } diff --git a/mindspore/ccsrc/pipeline/jit/parse/parse.cc b/mindspore/ccsrc/pipeline/jit/parse/parse.cc index bddd1a554ad..0814e0bcefe 100644 --- a/mindspore/ccsrc/pipeline/jit/parse/parse.cc +++ b/mindspore/ccsrc/pipeline/jit/parse/parse.cc @@ -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; diff --git a/mindspore/ccsrc/pipeline/jit/parse/resolve.cc b/mindspore/ccsrc/pipeline/jit/parse/resolve.cc index 260ce084f21..fab20a82adb 100644 --- a/mindspore/ccsrc/pipeline/jit/parse/resolve.cc +++ b/mindspore/ccsrc/pipeline/jit/parse/resolve.cc @@ -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; } diff --git a/mindspore/ccsrc/pipeline/jit/pipeline.cc b/mindspore/ccsrc/pipeline/jit/pipeline.cc index 2d0c8cc90e6..6e8c2998346 100644 --- a/mindspore/ccsrc/pipeline/jit/pipeline.cc +++ b/mindspore/ccsrc/pipeline/jit/pipeline.cc @@ -102,6 +102,20 @@ AbstractBasePtr ArgsToAbstract(const ValuePtr &value) { bool broaden = value->isa(); 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 &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 diff --git a/mindspore/core/utils/info.cc b/mindspore/core/utils/info.cc index feb10c5332c..43e5790b678 100644 --- a/mindspore/core/utils/info.cc +++ b/mindspore/core/utils/info.cc @@ -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(location); TraceManager::trace_context_stack_.push(context); - TraceManager::debug_info_ = std::make_shared(location); + TraceManager::parse_or_resolve_debug_info_ = std::make_shared(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 TraceManager::trace_context_stack_; -DebugInfoPtr TraceManager::debug_info_ = nullptr; +DebugInfoPtr TraceManager::parse_or_resolve_debug_info_ = nullptr; } // namespace mindspore diff --git a/mindspore/core/utils/info.h b/mindspore/core/utils/info.h index d9fd01fe248..ced6aab8765 100644 --- a/mindspore/core/utils/info.h +++ b/mindspore/core/utils/info.h @@ -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 trace_context_stack_; - static DebugInfoPtr debug_info_; + static DebugInfoPtr parse_or_resolve_debug_info_; }; class TraceGuard {