Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
fe911a51
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看板
未验证
提交
fe911a51
编写于
6月 02, 2022
作者:
C
Chenxiao Niu
提交者:
GitHub
6月 02, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add concat_grad mlu kernel. (#43117)
上级
d999049f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
64 addition
and
0 deletion
+64
-0
paddle/fluid/operators/concat_op_mlu.cc
paddle/fluid/operators/concat_op_mlu.cc
+64
-0
未找到文件。
paddle/fluid/operators/concat_op_mlu.cc
浏览文件 @
fe911a51
...
...
@@ -74,6 +74,64 @@ class ConcatMLUKernel : public framework::OpKernel<T> {
output_desc
.
get
(),
GetBasePtr
(
out
));
}
};
template
<
typename
T
>
class
ConcatGradMLUKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
auto
*
out_grad
=
ctx
.
Input
<
framework
::
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
ins
=
ctx
.
MultiInput
<
framework
::
LoDTensor
>
(
"X"
);
auto
out_var_names
=
ctx
.
OutputNames
(
framework
::
GradVarName
(
"X"
));
auto
outs
=
ctx
.
MultiOutput
<
framework
::
LoDTensor
>
(
framework
::
GradVarName
(
"X"
));
auto
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
int
split_num
=
ins
.
size
();
PADDLE_ENFORCE_NOT_NULL
(
ins
[
0
],
platform
::
errors
::
NotFound
(
"The first input tensor is not initalized."
));
if
(
ctx
.
HasInput
(
"AxisTensor"
))
{
auto
*
axis_tensor
=
ctx
.
Input
<
framework
::
Tensor
>
(
"AxisTensor"
);
axis
=
GetDataFromTensor
<
int
>
(
axis_tensor
)[
0
];
}
axis
=
ComputeAxis
(
static_cast
<
int64_t
>
(
axis
),
static_cast
<
int64_t
>
(
ins
[
0
]
->
dims
().
size
()));
PADDLE_ENFORCE_GE
(
axis
,
0
,
platform
::
errors
::
InvalidArgument
(
"concat_grad: axis should be larger than or "
"equal to 0, but received axis is %d."
,
axis
));
PADDLE_ENFORCE_LT
(
axis
,
out_grad
->
dims
().
size
(),
platform
::
errors
::
InvalidArgument
(
"concat_grad: axis should be less than ins[0]->dims()!"
"But received axis is %d, while ins[0]->dims()"
"size is %d."
,
axis
,
out_grad
->
dims
().
size
()));
// get output tensor that the name is not kEmptyVarName
std
::
vector
<
void
*>
outputs_vec
;
std
::
vector
<
MLUCnnlTensorDesc
>
output_descs
;
std
::
vector
<
cnnlTensorDescriptor_t
>
descs_vec
;
for
(
size_t
j
=
0
;
j
<
outs
.
size
();
++
j
)
{
if
(
out_var_names
[
j
]
!=
framework
::
kEmptyVarName
&&
outs
[
j
]
->
numel
()
!=
0UL
)
{
outs
[
j
]
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
output_descs
.
emplace_back
(
MLUCnnlTensorDesc
(
*
outs
[
j
]));
descs_vec
.
push_back
(
output_descs
.
back
().
get
());
outputs_vec
.
push_back
(
GetBasePtr
(
outs
[
j
]));
}
else
{
outputs_vec
.
push_back
(
nullptr
);
}
}
MLUCnnlTensorDesc
out_grad_desc
(
*
out_grad
);
MLUCnnl
::
Split
(
ctx
,
static_cast
<
int
>
(
split_num
),
static_cast
<
int
>
(
axis
),
out_grad_desc
.
get
(),
GetBasePtr
(
out_grad
),
descs_vec
.
data
(),
outputs_vec
.
data
());
}
};
}
// namespace operators
}
// namespace paddle
...
...
@@ -84,3 +142,9 @@ REGISTER_OP_MLU_KERNEL(concat, ops::ConcatMLUKernel<float>,
ops
::
ConcatMLUKernel
<
int64_t
>
,
ops
::
ConcatMLUKernel
<
bool
>
,
ops
::
ConcatMLUKernel
<
int
>
,
ops
::
ConcatMLUKernel
<
uint8_t
>
);
REGISTER_OP_MLU_KERNEL
(
concat_grad
,
ops
::
ConcatGradMLUKernel
<
float
>
,
ops
::
ConcatGradMLUKernel
<
paddle
::
platform
::
float16
>
,
ops
::
ConcatGradMLUKernel
<
int64_t
>
,
ops
::
ConcatGradMLUKernel
<
bool
>
,
ops
::
ConcatGradMLUKernel
<
int
>
,
ops
::
ConcatGradMLUKernel
<
uint8_t
>
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录