Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
b4755c5a
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b4755c5a
编写于
8月 14, 2017
作者:
L
liaogang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Demangle exception call stack for PADDLE_ENFORCE
上级
9038b849
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
39 addition
and
8 deletion
+39
-8
paddle/platform/enforce.h
paddle/platform/enforce.h
+39
-8
未找到文件。
paddle/platform/enforce.h
浏览文件 @
b4755c5a
...
@@ -14,14 +14,20 @@ limitations under the License. */
...
@@ -14,14 +14,20 @@ limitations under the License. */
#pragma once
#pragma once
#include <execinfo.h>
#include <dlfcn.h> // for dladdr
#include <execinfo.h> // for backtrace
#include <iomanip>
#include <iomanip>
#include <sstream>
#include <sstream>
#include <stdexcept>
#include <stdexcept>
#include <string>
#include <string>
#include "paddle/string/printf.h"
#include "paddle/string/printf.h"
#include "paddle/string/to_string.h"
#include "paddle/string/to_string.h"
#ifdef __GNUC__
#include <cxxabi.h> // for __cxa_demangle
#endif
#ifndef PADDLE_ONLY_CPU
#ifndef PADDLE_ONLY_CPU
#include "paddle/platform/dynload/cublas.h"
#include "paddle/platform/dynload/cublas.h"
...
@@ -39,6 +45,19 @@ limitations under the License. */
...
@@ -39,6 +45,19 @@ limitations under the License. */
namespace
paddle
{
namespace
paddle
{
namespace
platform
{
namespace
platform
{
namespace
{
#ifdef __GNUC__
inline
std
::
string
demangle
(
std
::
string
name
)
{
int
status
=
-
4
;
// some arbitrary value to eliminate the compiler warning
std
::
unique_ptr
<
char
,
void
(
*
)(
void
*
)
>
res
{
abi
::
__cxa_demangle
(
name
.
c_str
(),
NULL
,
NULL
,
&
status
),
std
::
free
};
return
(
status
==
0
)
?
res
.
get
()
:
name
;
}
#else
inline
std
::
string
demangle
(
std
::
string
name
)
{
return
name
;
}
#endif
}
struct
EnforceNotMet
:
public
std
::
exception
{
struct
EnforceNotMet
:
public
std
::
exception
{
std
::
exception_ptr
exp_
;
std
::
exception_ptr
exp_
;
std
::
string
err_str_
;
std
::
string
err_str_
;
...
@@ -48,15 +67,27 @@ struct EnforceNotMet : public std::exception {
...
@@ -48,15 +67,27 @@ struct EnforceNotMet : public std::exception {
std
::
rethrow_exception
(
exp_
);
std
::
rethrow_exception
(
exp_
);
}
catch
(
const
std
::
exception
&
exp
)
{
}
catch
(
const
std
::
exception
&
exp
)
{
std
::
ostringstream
sout
;
std
::
ostringstream
sout
;
sout
<<
string
::
Sprintf
(
"%s at [%s:%d]"
,
exp
.
what
(),
f
,
l
)
<<
std
::
endl
;
sout
<<
string
::
Sprintf
(
"%s at [%s:%d]"
,
exp
.
what
(),
f
,
l
)
<<
std
::
endl
;
sout
<<
"Call Stacks: "
<<
std
::
endl
;
sout
<<
"PaddlePaddle Call Stacks: "
<<
std
::
endl
;
void
*
call_stack
[
TRACE_STACK_LIMIT
];
void
*
call_stack
[
TRACE_STACK_LIMIT
];
int
sz
=
backtrace
(
call_stack
,
TRACE_STACK_LIMIT
);
auto
size
=
backtrace
(
call_stack
,
TRACE_STACK_LIMIT
);
auto
line
=
backtrace_symbols
(
call_stack
,
sz
);
auto
symbols
=
backtrace_symbols
(
call_stack
,
size
);
for
(
int
i
=
0
;
i
<
sz
;
++
i
)
{
sout
<<
line
[
i
]
<<
std
::
endl
;
Dl_info
info
;
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
if
(
dladdr
(
call_stack
[
i
],
&
info
))
{
auto
demangled
=
demangle
(
info
.
dli_sname
);
sout
<<
string
::
Sprintf
(
"%-3d %*0p %s + %zd
\n
"
,
i
,
2
+
sizeof
(
void
*
)
*
2
,
call_stack
[
i
],
demangled
,
(
char
*
)
call_stack
[
i
]
-
(
char
*
)
info
.
dli_saddr
);
}
else
{
sout
<<
string
::
Sprintf
(
"%-3d %*0p %s
\n
"
,
i
,
2
+
sizeof
(
void
*
)
*
2
,
call_stack
[
i
]);
}
}
}
free
(
line
);
free
(
symbols
);
err_str_
=
sout
.
str
();
err_str_
=
sout
.
str
();
}
}
}
}
...
@@ -170,7 +201,7 @@ inline void throw_on_error(T e) {
...
@@ -170,7 +201,7 @@ inline void throw_on_error(T e) {
* PADDLE_ENFORCE_EQ(a, b);
* PADDLE_ENFORCE_EQ(a, b);
*
*
* will raise an expression described as follows:
* will raise an expression described as follows:
* "enforce a == b failed, 1 != 2" with detailed stack infomation.
* "enforce a == b failed, 1 != 2" with detailed stack info
r
mation.
*
*
* extra messages is also supported, for example:
* extra messages is also supported, for example:
* PADDLE_ENFORCE(a, b, "some simple enforce failed between %d numbers", 2)
* PADDLE_ENFORCE(a, b, "some simple enforce failed between %d numbers", 2)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录