Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
db5e74ab
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看板
未验证
提交
db5e74ab
编写于
5月 08, 2019
作者:
C
chengduo
提交者:
GitHub
5月 08, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update assert (#17282)
test=develop
上级
c3195de5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
35 deletion
+29
-35
paddle/fluid/operators/cross_entropy_op.h
paddle/fluid/operators/cross_entropy_op.h
+2
-0
paddle/fluid/operators/lookup_table_op.cu
paddle/fluid/operators/lookup_table_op.cu
+4
-4
paddle/fluid/platform/assert.h
paddle/fluid/platform/assert.h
+23
-31
未找到文件。
paddle/fluid/operators/cross_entropy_op.h
浏览文件 @
db5e74ab
...
...
@@ -154,6 +154,8 @@ struct HardLabelCrossEntropyForwardFunctor {
HOSTDEVICE
void
operator
()(
int64_t
idx
)
const
{
auto
label
=
label_
[
idx
];
PADDLE_ASSERT_MSG
(
label
>=
0
&&
label
<
feature_size_
,
"The label is out of the range."
,
label
);
if
(
label
!=
ignore_index_
)
{
auto
match_x
=
x_
[
idx
*
feature_size_
+
label
];
y_
[
idx
]
=
-
math
::
TolerableValue
<
T
>
()(
real_log
(
match_x
));
...
...
paddle/fluid/operators/lookup_table_op.cu
浏览文件 @
db5e74ab
...
...
@@ -32,8 +32,8 @@ __global__ void LookupTable(T *output, const T *table, const int64_t *ids,
while
(
idy
<
K
)
{
int64_t
id
=
ids
[
idy
];
PADDLE_ASSERT_MSG
_CODE
(
id
>=
0
,
"received id:"
,
id
);
PADDLE_ASSERT_MSG
_CODE
(
id
<
N
,
"received id:"
,
id
);
PADDLE_ASSERT_MSG
(
id
>=
0
,
"received id:"
,
id
);
PADDLE_ASSERT_MSG
(
id
<
N
,
"received id:"
,
id
);
T
*
out
=
output
+
idy
*
D
;
const
T
*
tab
=
table
+
id
*
D
;
for
(
int
i
=
idx
;
i
<
D
;
i
+=
BlockDimX
)
{
...
...
@@ -59,8 +59,8 @@ __global__ void LookupTableGrad(T *table, const T *output, const int64_t *ids,
while
(
idy
<
K
)
{
int64_t
id
=
ids
[
idy
];
PADDLE_ASSERT_MSG
_CODE
(
id
>=
0
,
"received id:"
,
id
);
PADDLE_ASSERT_MSG
_CODE
(
id
<
N
,
"received id:"
,
id
);
PADDLE_ASSERT_MSG
(
id
>=
0
,
"received id:"
,
id
);
PADDLE_ASSERT_MSG
(
id
<
N
,
"received id:"
,
id
);
const
T
*
out
=
output
+
idy
*
D
;
T
*
tab
=
table
+
id
*
D
;
for
(
int
i
=
idx
;
i
<
D
;
i
+=
BlockDimX
)
{
...
...
paddle/fluid/platform/assert.h
浏览文件 @
db5e74ab
...
...
@@ -17,40 +17,32 @@ limitations under the License. */
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
// For cuda, the assertions can affect performance and it is therefore
// recommended to disable them in production code
// https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#assertion
#if defined(__CUDA_ARCH__)
#include <stdio.h>
#define PADDLE_ASSERT(e) \
do { \
if (!(e)) { \
printf("%s:%d Assertion `%s` failed.\n", __FILE__, __LINE__, \
TOSTRING(e)); \
asm("trap;"); \
} \
} while (0)
#define EXIT() asm("trap;")
#else
#include <assert.h>
#define EXIT() throw std::runtime_error("Exception encounter.")
#endif
#define PADDLE_ASSERT
_MSG(e, m)
\
do { \
if (!(
e)) {
\
printf("
%s:%d Assertion `%s` failed (%s)
.\n", __FILE__, __LINE__, \
TOSTRING(
e), m);
\
asm("trap;");
\
} \
#define PADDLE_ASSERT
(_IS_NOT_ERROR)
\
do {
\
if (!(
_IS_NOT_ERROR)) {
\
printf("
Exception: %s:%d Assertion `%s` failed
.\n", __FILE__, __LINE__, \
TOSTRING(
_IS_NOT_ERROR));
\
EXIT();
\
}
\
} while (0)
#define PADDLE_ASSERT_MSG_CODE(e, m, c) \
do { \
if (!(e)) { \
printf("%s:%d Assertion `%s` failed (%s %ld).\n", __FILE__, __LINE__, \
TOSTRING(e), m, c); \
asm("trap;"); \
} \
// NOTE: PADDLE_ASSERT is mainly used in CUDA Kernel or HOSTDEVICE function.
#define PADDLE_ASSERT_MSG(_IS_NOT_ERROR, __MSG, __VAL) \
do { \
if (!(_IS_NOT_ERROR)) { \
printf("Exception: %s:%d Assertion `%s` failed (%s %ld).\n", __FILE__, \
__LINE__, TOSTRING(_IS_NOT_ERROR), __MSG, __VAL); \
EXIT(); \
} \
} while (0)
#else
#include <assert.h>
// For cuda, the assertions can affect performance and it is therefore
// recommended to disable them in production code
// https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#assertion
#define PADDLE_ASSERT(e) assert((e))
#define PADDLE_ASSERT_MSG(e, m) assert((e) && (m))
#define PADDLE_ASSERT_MSG_CODE(e, m, c) assert((e) && (m) && (c || 1))
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录