Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wmsofts
Paddle
提交
30f4ef7f
P
Paddle
项目概览
wmsofts
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
30f4ef7f
编写于
12月 05, 2022
作者:
Z
zhoutianzi666
提交者:
GitHub
12月 05, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support nhwc in conv2d_fusion (#48642)
上级
4639d65d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
46 addition
and
12 deletion
+46
-12
paddle/fluid/operators/fused/conv_fusion_op.cc
paddle/fluid/operators/fused/conv_fusion_op.cc
+37
-12
paddle/fluid/operators/fused/conv_fusion_op.cu
paddle/fluid/operators/fused/conv_fusion_op.cu
+9
-0
未找到文件。
paddle/fluid/operators/fused/conv_fusion_op.cc
浏览文件 @
30f4ef7f
...
@@ -81,12 +81,16 @@ class Conv2DFusionOp : public operators::ConvOp {
...
@@ -81,12 +81,16 @@ class Conv2DFusionOp : public operators::ConvOp {
std
::
string
data_format
=
ctx
->
Attrs
().
Get
<
std
::
string
>
(
"data_format"
);
std
::
string
data_format
=
ctx
->
Attrs
().
Get
<
std
::
string
>
(
"data_format"
);
PADDLE_ENFORCE_NE
(
PADDLE_ENFORCE_NE
(
data_format
,
data_format
,
"NHWC"
,
"N
D
HWC"
,
platform
::
errors
::
PermissionDenied
(
platform
::
errors
::
PermissionDenied
(
"Operator(Conv2DFusion) only supports data format of "
"Operator(Conv2DFusion) supports data format of "
"channel first (NCHW) now. But received: data_format = '%s'."
,
"channel first (NCHW,NCDHW) and data format of channel last(NHWC) "
"now. But received: data_format = '%s'."
,
data_format
));
data_format
));
// MKL-DNN Kernels are using NCHW order of dims description
// so we ignore data_format consideration for MKL-DNN kernel
const
bool
channel_last
=
(
ctx
->
IsRunMKLDNNKernel
()
==
false
)
&&
(
data_format
==
"NHWC"
||
data_format
==
"NDHWC"
);
std
::
vector
<
int64_t
>
output_shape
=
ComputeOutputShape
(
ctx
);
std
::
vector
<
int64_t
>
output_shape
=
ComputeOutputShape
(
ctx
);
ctx
->
SetOutputDim
(
"Output"
,
phi
::
make_ddim
(
output_shape
));
ctx
->
SetOutputDim
(
"Output"
,
phi
::
make_ddim
(
output_shape
));
ctx
->
ShareLoD
(
"Input"
,
"Output"
);
ctx
->
ShareLoD
(
"Input"
,
"Output"
);
...
@@ -112,21 +116,31 @@ class Conv2DFusionOp : public operators::ConvOp {
...
@@ -112,21 +116,31 @@ class Conv2DFusionOp : public operators::ConvOp {
std
::
vector
<
framework
::
DDim
>
output_shapes
(
split_channels
.
size
());
std
::
vector
<
framework
::
DDim
>
output_shapes
(
split_channels
.
size
());
for
(
size_t
i
=
0
;
i
<
split_channels
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
split_channels
.
size
();
++
i
)
{
split_channels_sum
+=
split_channels
[
i
];
split_channels_sum
+=
split_channels
[
i
];
output_shapes
[
i
]
=
phi
::
make_ddim
({
output_shape
[
0
],
if
(
channel_last
)
{
split_channels
[
i
],
output_shapes
[
i
]
=
phi
::
make_ddim
({
output_shape
[
0
],
output_shape
[
2
],
output_shape
[
1
],
output_shape
[
3
]});
output_shape
[
2
],
split_channels
[
i
]});
}
else
{
output_shapes
[
i
]
=
phi
::
make_ddim
({
output_shape
[
0
],
split_channels
[
i
],
output_shape
[
2
],
output_shape
[
3
]});
}
}
}
int
output_channels
=
output_shape
[
1
];
// for NHWC
if
(
channel_last
)
output_channels
=
output_shape
[
3
];
PADDLE_ENFORCE_EQ
(
PADDLE_ENFORCE_EQ
(
split_channels_sum
,
split_channels_sum
,
output_
shape
[
1
]
,
output_
channels
,
platform
::
errors
::
InvalidArgument
(
platform
::
errors
::
InvalidArgument
(
"The sum of Attr(split_channels) is expected to be equal to the "
"The sum of Attr(split_channels) is expected to be equal to "
"the "
"total output channels. But received: the sum of "
"total output channels. But received: the sum of "
"Attr(split_channels) = %d, the total output channels = %d."
,
"Attr(split_channels) = %d, the total output channels = %d."
,
split_channels_sum
,
split_channels_sum
,
output_shape
[
1
]));
output_channels
));
ctx
->
SetOutputsDim
(
"Outputs"
,
output_shapes
);
ctx
->
SetOutputsDim
(
"Outputs"
,
output_shapes
);
}
}
}
}
...
@@ -159,6 +173,17 @@ class Conv2DFusionOp : public operators::ConvOp {
...
@@ -159,6 +173,17 @@ class Conv2DFusionOp : public operators::ConvOp {
const
std
::
string
data_format
=
const
std
::
string
data_format
=
ctx
->
Attrs
().
Get
<
std
::
string
>
(
"data_format"
);
ctx
->
Attrs
().
Get
<
std
::
string
>
(
"data_format"
);
// if data_format is NHWC, we convert the weight dimension to the form of
// nchw to minimize program changes.
if
(
data_format
==
"NHWC"
)
{
int
kh
=
filter_dims
[
1
];
int
kw
=
filter_dims
[
2
];
int
ic
=
filter_dims
[
3
];
filter_dims
[
1
]
=
ic
;
filter_dims
[
2
]
=
kh
;
filter_dims
[
3
]
=
kw
;
}
// MKL-DNN Kernels are using NCHW order of dims description
// MKL-DNN Kernels are using NCHW order of dims description
// so we ignore data_format consideration for MKL-DNN kernel
// so we ignore data_format consideration for MKL-DNN kernel
const
bool
channel_last
=
(
ctx
->
IsRunMKLDNNKernel
()
==
false
)
&&
const
bool
channel_last
=
(
ctx
->
IsRunMKLDNNKernel
()
==
false
)
&&
...
...
paddle/fluid/operators/fused/conv_fusion_op.cu
浏览文件 @
30f4ef7f
...
@@ -56,6 +56,15 @@ class CUDNNConvFusionOpKernel : public framework::OpKernel<T> {
...
@@ -56,6 +56,15 @@ class CUDNNConvFusionOpKernel : public framework::OpKernel<T> {
std
::
vector
<
int
>
paddings
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
std
::
vector
<
int
>
paddings
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
std
::
vector
<
int
>
dilations
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"dilations"
);
std
::
vector
<
int
>
dilations
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"dilations"
);
const
std
::
string
activation
=
ctx
.
Attr
<
std
::
string
>
(
"activation"
);
const
std
::
string
activation
=
ctx
.
Attr
<
std
::
string
>
(
"activation"
);
std
::
string
data_format
=
ctx
.
Attr
<
std
::
string
>
(
"data_format"
);
PADDLE_ENFORCE_NE
(
data_format
,
"NHWC"
,
platform
::
errors
::
PermissionDenied
(
"Operator(Conv2DFusion) in cuDNN only supports data format of "
"channel first (NCHW) now. But received: data_format = '%s'."
,
data_format
));
int
groups
=
ctx
.
Attr
<
int
>
(
"groups"
);
int
groups
=
ctx
.
Attr
<
int
>
(
"groups"
);
int64_t
user_workspace_size
=
int64_t
user_workspace_size
=
static_cast
<
size_t
>
(
ctx
.
Attr
<
int
>
(
"workspace_size_MB"
));
static_cast
<
size_t
>
(
ctx
.
Attr
<
int
>
(
"workspace_size_MB"
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录