Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c95c35a2
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看板
未验证
提交
c95c35a2
编写于
1月 12, 2023
作者:
G
gem5
提交者:
GitHub
1月 12, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
conv2d_fusion(cudnn or cutlass) (#49707)
上级
3fb4a08c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
24 addition
and
21 deletion
+24
-21
paddle/fluid/framework/ir/conv2d_fusion_layout_transfer_pass.cc
.../fluid/framework/ir/conv2d_fusion_layout_transfer_pass.cc
+24
-21
未找到文件。
paddle/fluid/framework/ir/conv2d_fusion_layout_transfer_pass.cc
浏览文件 @
c95c35a2
...
...
@@ -155,7 +155,7 @@ void Conv2dFusionLayoutTransferPass::ApplyImpl(ir::Graph *graph) const {
}
#endif
if
(
!
(
is_fp16_precision
&&
cutlass_enable
)
)
return
;
if
(
!
is_fp16_precision
)
return
;
PADDLE_ENFORCE_EQ
(
graph
->
IsMainGraph
(),
true
,
...
...
@@ -180,16 +180,31 @@ void Conv2dFusionLayoutTransferPass::ApplyImpl(ir::Graph *graph) const {
std
::
string
target_op_type
=
"conv2d_fusion"
;
std
::
unordered_set
<
ir
::
Node
*>
valid_ops
;
auto
Op
IsValid
=
[
&
](
ir
::
Node
*
op_node
)
->
bool
{
auto
cuDNN
IsValid
=
[
&
](
ir
::
Node
*
op_node
)
->
bool
{
if
(
op_node
->
Op
()
->
Type
()
!=
target_op_type
)
return
false
;
auto
data_format
=
op_node
->
Op
()
->
GetAttrIfExists
<
std
::
string
>
(
"data_format"
);
if
(
data_format
!=
"NCHW"
)
return
false
;
auto
filter_names
=
op_node
->
Op
()
->
Input
(
"Filter"
);
auto
act_type
=
op_node
->
Op
()
->
GetAttrIfExists
<
std
::
string
>
(
"activation"
);
constexpr
int
CUTLASS_NHWC_ALIGNMENT
=
8
;
// If filter's channel is not multiple of 8, conv2d_fusion not run at nhwc.
for
(
const
auto
&
filter_name
:
filter_names
)
{
auto
*
filter_var
=
scope
->
FindLocalVar
(
filter_name
);
const
auto
&
filter_tensor
=
filter_var
->
Get
<
phi
::
DenseTensor
>
();
CHECK_EQ
(
filter_tensor
.
dims
().
size
()
==
4UL
,
true
);
int
oc
=
filter_tensor
.
dims
()[
0
];
int
ic
=
filter_tensor
.
dims
()[
1
];
bool
cutlass_can_support
=
oc
%
CUTLASS_NHWC_ALIGNMENT
==
0
&&
ic
%
CUTLASS_NHWC_ALIGNMENT
==
0
;
if
(
!
cutlass_can_support
)
{
return
false
;
}
}
return
true
;
};
auto
CutlassIsValid
=
[
&
](
ir
::
Node
*
op_node
)
->
bool
{
auto
act_type
=
op_node
->
Op
()
->
GetAttrIfExists
<
std
::
string
>
(
"activation"
);
// conv2d_fusion has two forms: conv + bias + act, conv + bias +
// elmentwise_add + act.
std
::
unordered_set
<
std
::
string
>
cutlass_cba_act_set
=
{
...
...
@@ -206,31 +221,19 @@ void Conv2dFusionLayoutTransferPass::ApplyImpl(ir::Graph *graph) const {
return
false
;
}
}
// If filter's channel is not multiple of 8, conv2d_fusion not run at nhwc.
for
(
const
auto
&
filter_name
:
filter_names
)
{
auto
*
filter_var
=
scope
->
FindLocalVar
(
filter_name
);
const
auto
&
filter_tensor
=
filter_var
->
Get
<
phi
::
DenseTensor
>
();
CHECK_EQ
(
filter_tensor
.
dims
().
size
()
==
4UL
,
true
);
int
oc
=
filter_tensor
.
dims
()[
0
];
int
ic
=
filter_tensor
.
dims
()[
1
];
bool
cutlass_can_support
=
oc
%
CUTLASS_NHWC_ALIGNMENT
==
0
&&
ic
%
CUTLASS_NHWC_ALIGNMENT
==
0
;
if
(
!
cutlass_can_support
)
{
return
false
;
}
}
return
true
;
};
for
(
auto
*
op_node
:
op_nodes
)
{
CHECK_EQ
(
op_node
->
IsOp
(),
true
);
if
(
Op
IsValid
(
op_node
))
{
if
(
cuDNN
IsValid
(
op_node
))
{
valid_ops
.
insert
(
op_node
);
auto
*
op_desc
=
op_node
->
Op
();
auto
nhwc_attr
=
framework
::
Attribute
(
std
::
string
(
"NHWC"
));
op_desc
->
SetAttr
(
"data_format"
,
nhwc_attr
);
op_desc
->
SetType
(
"conv2d_fusion_cutlass"
);
if
(
cutlass_enable
&&
CutlassIsValid
(
op_node
))
{
op_desc
->
SetType
(
"conv2d_fusion_cutlass"
);
}
op_desc
->
Flush
();
// transfer weights
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录