提交 c1235c93 编写于 作者: P peizhilin

add the enable_debug flag

test=develop
上级 c783dd03
...@@ -32,6 +32,12 @@ DEFINE_bool(check_nan_inf, false, ...@@ -32,6 +32,12 @@ DEFINE_bool(check_nan_inf, false,
"Checking whether operator produce NAN/INF or not. It will be " "Checking whether operator produce NAN/INF or not. It will be "
"extremely slow so please use this flag wisely."); "extremely slow so please use this flag wisely.");
DEFINE_bool(
enable_debug, false,
"The enable_debug indicate whether to give more detail information when, "
"use the paddlepaddle. However it may deduce the performance since it has"
"to record the information during runtime.");
namespace paddle { namespace paddle {
namespace framework { namespace framework {
...@@ -157,7 +163,7 @@ RuntimeContext::RuntimeContext(const VariableNameMap& innames, ...@@ -157,7 +163,7 @@ RuntimeContext::RuntimeContext(const VariableNameMap& innames,
} }
} }
void OperatorBase::PreHook() { void OperatorBase::PreHook(const Scope& scope, const platform::Place& place) {
auto attrName = OpProtoAndCheckerMaker::OpCreationCallstackAttrName(); auto attrName = OpProtoAndCheckerMaker::OpCreationCallstackAttrName();
if (HasAttr(attrName)) { if (HasAttr(attrName)) {
auto& callstack = Attr<std::vector<std::string>>(attrName); auto& callstack = Attr<std::vector<std::string>>(attrName);
...@@ -166,8 +172,10 @@ void OperatorBase::PreHook() { ...@@ -166,8 +172,10 @@ void OperatorBase::PreHook() {
} }
void OperatorBase::Run(const Scope& scope, const platform::Place& place) { void OperatorBase::Run(const Scope& scope, const platform::Place& place) {
if (FLAGS_enable_debug) {
VLOG(4) << "Call the prehook ... "; VLOG(4) << "Call the prehook ... ";
PreHook(); PreHook(scope, place);
}
VLOG(4) << place << " " << DebugStringEx(&scope); VLOG(4) << place << " " << DebugStringEx(&scope);
if (platform::is_gpu_place(place)) { if (platform::is_gpu_place(place)) {
...@@ -191,11 +199,13 @@ void OperatorBase::Run(const Scope& scope, const platform::Place& place) { ...@@ -191,11 +199,13 @@ void OperatorBase::Run(const Scope& scope, const platform::Place& place) {
} }
VLOG(3) << place << " " << DebugStringEx(&scope); VLOG(3) << place << " " << DebugStringEx(&scope);
if (FLAGS_enable_debug) {
VLOG(4) << "Call the posthook ... "; VLOG(4) << "Call the posthook ... ";
PostHook(); PostHook(scope, place);
}
} }
void OperatorBase::PostHook() { void OperatorBase::PostHook(const Scope& scope, const platform::Place& place) {
// do nothing here // do nothing here
} }
......
...@@ -161,8 +161,8 @@ class OperatorBase { ...@@ -161,8 +161,8 @@ class OperatorBase {
const RuntimeContext& ctx) const {} const RuntimeContext& ctx) const {}
// Add the hooks // Add the hooks
virtual void PreHook(); virtual void PreHook(const Scope& scope, const platform::Place& place);
virtual void PostHook(); virtual void PostHook(const Scope& scope, const platform::Place& place);
protected: protected:
std::string type_; std::string type_;
......
...@@ -27,6 +27,15 @@ std::string PythonDebugSupport::Format() const { ...@@ -27,6 +27,15 @@ std::string PythonDebugSupport::Format() const {
for (auto &line : info) { for (auto &line : info) {
sout << line; sout << line;
} }
} else {
#ifdef _WIN32
sout << "please set FLAGS_enable_debug=True to get more details regard to "
"this failure.\n";
#else // _WIN32
sout << "please export FLAGS_enable_debug=True to get more details regard "
"to "
"this failure.\n";
#endif // _WIN32
} }
return sout.str(); return sout.str();
} }
......
...@@ -265,6 +265,10 @@ inline void throw_on_error(T e) { ...@@ -265,6 +265,10 @@ inline void throw_on_error(T e) {
#define __THROW_ON_ERROR_ONE_ARG(COND, ARG) \ #define __THROW_ON_ERROR_ONE_ARG(COND, ARG) \
::paddle::platform::throw_on_error(COND, ::paddle::string::Sprintf(ARG)); ::paddle::platform::throw_on_error(COND, ::paddle::string::Sprintf(ARG));
#ifdef _WIN32
#define __PADDLE_THROW_ON_ERROR(COND, ...) \
__THROW_ON_ERROR_ONE_ARG(COND, __VA_ARGS__)
#else // _WIN32
#define __PADDLE_THROW_ON_ERROR(COND, ...) \ #define __PADDLE_THROW_ON_ERROR(COND, ...) \
__PADDLE_THROW_ERROR_I( \ __PADDLE_THROW_ERROR_I( \
__VA_ARGS__, ::paddle::platform::throw_on_error(COND, __VA_ARGS__), \ __VA_ARGS__, ::paddle::platform::throw_on_error(COND, __VA_ARGS__), \
...@@ -276,6 +280,7 @@ inline void throw_on_error(T e) { ...@@ -276,6 +280,7 @@ inline void throw_on_error(T e) {
::paddle::platform::throw_on_error(COND, __VA_ARGS__), \ ::paddle::platform::throw_on_error(COND, __VA_ARGS__), \
::paddle::platform::throw_on_error(COND, __VA_ARGS__), \ ::paddle::platform::throw_on_error(COND, __VA_ARGS__), \
__THROW_ON_ERROR_ONE_ARG(COND, __VA_ARGS__)) __THROW_ON_ERROR_ONE_ARG(COND, __VA_ARGS__))
#endif // _WIN32
#define __PADDLE_UNARY_COMPARE(COND, ...) \ #define __PADDLE_UNARY_COMPARE(COND, ...) \
do { \ do { \
......
...@@ -627,9 +627,15 @@ class Operator(object): ...@@ -627,9 +627,15 @@ class Operator(object):
if role_var_name in op_attrs and len(op_attrs[role_var_name]) == 0: if role_var_name in op_attrs and len(op_attrs[role_var_name]) == 0:
del op_attrs[role_var_name] del op_attrs[role_var_name]
if 'FLAGS_enable_debug' in os.environ and os.environ[
'FLAGS_enable_debug']:
callstack_var_name = op_maker.kOpCreationCallstackAttrName() callstack_var_name = op_maker.kOpCreationCallstackAttrName()
op_attrs[callstack_var_name] = list( op_attrs[callstack_var_name] = list(
reversed(traceback.format_stack()))[1:] reversed(traceback.format_stack()))[1:]
op_attrs[callstack_var_name].insert(
0,
'Invoke operator ' + (''
if type is None else type) + ' error.\n')
if len(self.desc.type()) != 0: if len(self.desc.type()) != 0:
return return
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册