Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
f94d0537
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f94d0537
编写于
10月 16, 2020
作者:
G
Guanghua Yu
提交者:
GitHub
10月 16, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
error message optimization in mean_xpu,softmax_with_cross_entropy_op_xpu,test=kunlun (#27967)
上级
ff0ebefc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
13 deletion
+28
-13
paddle/fluid/operators/mean_op_xpu.cc
paddle/fluid/operators/mean_op_xpu.cc
+10
-4
paddle/fluid/operators/softmax_with_cross_entropy_op_xpu.cc
paddle/fluid/operators/softmax_with_cross_entropy_op_xpu.cc
+18
-9
未找到文件。
paddle/fluid/operators/mean_op_xpu.cc
浏览文件 @
f94d0537
...
@@ -32,8 +32,11 @@ class MeanXPUKernel : public framework::OpKernel<T> {
...
@@ -32,8 +32,11 @@ class MeanXPUKernel : public framework::OpKernel<T> {
const
float
*
x_data
=
input
->
data
<
float
>
();
const
float
*
x_data
=
input
->
data
<
float
>
();
float
*
y_data
=
output
->
data
<
float
>
();
float
*
y_data
=
output
->
data
<
float
>
();
int
r
=
xpu
::
mean
(
dev_ctx
.
x_context
(),
x_data
,
y_data
,
input
->
numel
());
int
r
=
xpu
::
mean
(
dev_ctx
.
x_context
(),
x_data
,
y_data
,
input
->
numel
());
PADDLE_ENFORCE_EQ
(
r
,
xpu
::
Error_t
::
SUCCESS
,
PADDLE_ENFORCE_EQ
(
platform
::
errors
::
InvalidArgument
(
"XPU kernel error!"
));
r
,
xpu
::
Error_t
::
SUCCESS
,
platform
::
errors
::
External
(
"XPU kernel error, Mean op execution not succeed, error code=%d"
,
r
));
}
}
};
};
template
<
typename
DeviceContext
,
typename
T
>
template
<
typename
DeviceContext
,
typename
T
>
...
@@ -49,8 +52,11 @@ class MeanGradXPUKernel : public framework::OpKernel<T> {
...
@@ -49,8 +52,11 @@ class MeanGradXPUKernel : public framework::OpKernel<T> {
float
*
dx
=
IG
->
data
<
float
>
();
float
*
dx
=
IG
->
data
<
float
>
();
const
float
*
dy
=
OG
->
data
<
float
>
();
const
float
*
dy
=
OG
->
data
<
float
>
();
int
r
=
xpu
::
mean_grad
(
dev_ctx
.
x_context
(),
dx
,
dy
,
IG
->
numel
());
int
r
=
xpu
::
mean_grad
(
dev_ctx
.
x_context
(),
dx
,
dy
,
IG
->
numel
());
PADDLE_ENFORCE_EQ
(
r
,
xpu
::
Error_t
::
SUCCESS
,
PADDLE_ENFORCE_EQ
(
platform
::
errors
::
InvalidArgument
(
"XPU kernel error!"
));
r
,
xpu
::
Error_t
::
SUCCESS
,
platform
::
errors
::
External
(
"XPU kernel error. Mean_grad execution not succeed, error code=%d"
,
r
));
}
}
};
};
...
...
paddle/fluid/operators/softmax_with_cross_entropy_op_xpu.cc
浏览文件 @
f94d0537
...
@@ -28,7 +28,7 @@ class SoftmaxWithCrossEntropyXPUKernel : public framework::OpKernel<T> {
...
@@ -28,7 +28,7 @@ class SoftmaxWithCrossEntropyXPUKernel : public framework::OpKernel<T> {
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
PADDLE_ENFORCE_EQ
(
PADDLE_ENFORCE_EQ
(
platform
::
is_xpu_place
(
context
.
GetPlace
()),
true
,
platform
::
is_xpu_place
(
context
.
GetPlace
()),
true
,
platform
::
errors
::
InvalidArgumen
t
(
"This kernel only runs on XPU."
));
platform
::
errors
::
PreconditionNotMe
t
(
"This kernel only runs on XPU."
));
const
Tensor
*
logits
=
context
.
Input
<
Tensor
>
(
"Logits"
);
const
Tensor
*
logits
=
context
.
Input
<
Tensor
>
(
"Logits"
);
const
Tensor
*
labels
=
context
.
Input
<
Tensor
>
(
"Label"
);
const
Tensor
*
labels
=
context
.
Input
<
Tensor
>
(
"Label"
);
Tensor
*
softmax
=
context
.
Output
<
Tensor
>
(
"Softmax"
);
Tensor
*
softmax
=
context
.
Output
<
Tensor
>
(
"Softmax"
);
...
@@ -46,8 +46,11 @@ class SoftmaxWithCrossEntropyXPUKernel : public framework::OpKernel<T> {
...
@@ -46,8 +46,11 @@ class SoftmaxWithCrossEntropyXPUKernel : public framework::OpKernel<T> {
context
.
template
device_context
<
platform
::
XPUDeviceContext
>();
context
.
template
device_context
<
platform
::
XPUDeviceContext
>();
int
r
=
xpu
::
softmax2d_forward
(
dev_ctx
.
x_context
(),
logits
->
data
<
float
>
(),
int
r
=
xpu
::
softmax2d_forward
(
dev_ctx
.
x_context
(),
logits
->
data
<
float
>
(),
softmax
->
data
<
float
>
(),
n
,
d
);
softmax
->
data
<
float
>
(),
n
,
d
);
PADDLE_ENFORCE_EQ
(
r
,
xpu
::
Error_t
::
SUCCESS
,
PADDLE_ENFORCE_EQ
(
platform
::
errors
::
InvalidArgument
(
"XPU kernel error!"
));
r
,
xpu
::
Error_t
::
SUCCESS
,
platform
::
errors
::
External
(
"XPU kernel error. Softmax2d_forward "
"execution not succeed, error code=%d"
,
r
));
// cross_entropy
// cross_entropy
auto
ignore_index
=
context
.
Attr
<
int
>
(
"ignore_index"
);
auto
ignore_index
=
context
.
Attr
<
int
>
(
"ignore_index"
);
const
bool
soft_label
=
context
.
Attr
<
bool
>
(
"soft_label"
);
const
bool
soft_label
=
context
.
Attr
<
bool
>
(
"soft_label"
);
...
@@ -61,10 +64,13 @@ class SoftmaxWithCrossEntropyXPUKernel : public framework::OpKernel<T> {
...
@@ -61,10 +64,13 @@ class SoftmaxWithCrossEntropyXPUKernel : public framework::OpKernel<T> {
int
*
labels_int32_host
=
int
*
labels_int32_host
=
reinterpret_cast
<
int
*>
(
std
::
malloc
(
n
*
sizeof
(
int
)));
reinterpret_cast
<
int
*>
(
std
::
malloc
(
n
*
sizeof
(
int
)));
int
*
labels_int32_device
=
NULL
;
int
*
labels_int32_device
=
NULL
;
PADDLE_ENFORCE_EQ
(
int
ret
=
xpu_malloc
(
reinterpret_cast
<
void
**>
(
&
labels_int32_device
),
xpu_malloc
(
reinterpret_cast
<
void
**>
(
&
labels_int32_device
),
n
*
sizeof
(
int
));
n
*
sizeof
(
int
)),
PADDLE_ENFORCE_EQ
(
ret
,
XPU_SUCCESS
,
XPU_SUCCESS
,
platform
::
errors
::
InvalidArgument
(
"XPU kernel error!"
));
platform
::
errors
::
External
(
"XPU API return wrong value[%d], please check "
"where Baidu Kunlun Card is properly installed."
,
ret
));
dev_ctx
.
Wait
();
dev_ctx
.
Wait
();
memory
::
Copy
(
platform
::
CPUPlace
(),
labels_int64_host
,
memory
::
Copy
(
platform
::
CPUPlace
(),
labels_int64_host
,
BOOST_GET_CONST
(
platform
::
XPUPlace
,
context
.
GetPlace
()),
BOOST_GET_CONST
(
platform
::
XPUPlace
,
context
.
GetPlace
()),
...
@@ -78,8 +84,11 @@ class SoftmaxWithCrossEntropyXPUKernel : public framework::OpKernel<T> {
...
@@ -78,8 +84,11 @@ class SoftmaxWithCrossEntropyXPUKernel : public framework::OpKernel<T> {
int
r
=
xpu
::
cross_entropy_forward
(
int
r
=
xpu
::
cross_entropy_forward
(
dev_ctx
.
x_context
(),
n
,
d
,
softmax
->
data
<
float
>
(),
dev_ctx
.
x_context
(),
n
,
d
,
softmax
->
data
<
float
>
(),
labels_int32_device
,
loss
->
data
<
float
>
(),
nullptr
,
ignore_index
);
labels_int32_device
,
loss
->
data
<
float
>
(),
nullptr
,
ignore_index
);
PADDLE_ENFORCE_EQ
(
r
,
xpu
::
Error_t
::
SUCCESS
,
PADDLE_ENFORCE_EQ
(
platform
::
errors
::
InvalidArgument
(
"XPU kernel error!"
));
r
,
xpu
::
Error_t
::
SUCCESS
,
platform
::
errors
::
External
(
"XPU kernel error. Cross_entropy_forward "
"execution not succeed, error code=%d"
,
r
));
dev_ctx
.
Wait
();
dev_ctx
.
Wait
();
std
::
free
(
labels_int32_host
);
std
::
free
(
labels_int32_host
);
std
::
free
(
labels_int64_host
);
std
::
free
(
labels_int64_host
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录