Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
a6c18075
P
Paddle
项目概览
机器未来
/
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看板
未验证
提交
a6c18075
编写于
10月 17, 2020
作者:
J
Jack Zhou
提交者:
GitHub
10月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add xpu error message description in some ops
add xpu error message description
上级
2ca53fa6
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
48 addition
and
24 deletion
+48
-24
paddle/fluid/operators/elementwise/elementwise_add_op_xpu.cc
paddle/fluid/operators/elementwise/elementwise_add_op_xpu.cc
+5
-3
paddle/fluid/operators/elementwise/elementwise_xpu.h
paddle/fluid/operators/elementwise/elementwise_xpu.h
+42
-20
python/paddle/fluid/tests/unittests/xpu/elementwise.py
python/paddle/fluid/tests/unittests/xpu/elementwise.py
+1
-1
未找到文件。
paddle/fluid/operators/elementwise/elementwise_add_op_xpu.cc
浏览文件 @
a6c18075
...
@@ -49,7 +49,8 @@ class ElementwiseAddGradXPUKernel : public ElemwiseGradKernel<T> {
...
@@ -49,7 +49,8 @@ class ElementwiseAddGradXPUKernel : public ElemwiseGradKernel<T> {
int
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
int
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
PADDLE_ENFORCE_GE
(
dx_dims
.
size
(),
dy_dims_untrimed
.
size
(),
PADDLE_ENFORCE_GE
(
dx_dims
.
size
(),
dy_dims_untrimed
.
size
(),
"Rank of first input must >= rank of second input."
);
platform
::
errors
::
InvalidArgument
(
"Rank of first input must >= rank of second input."
));
if
(
dx
!=
nullptr
)
{
if
(
dx
!=
nullptr
)
{
dx
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
dx
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
...
@@ -69,8 +70,9 @@ class ElementwiseAddGradXPUKernel : public ElemwiseGradKernel<T> {
...
@@ -69,8 +70,9 @@ class ElementwiseAddGradXPUKernel : public ElemwiseGradKernel<T> {
n
=
dout
->
numel
();
n
=
dout
->
numel
();
}
else
{
}
else
{
axis
=
(
axis
==
-
1
?
dx_dims
.
size
()
-
dy_dims_untrimed
.
size
()
:
axis
);
axis
=
(
axis
==
-
1
?
dx_dims
.
size
()
-
dy_dims_untrimed
.
size
()
:
axis
);
PADDLE_ENFORCE
(
axis
>=
0
&&
axis
<
dx_dims
.
size
(),
PADDLE_ENFORCE_EQ
(
axis
>=
0
&&
axis
<
dx_dims
.
size
(),
true
,
"Axis should be in range [0, dx_dims)"
);
platform
::
errors
::
InvalidArgument
(
"Axis should be in range [0, dx_dims)"
));
auto
dy_dims
=
trim_trailing_singular_dims
(
dy_dims_untrimed
);
auto
dy_dims
=
trim_trailing_singular_dims
(
dy_dims_untrimed
);
axis
=
(
dy_dims
.
size
()
==
0
)
?
dx_dims
.
size
()
:
axis
;
axis
=
(
dy_dims
.
size
()
==
0
)
?
dx_dims
.
size
()
:
axis
;
get_mid_dims
(
dx_dims
,
dy_dims
,
axis
,
&
pre
,
&
n
,
&
post
,
get_mid_dims
(
dx_dims
,
dy_dims
,
axis
,
&
pre
,
&
n
,
&
post
,
...
...
paddle/fluid/operators/elementwise/elementwise_xpu.h
浏览文件 @
a6c18075
...
@@ -14,9 +14,25 @@ limitations under the License. */
...
@@ -14,9 +14,25 @@ limitations under the License. */
#pragma once
#pragma once
#ifdef PADDLE_WITH_XPU
#ifdef PADDLE_WITH_XPU
#include <string>
#include <string>
#include <unordered_map>
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/fluid/platform/place.h"
inline
std
::
string
get_xpu_error_message
(
int
error_type
)
{
static
std
::
unordered_map
<
int
,
std
::
string
>
xpu_error_map
=
{
{
baidu
::
xpu
::
api
::
INVALID_PARAM
,
"Parameter is invalid."
},
{
baidu
::
xpu
::
api
::
RUNTIME_ERROR
,
"Please check whether Baidu Kunlun Card "
"is properly installed."
},
{
baidu
::
xpu
::
api
::
NO_ENOUGH_WORKSPACE
,
"There is not enough memory in Baidu"
" Kunlun Card."
}};
if
(
xpu_error_map
.
find
(
error_type
)
==
xpu_error_map
.
end
())
{
return
"Unknown error type!"
;
}
return
xpu_error_map
[
error_type
];
}
#define XPU_MALLOC(addr, num_bytes) \
#define XPU_MALLOC(addr, num_bytes) \
PADDLE_ENFORCE_EQ(xpu_malloc(reinterpret_cast<void**>(addr), num_bytes), \
PADDLE_ENFORCE_EQ(xpu_malloc(reinterpret_cast<void**>(addr), num_bytes), \
XPU_SUCCESS, \
XPU_SUCCESS, \
...
@@ -102,21 +118,27 @@ limitations under the License. */
...
@@ -102,21 +118,27 @@ limitations under the License. */
int res = \
int res = \
xpu::broadcast_ew(dev_ctx.x_context(), y_data, y_broadcast, pre, \
xpu::broadcast_ew(dev_ctx.x_context(), y_data, y_broadcast, pre, \
n, post, xpu::ElementwiseOp::ASSIGN); \
n, post, xpu::ElementwiseOp::ASSIGN); \
PADDLE_ENFORCE_EQ(res, xpu::Error_t::SUCCESS, \
PADDLE_ENFORCE_EQ( \
platform::errors::Fatal("XPU kernel error!")); \
res, xpu::Error_t::SUCCESS, \
platform::errors::External("XPU kernel error occur! %s", \
get_xpu_error_message(res))); \
y_data = y_broadcast; \
y_data = y_broadcast; \
} \
} \
} \
} \
int res = xpu::elementwise_##kernel_name##_grad( \
int res = xpu::elementwise_##kernel_name##_grad( \
dev_ctx.x_context(), x_data, y_data, dout->data<T>()
/*out*/
, \
dev_ctx.x_context(), x_data, y_data, dout->data<T>()
/*out*/
, \
dout->data<T>(), dx_data, dy_data, len); \
dout->data<T>(), dx_data, dy_data, len); \
PADDLE_ENFORCE_EQ(res, xpu::Error_t::SUCCESS, \
PADDLE_ENFORCE_EQ( \
platform::errors::Fatal("XPU kernel error!")); \
res, xpu::Error_t::SUCCESS, \
platform::errors::External("XPU kernel error occur! %s", \
get_xpu_error_message(res))); \
if ((dy != nullptr) && (len != n)) { \
if ((dy != nullptr) && (len != n)) { \
int res = xpu::reduce_ew(dev_ctx.x_context(), dy_data, dy->data<T>(), \
int res = xpu::reduce_ew(dev_ctx.x_context(), dy_data, dy->data<T>(), \
pre, n, post, xpu::ElementwiseOp::ASSIGN); \
pre, n, post, xpu::ElementwiseOp::ASSIGN); \
PADDLE_ENFORCE_EQ(res, xpu::Error_t::SUCCESS, \
PADDLE_ENFORCE_EQ( \
platform::errors::Fatal("XPU kernel error!")); \
res, xpu::Error_t::SUCCESS, \
platform::errors::External("XPU kernel error occur! %s", \
get_xpu_error_message(res))); \
dev_ctx.Wait(); \
dev_ctx.Wait(); \
xpu_free(dy_data); \
xpu_free(dy_data); \
} \
} \
...
@@ -161,8 +183,8 @@ void XPUElementwise(const framework::ExecutionContext& ctx) {
...
@@ -161,8 +183,8 @@ void XPUElementwise(const framework::ExecutionContext& ctx) {
platform
::
errors
::
PreconditionNotMet
(
platform
::
errors
::
PreconditionNotMet
(
"This kernel only runs on XPU device."
));
"This kernel only runs on XPU device."
));
auto
x_var
=
ctx
.
InputVar
(
"X"
);
auto
x_var
=
ctx
.
InputVar
(
"X"
);
PADDLE_ENFORCE_NE
(
x_var
,
nullptr
,
PADDLE_ENFORCE_NE
(
x_var
,
nullptr
,
platform
::
errors
::
InvalidArgument
(
platform
::
errors
::
Fatal
(
"Cannot get input Variable X"
));
"Cannot get input Variable X"
));
PADDLE_ENFORCE_EQ
(
PADDLE_ENFORCE_EQ
(
x_var
->
IsType
<
framework
::
LoDTensor
>
(),
true
,
x_var
->
IsType
<
framework
::
LoDTensor
>
(),
true
,
platform
::
errors
::
InvalidArgument
(
platform
::
errors
::
InvalidArgument
(
...
@@ -206,36 +228,36 @@ void XPUElementwise(const framework::ExecutionContext& ctx) {
...
@@ -206,36 +228,36 @@ void XPUElementwise(const framework::ExecutionContext& ctx) {
if
(
std
::
is_same
<
Functor
,
XPUAddFunctor
<
T
>>::
value
)
{
if
(
std
::
is_same
<
Functor
,
XPUAddFunctor
<
T
>>::
value
)
{
int
res
=
xpu
::
matrix_vector_add
(
dev_ctx
.
x_context
(),
x_data
,
y_data
,
int
res
=
xpu
::
matrix_vector_add
(
dev_ctx
.
x_context
(),
x_data
,
y_data
,
z_data
,
pre
,
n
);
z_data
,
pre
,
n
);
PADDLE_ENFORCE_EQ
(
PADDLE_ENFORCE_EQ
(
res
,
xpu
::
Error_t
::
SUCCESS
,
res
,
xpu
::
Error_t
::
SUCCESS
,
platform
::
errors
::
External
(
"XPU kernel error occur! %s"
,
platform
::
errors
::
Fatal
(
"XPU kernel error! res = %d"
,
res
));
get_xpu_error_message
(
res
)
));
return
;
return
;
}
}
if
(
std
::
is_same
<
Functor
,
XPUMulFunctor
<
T
>>::
value
)
{
if
(
std
::
is_same
<
Functor
,
XPUMulFunctor
<
T
>>::
value
)
{
int
res
=
xpu
::
matrix_vector_mul
(
dev_ctx
.
x_context
(),
x_data
,
y_data
,
int
res
=
xpu
::
matrix_vector_mul
(
dev_ctx
.
x_context
(),
x_data
,
y_data
,
z_data
,
pre
,
n
);
z_data
,
pre
,
n
);
PADDLE_ENFORCE_EQ
(
PADDLE_ENFORCE_EQ
(
res
,
xpu
::
Error_t
::
SUCCESS
,
res
,
xpu
::
Error_t
::
SUCCESS
,
platform
::
errors
::
External
(
"XPU kernel error occur! %s"
,
platform
::
errors
::
Fatal
(
"XPU kernel error! res = %d"
,
res
));
get_xpu_error_message
(
res
)
));
return
;
return
;
}
}
}
}
if
(
pre
!=
1
||
post
!=
1
)
{
if
(
pre
!=
1
||
post
!=
1
)
{
PADDLE_ENFORCE
(
xpu_malloc
(
reinterpret_cast
<
void
**>
(
&
y_broadcast
),
XPU_MALLOC
(
&
y_broadcast
,
len
*
sizeof
(
T
));
len
*
sizeof
(
T
))
==
XPU_SUCCESS
);
int
res
=
xpu
::
broadcast_ew
(
dev_ctx
.
x_context
(),
y_data
,
y_broadcast
,
pre
,
int
res
=
xpu
::
broadcast_ew
(
dev_ctx
.
x_context
(),
y_data
,
y_broadcast
,
pre
,
n
,
post
,
xpu
::
ElementwiseOp
::
ASSIGN
);
n
,
post
,
xpu
::
ElementwiseOp
::
ASSIGN
);
PADDLE_ENFORCE_EQ
(
PADDLE_ENFORCE_EQ
(
res
,
xpu
::
Error_t
::
SUCCESS
,
res
,
xpu
::
Error_t
::
SUCCESS
,
platform
::
errors
::
External
(
"XPU kernel error occur! %s"
,
platform
::
errors
::
Fatal
(
"XPU kernel error! res = %d"
,
res
));
get_xpu_error_message
(
res
)
));
y_data
=
y_broadcast
;
y_data
=
y_broadcast
;
}
}
Functor
functor
;
Functor
functor
;
int
res
=
functor
(
dev_ctx
.
x_context
(),
x_data
,
y_data
,
z_data
,
len
);
int
res
=
functor
(
dev_ctx
.
x_context
(),
x_data
,
y_data
,
z_data
,
len
);
PADDLE_ENFORCE_EQ
(
res
,
xpu
::
Error_t
::
SUCCESS
,
PADDLE_ENFORCE_EQ
(
res
,
xpu
::
Error_t
::
SUCCESS
,
platform
::
errors
::
Fatal
(
"XPU kernel error! res = %d"
,
res
));
platform
::
errors
::
External
(
"XPU kernel error occur! %s"
,
get_xpu_error_message
(
res
)));
if
(
pre
!=
1
||
post
!=
1
)
{
if
(
pre
!=
1
||
post
!=
1
)
{
dev_ctx
.
Wait
();
dev_ctx
.
Wait
();
...
...
python/paddle/fluid/tests/unittests/xpu/elementwise.py
浏览文件 @
a6c18075
...
@@ -54,7 +54,7 @@ class TestXPUElementwiseOpBase(object):
...
@@ -54,7 +54,7 @@ class TestXPUElementwiseOpBase(object):
inputs_to_check
,
inputs_to_check
,
output_names
,
output_names
,
no_grad_set
=
None
,
no_grad_set
=
None
,
max_relative_error
=
0.0
5
):
max_relative_error
=
0.0
1
):
if
self
.
grad_implemented
and
not
self
.
is_common_broadcast
\
if
self
.
grad_implemented
and
not
self
.
is_common_broadcast
\
and
not
self
.
is_x_size_less_than_y
:
and
not
self
.
is_x_size_less_than_y
:
if
paddle
.
is_compiled_with_xpu
():
if
paddle
.
is_compiled_with_xpu
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录