Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
eee6b3a7
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
eee6b3a7
编写于
10月 14, 2022
作者:
R
Rayman
提交者:
GitHub
10月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
speed_up for deformable conv (#46997)
上级
a6a2618e
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
39 addition
and
5 deletion
+39
-5
paddle/phi/kernels/impl/deformable_conv_kernel_impl.h
paddle/phi/kernels/impl/deformable_conv_kernel_impl.h
+39
-5
未找到文件。
paddle/phi/kernels/impl/deformable_conv_kernel_impl.h
浏览文件 @
eee6b3a7
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#include "paddle/phi/kernels/empty_kernel.h"
#include "paddle/phi/kernels/empty_kernel.h"
#include "paddle/phi/kernels/funcs/blas/blas.h"
#include "paddle/phi/kernels/funcs/blas/blas.h"
#include "paddle/phi/kernels/funcs/deformable_conv_functor.h"
#include "paddle/phi/kernels/funcs/deformable_conv_functor.h"
#include "paddle/phi/kernels/transpose_kernel.h"
#include "paddle/utils/optional.h"
#include "paddle/utils/optional.h"
namespace
phi
{
namespace
phi
{
...
@@ -38,6 +39,11 @@ void DeformableConvKernel(const Context& dev_ctx,
...
@@ -38,6 +39,11 @@ void DeformableConvKernel(const Context& dev_ctx,
DenseTensor
*
out
)
{
DenseTensor
*
out
)
{
const
int
batch_size
=
static_cast
<
int
>
(
x
.
dims
()[
0
]);
const
int
batch_size
=
static_cast
<
int
>
(
x
.
dims
()[
0
]);
int
temp_step
=
std
::
min
(
64
,
batch_size
);
if
(
batch_size
%
temp_step
==
0
)
{
im2col_step
=
temp_step
;
}
std
::
vector
<
int64_t
>
filter_shape_vec
(
phi
::
vectorize
(
filter
.
dims
()));
std
::
vector
<
int64_t
>
filter_shape_vec
(
phi
::
vectorize
(
filter
.
dims
()));
std
::
vector
<
int64_t
>
output_shape_vec
(
phi
::
vectorize
(
out
->
dims
()));
std
::
vector
<
int64_t
>
output_shape_vec
(
phi
::
vectorize
(
out
->
dims
()));
...
@@ -101,8 +107,11 @@ void DeformableConvKernel(const Context& dev_ctx,
...
@@ -101,8 +107,11 @@ void DeformableConvKernel(const Context& dev_ctx,
dilations
,
dilations
,
deformable_groups
,
deformable_groups
,
col_buffer_ptr
);
col_buffer_ptr
);
DenseTensor
output_3d
=
output_4d
.
Slice
(
i
,
i
+
1
).
Resize
(
DenseTensor
output_3d
=
output_4d
.
Slice
(
i
,
i
+
1
).
Resize
(
phi
::
slice_ddim
(
phi
::
slice_ddim
(
output_4d
.
dims
(),
1
,
output_4d
.
dims
().
size
()));
output_4d
.
dims
(),
1
,
output_4d
.
dims
().
size
()));
// group * C/group * (im2step * H * W)
// get the product of pixel and weight
// get the product of pixel and weight
for
(
int
g
=
0
;
g
<
groups
;
++
g
)
{
for
(
int
g
=
0
;
g
<
groups
;
++
g
)
{
DenseTensor
weight_3d_slice
=
weight_3d
.
Slice
(
g
,
g
+
1
).
Resize
(
DenseTensor
weight_3d_slice
=
weight_3d
.
Slice
(
g
,
g
+
1
).
Resize
(
...
@@ -110,8 +119,11 @@ void DeformableConvKernel(const Context& dev_ctx,
...
@@ -110,8 +119,11 @@ void DeformableConvKernel(const Context& dev_ctx,
DenseTensor
col_buffer_3d_slice
=
DenseTensor
col_buffer_3d_slice
=
col_buffer_3d
.
Slice
(
g
,
g
+
1
).
Resize
(
phi
::
slice_ddim
(
col_buffer_3d
.
Slice
(
g
,
g
+
1
).
Resize
(
phi
::
slice_ddim
(
col_buffer_3d
.
dims
(),
1
,
col_buffer_3d
.
dims
().
size
()));
col_buffer_3d
.
dims
(),
1
,
col_buffer_3d
.
dims
().
size
()));
DenseTensor
output_3d_slice
=
output_3d
.
Slice
(
g
,
g
+
1
).
Resize
(
DenseTensor
output_3d_slice
=
phi
::
slice_ddim
(
output_3d
.
dims
(),
1
,
output_3d
.
dims
().
size
()));
output_3d
.
Slice
(
g
,
g
+
1
).
Resize
(
phi
::
slice_ddim
(
output_3d
.
dims
(),
1
,
output_3d
.
dims
().
size
()));
// C * ((im2col_step)*H*W))
blas
.
MatMul
(
weight_3d_slice
,
blas
.
MatMul
(
weight_3d_slice
,
false
,
false
,
col_buffer_3d_slice
,
col_buffer_3d_slice
,
...
@@ -121,7 +133,29 @@ void DeformableConvKernel(const Context& dev_ctx,
...
@@ -121,7 +133,29 @@ void DeformableConvKernel(const Context& dev_ctx,
T
(
0.0
));
T
(
0.0
));
}
}
}
}
// swap axis to get the right result when im2col_step is greater than 1
if
(
im2col_step
>
1
)
{
std
::
vector
<
int
>
axis
(
4
);
axis
[
0
]
=
0
;
axis
[
1
]
=
2
;
axis
[
2
]
=
1
;
axis
[
3
]
=
3
;
DenseTensor
real_output_buffer
=
phi
::
Transpose
<
T
,
Context
>
(
dev_ctx
,
output_4d
.
Resize
(
phi
::
make_ddim
({
batch_size
/
im2col_step
,
output_shape_vec
[
1
],
im2col_step
,
output_shape_vec
[
2
]
*
output_shape_vec
[
3
]})),
axis
);
out
->
ShareDataWith
(
real_output_buffer
)
.
Resize
(
phi
::
make_ddim
(
output_shape_vec
));
}
else
{
out
->
ShareDataWith
(
output_buffer
).
Resize
(
phi
::
make_ddim
(
output_shape_vec
));
out
->
ShareDataWith
(
output_buffer
).
Resize
(
phi
::
make_ddim
(
output_shape_vec
));
}
}
}
}
// namespace phi
}
// namespace phi
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录