Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8b1048b4
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8b1048b4
编写于
2月 16, 2022
作者:
L
Leo Chen
提交者:
GitHub
2月 16, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "[pten] remove concat fluid kernel (#39268)"
This reverts commit
552db8dc
.
上级
a909bdf1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
74 addition
and
3 deletion
+74
-3
paddle/fluid/operators/concat_op.cc
paddle/fluid/operators/concat_op.cc
+13
-1
paddle/fluid/operators/concat_op.cu.cc
paddle/fluid/operators/concat_op.cu.cc
+12
-1
paddle/fluid/operators/concat_op.h
paddle/fluid/operators/concat_op.h
+48
-0
paddle/fluid/operators/tensor_array_to_tensor_op.cc
paddle/fluid/operators/tensor_array_to_tensor_op.cc
+1
-1
未找到文件。
paddle/fluid/operators/concat_op.cc
浏览文件 @
8b1048b4
...
...
@@ -244,7 +244,19 @@ REGISTER_OPERATOR(concat_grad, ops::ConcatOpGrad,
ops
::
ConcatDoubleGradOpMaker
<
paddle
::
framework
::
OpDesc
>
,
ops
::
ConcatDoubleGradOpMaker
<
paddle
::
imperative
::
OpBase
>
,
ops
::
ConcatOpGradNoNeedBufferVarInferer
);
REGISTER_OP_CPU_KERNEL
(
concat
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CPUDeviceContext
,
bool
>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int64_t
>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
float16
>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int
>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CPUDeviceContext
,
uint8_t
>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
complex
<
float
>>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CPUDeviceContext
,
paddle
::
platform
::
complex
<
double
>>
);
REGISTER_OP_CPU_KERNEL
(
concat_grad
,
ops
::
ConcatGradKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
>
,
...
...
paddle/fluid/operators/concat_op.cu.cc
浏览文件 @
8b1048b4
...
...
@@ -19,7 +19,18 @@ limitations under the License. */
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
REGISTER_OP_CUDA_KERNEL
(
concat
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CUDADeviceContext
,
double
>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CUDADeviceContext
,
bool
>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CUDADeviceContext
,
plat
::
float16
>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int64_t
>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int
>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CUDADeviceContext
,
uint8_t
>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CUDADeviceContext
,
plat
::
complex
<
float
>>
,
ops
::
ConcatKernel
<
paddle
::
platform
::
CUDADeviceContext
,
plat
::
complex
<
double
>>
);
REGISTER_OP_CUDA_KERNEL
(
concat_grad
,
ops
::
ConcatGradKernel
<
paddle
::
platform
::
CUDADeviceContext
,
double
>
,
...
...
paddle/fluid/operators/concat_op.h
浏览文件 @
8b1048b4
...
...
@@ -39,6 +39,54 @@ static inline int64_t ComputeAxis(int64_t axis, int64_t rank) {
}
return
axis
>
0
?
axis
:
0
;
}
template
<
typename
DeviceContext
,
typename
T
>
class
ConcatKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
auto
ins
=
ctx
.
MultiInput
<
framework
::
LoDTensor
>
(
"X"
);
framework
::
LoDTensor
*
out
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
);
PADDLE_ENFORCE_NOT_NULL
(
ins
[
0
],
platform
::
errors
::
NotFound
(
"The first input tensor is not initalized."
));
auto
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
bool
need_resize_out_dims
=
false
;
if
(
ctx
.
HasInput
(
"AxisTensor"
))
{
auto
*
axis_tensor
=
ctx
.
Input
<
framework
::
Tensor
>
(
"AxisTensor"
);
axis
=
GetDataFromTensor
<
int
>
(
axis_tensor
)[
0
];
need_resize_out_dims
=
true
;
}
axis
=
ComputeAxis
(
static_cast
<
int64_t
>
(
axis
),
static_cast
<
int64_t
>
(
ins
[
0
]
->
dims
().
size
()));
if
(
need_resize_out_dims
)
{
const
size_t
n
=
ins
.
size
();
std
::
vector
<
framework
::
DDim
>
ins_dims
(
n
);
for
(
size_t
i
=
0
;
i
<
n
;
i
++
)
{
ins_dims
[
i
]
=
ins
[
i
]
->
dims
();
}
framework
::
DDim
out_dims
=
pten
::
funcs
::
ComputeAndCheckShape
(
true
,
ins_dims
,
axis
);
out
->
Resize
(
out_dims
);
}
auto
place
=
ctx
.
GetPlace
();
out
->
mutable_data
<
T
>
(
place
);
// call new kernel
auto
&
dev_ctx
=
ctx
.
device_context
<
DeviceContext
>
();
std
::
vector
<
pten
::
DenseTensor
>
pt_ins
;
for
(
auto
&
in
:
ins
)
{
pt_ins
.
push_back
(
*
in
);
}
pten
::
ConcatKernel
<
T
>
(
static_cast
<
const
typename
paddle
::
framework
::
ConvertToPtenContext
<
DeviceContext
>::
TYPE
&>
(
dev_ctx
),
pt_ins
,
axis
,
out
);
}
};
template
<
typename
DeviceContext
,
typename
T
>
class
ConcatGradKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
...
...
paddle/fluid/operators/tensor_array_to_tensor_op.cc
浏览文件 @
8b1048b4
...
...
@@ -299,7 +299,7 @@ class TensorArrayToTensorGradOpMaker : public framework::SingleGradOpMaker<T> {
}
// namespace operators
}
// namespace paddle
USE_OP
_ITSELF
(
concat
);
USE_OP
(
concat
);
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录