Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
190cf44f
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看板
未验证
提交
190cf44f
编写于
5月 12, 2022
作者:
F
fwenguang
提交者:
GitHub
5月 12, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[MLU] fix cnnl error when index is 2D (#42669)
上级
9ac736c2
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
37 addition
and
2 deletion
+37
-2
paddle/fluid/operators/gather_op_mlu.cc
paddle/fluid/operators/gather_op_mlu.cc
+37
-2
未找到文件。
paddle/fluid/operators/gather_op_mlu.cc
浏览文件 @
190cf44f
...
@@ -27,11 +27,28 @@ class GatherOpMLUKernel : public framework::OpKernel<T> {
...
@@ -27,11 +27,28 @@ class GatherOpMLUKernel : public framework::OpKernel<T> {
auto
*
index
=
ctx
.
Input
<
Tensor
>
(
"Index"
);
auto
*
index
=
ctx
.
Input
<
Tensor
>
(
"Index"
);
auto
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
auto
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
const
auto
index_dims
=
index
->
dims
();
if
(
index_dims
.
size
()
==
2
)
{
PADDLE_ENFORCE_EQ
(
index_dims
[
1
],
1
,
platform
::
errors
::
InvalidArgument
(
"The last dim of index should be 1 when it is 2D, but we get %d"
,
index_dims
[
1
]));
}
else
{
PADDLE_ENFORCE_EQ
(
index_dims
.
size
(),
1
,
platform
::
errors
::
InvalidArgument
(
"The index should be 1D, when it is not 2D, but we get %d"
,
index_dims
.
size
()));
}
auto
*
out
=
ctx
.
Output
<
Tensor
>
(
"Out"
);
auto
*
out
=
ctx
.
Output
<
Tensor
>
(
"Out"
);
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
MLUCnnlTensorDesc
x_desc
(
*
x
);
MLUCnnlTensorDesc
x_desc
(
*
x
);
MLUCnnlTensorDesc
index_desc
(
*
index
);
int
index_shape_1d
[
1
]
=
{
static_cast
<
int
>
(
index_dims
[
0
])};
MLUCnnlTensorDesc
index_desc
(
1
,
index_shape_1d
,
ToCnnlDataType
(
index
->
dtype
()));
MLUCnnlTensorDesc
out_desc
(
*
out
);
MLUCnnlTensorDesc
out_desc
(
*
out
);
MLUCnnl
::
GatherFunctor
(
ctx
,
axis
,
0
/*batch_dims*/
,
x_desc
.
get
(),
MLUCnnl
::
GatherFunctor
(
ctx
,
axis
,
0
/*batch_dims*/
,
x_desc
.
get
(),
GetBasePtr
(
x
),
index_desc
.
get
(),
GetBasePtr
(
index
),
GetBasePtr
(
x
),
index_desc
.
get
(),
GetBasePtr
(
index
),
...
@@ -46,6 +63,22 @@ class GatherGradOpMLUKernel : public framework::OpKernel<T> {
...
@@ -46,6 +63,22 @@ class GatherGradOpMLUKernel : public framework::OpKernel<T> {
auto
*
index
=
ctx
.
Input
<
Tensor
>
(
"Index"
);
auto
*
index
=
ctx
.
Input
<
Tensor
>
(
"Index"
);
auto
*
dout
=
ctx
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
dout
=
ctx
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
dx
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
auto
*
dx
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
const
auto
index_dims
=
index
->
dims
();
if
(
index_dims
.
size
()
==
2
)
{
PADDLE_ENFORCE_EQ
(
index_dims
[
1
],
1
,
platform
::
errors
::
InvalidArgument
(
"The last dim of index should be 1 when it is 2D, but we get %d"
,
index_dims
[
1
]));
}
else
{
PADDLE_ENFORCE_EQ
(
index_dims
.
size
(),
1
,
platform
::
errors
::
InvalidArgument
(
"The index should be 1D, when it is not 2D, but we get %d"
,
index_dims
.
size
()));
}
dx
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
dx
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
MLUCnnlTensorDesc
dx_desc
(
*
dx
);
MLUCnnlTensorDesc
dx_desc
(
*
dx
);
...
@@ -53,7 +86,9 @@ class GatherGradOpMLUKernel : public framework::OpKernel<T> {
...
@@ -53,7 +86,9 @@ class GatherGradOpMLUKernel : public framework::OpKernel<T> {
MLUCnnl
::
Fill
(
ctx
,
CNNL_POINTER_MODE_HOST
,
&
value
,
dx_desc
.
get
(),
MLUCnnl
::
Fill
(
ctx
,
CNNL_POINTER_MODE_HOST
,
&
value
,
dx_desc
.
get
(),
GetBasePtr
(
dx
));
GetBasePtr
(
dx
));
MLUCnnlTensorDesc
index_desc
(
*
index
);
int
index_shape_1d
[
1
]
=
{
static_cast
<
int
>
(
index_dims
[
0
])};
MLUCnnlTensorDesc
index_desc
(
1
,
index_shape_1d
,
ToCnnlDataType
(
index
->
dtype
()));
MLUCnnlTensorDesc
dout_desc
(
*
dout
);
MLUCnnlTensorDesc
dout_desc
(
*
dout
);
const
cnnlScatterRefMode_t
mode
=
CNNL_SCATTERREF_UPDATE
;
const
cnnlScatterRefMode_t
mode
=
CNNL_SCATTERREF_UPDATE
;
MLUCnnl
::
ScatterFunctor
(
ctx
,
dx_desc
.
get
(),
GetBasePtr
(
dx
),
dout_desc
.
get
(),
MLUCnnl
::
ScatterFunctor
(
ctx
,
dx_desc
.
get
(),
GetBasePtr
(
dx
),
dout_desc
.
get
(),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录