Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
cf3ddd3b
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看板
未验证
提交
cf3ddd3b
编写于
6月 22, 2021
作者:
T
TeslaZhao
提交者:
GitHub
6月 22, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass compat of conv_transpose_bias_mkldnn_fuse_pass (#33708)
上级
18284261
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
117 addition
and
1 deletion
+117
-1
paddle/fluid/framework/ir/mkldnn/conv_bias_mkldnn_fuse_pass.cc
...e/fluid/framework/ir/mkldnn/conv_bias_mkldnn_fuse_pass.cc
+102
-0
paddle/fluid/framework/ir/mkldnn/conv_bias_mkldnn_fuse_pass.h
...le/fluid/framework/ir/mkldnn/conv_bias_mkldnn_fuse_pass.h
+2
-0
paddle/fluid/framework/ir/mkldnn/conv_bias_mkldnn_fuse_pass_tester.cc
.../framework/ir/mkldnn/conv_bias_mkldnn_fuse_pass_tester.cc
+13
-1
未找到文件。
paddle/fluid/framework/ir/mkldnn/conv_bias_mkldnn_fuse_pass.cc
浏览文件 @
cf3ddd3b
...
@@ -25,6 +25,102 @@ namespace paddle {
...
@@ -25,6 +25,102 @@ namespace paddle {
namespace
framework
{
namespace
framework
{
namespace
ir
{
namespace
ir
{
ConvBiasFusePass
::
ConvBiasFusePass
()
{
AddOpCompat
(
OpCompat
(
"conv2d"
))
.
AddInput
(
"Input"
)
.
IsTensor
()
.
End
()
.
AddInput
(
"Filter"
)
.
IsTensor
()
.
End
()
.
AddInput
(
"Bias"
)
.
IsTensor
()
.
IsOptional
()
.
End
()
.
AddOutput
(
"Output"
)
.
IsTensor
()
.
End
()
.
AddAttr
(
"strides"
)
.
End
()
.
AddAttr
(
"paddings"
)
.
End
()
.
AddAttr
(
"padding_algorithm"
)
.
IsStringIn
({
"EXPLICIT"
,
"SAME"
,
"VALID"
})
.
End
()
.
AddAttr
(
"groups"
)
.
IsNumGE
(
1
)
.
End
()
.
AddAttr
(
"dilations"
)
.
End
()
.
AddAttr
(
"data_format"
)
.
IsStringIn
({
"NCHW"
,
"NHWC"
})
.
End
();
AddOpCompat
(
OpCompat
(
"elementwise_add"
))
.
AddInput
(
"X"
)
.
IsTensor
()
.
End
()
.
AddInput
(
"Y"
)
.
IsTensor
()
.
End
()
.
AddOutput
(
"Out"
)
.
IsTensor
()
.
End
()
.
AddAttr
(
"axis"
)
.
IsNumEQ
(
-
1
)
.
End
();
}
Conv2DTransposeBiasFusePass
::
Conv2DTransposeBiasFusePass
()
{
AddOpCompat
(
OpCompat
(
"conv2d_transpose"
))
.
AddInput
(
"Input"
)
.
IsTensor
()
.
End
()
.
AddInput
(
"Filter"
)
.
IsTensor
()
.
End
()
.
AddInput
(
"Bias"
)
.
IsTensor
()
.
End
()
.
AddOutput
(
"Output"
)
.
IsTensor
()
.
End
()
.
AddAttr
(
"output_padding"
)
.
End
()
.
AddAttr
(
"output_size"
)
.
IsNumGE
(
1
)
.
End
()
.
AddAttr
(
"groups"
)
.
IsNumGE
(
1
)
.
End
()
.
AddAttr
(
"dilations"
)
.
End
()
.
AddAttr
(
"strides"
)
.
End
()
.
AddAttr
(
"paddings"
)
.
End
()
.
AddAttr
(
"padding_algorithm"
)
.
IsStringIn
({
"EXPLICIT"
,
"SAME"
,
"VALID"
})
.
End
()
.
AddAttr
(
"data_format"
)
.
IsStringIn
({
"NCHW"
,
"NHWC"
})
.
End
();
AddOpCompat
(
OpCompat
(
"elementwise_add"
))
.
AddInput
(
"X"
)
.
IsTensor
()
.
End
()
.
AddInput
(
"Y"
)
.
IsTensor
()
.
End
()
.
AddOutput
(
"Out"
)
.
IsTensor
()
.
End
()
.
AddAttr
(
"axis"
)
.
IsNumEQ
(
-
1
)
.
End
();
}
template
<
typename
BinaryOperation
>
template
<
typename
BinaryOperation
>
LoDTensor
tensor_apply_eltwise
(
const
LoDTensor
&
vec_a
,
const
LoDTensor
&
vec_b
,
LoDTensor
tensor_apply_eltwise
(
const
LoDTensor
&
vec_a
,
const
LoDTensor
&
vec_b
,
BinaryOperation
f
)
{
BinaryOperation
f
)
{
...
@@ -80,6 +176,12 @@ void ConvBiasFusePass::ApplyImpl(ir::Graph* graph) const {
...
@@ -80,6 +176,12 @@ void ConvBiasFusePass::ApplyImpl(ir::Graph* graph) const {
subgraph
.
count
(
conv_input
),
0
,
subgraph
.
count
(
conv_input
),
0
,
platform
::
errors
::
NotFound
(
"Detector did not find conv input."
));
platform
::
errors
::
NotFound
(
"Detector did not find conv input."
));
// check compat
if
(
!
IsCompat
(
subgraph
,
g
))
{
VLOG
(
3
)
<<
"Pass in op compat failed."
;
return
;
}
// check if fuse can be done and if MKL-DNN should be used
// check if fuse can be done and if MKL-DNN should be used
FuseOptions
fuse_option
=
FindFuseOption
(
*
conv
,
*
eltwise
);
FuseOptions
fuse_option
=
FindFuseOption
(
*
conv
,
*
eltwise
);
if
(
fuse_option
==
DO_NOT_FUSE
||
fuse_option
==
FUSE_NATIVE
)
{
if
(
fuse_option
==
DO_NOT_FUSE
||
fuse_option
==
FUSE_NATIVE
)
{
...
...
paddle/fluid/framework/ir/mkldnn/conv_bias_mkldnn_fuse_pass.h
浏览文件 @
cf3ddd3b
...
@@ -29,6 +29,7 @@ class Graph;
...
@@ -29,6 +29,7 @@ class Graph;
class
ConvBiasFusePass
:
public
FusePassBase
{
class
ConvBiasFusePass
:
public
FusePassBase
{
public:
public:
ConvBiasFusePass
();
virtual
~
ConvBiasFusePass
()
{}
virtual
~
ConvBiasFusePass
()
{}
virtual
std
::
string
type
()
const
{
return
"conv2d"
;
}
virtual
std
::
string
type
()
const
{
return
"conv2d"
;
}
...
@@ -41,6 +42,7 @@ class ConvBiasFusePass : public FusePassBase {
...
@@ -41,6 +42,7 @@ class ConvBiasFusePass : public FusePassBase {
*/
*/
class
Conv2DTransposeBiasFusePass
:
public
ConvBiasFusePass
{
class
Conv2DTransposeBiasFusePass
:
public
ConvBiasFusePass
{
public:
public:
Conv2DTransposeBiasFusePass
();
std
::
string
type
()
const
override
{
return
"conv2d_transpose"
;
}
std
::
string
type
()
const
override
{
return
"conv2d_transpose"
;
}
};
};
...
...
paddle/fluid/framework/ir/mkldnn/conv_bias_mkldnn_fuse_pass_tester.cc
浏览文件 @
cf3ddd3b
...
@@ -31,8 +31,19 @@ void SetOp(ProgramDesc* prog, const std::string& type, const std::string& name,
...
@@ -31,8 +31,19 @@ void SetOp(ProgramDesc* prog, const std::string& type, const std::string& name,
auto
*
op
=
prog
->
MutableBlock
(
0
)
->
AppendOp
();
auto
*
op
=
prog
->
MutableBlock
(
0
)
->
AppendOp
();
op
->
SetType
(
type
);
op
->
SetType
(
type
);
if
(
type
==
"conv2d"
)
{
if
(
type
==
"conv2d"
)
{
const
std
::
vector
<
int
>
strides
({
1
,
1
});
const
std
::
vector
<
int
>
paddings
({
0
,
0
});
const
std
::
vector
<
int
>
dilations
({
1
,
1
});
op
->
SetAttr
(
"use_mkldnn"
,
true
);
op
->
SetAttr
(
"use_mkldnn"
,
true
);
op
->
SetAttr
(
"name"
,
name
);
op
->
SetAttr
(
"name"
,
name
);
op
->
SetAttr
(
"strides"
,
strides
);
op
->
SetAttr
(
"groups"
,
1
);
op
->
SetAttr
(
"paddings"
,
paddings
);
op
->
SetAttr
(
"padding_algorithm"
,
std
::
string
(
"EXPLICIT"
));
op
->
SetAttr
(
"dilations"
,
dilations
);
op
->
SetAttr
(
"data_format"
,
std
::
string
(
"NCHW"
));
op
->
SetOutput
(
"Output"
,
outputs
);
op
->
SetInput
(
"Input"
,
{
inputs
[
0
]});
op
->
SetInput
(
"Input"
,
{
inputs
[
0
]});
op
->
SetInput
(
"Filter"
,
{
inputs
[
1
]});
op
->
SetInput
(
"Filter"
,
{
inputs
[
1
]});
if
(
inputs
.
size
()
>
2
)
if
(
inputs
.
size
()
>
2
)
...
@@ -41,10 +52,11 @@ void SetOp(ProgramDesc* prog, const std::string& type, const std::string& name,
...
@@ -41,10 +52,11 @@ void SetOp(ProgramDesc* prog, const std::string& type, const std::string& name,
op
->
SetInput
(
"Bias"
,
{});
op
->
SetInput
(
"Bias"
,
{});
}
else
if
(
type
==
"elementwise_add"
)
{
}
else
if
(
type
==
"elementwise_add"
)
{
op
->
SetAttr
(
"use_mkldnn"
,
true
);
op
->
SetAttr
(
"use_mkldnn"
,
true
);
op
->
SetAttr
(
"axis"
,
-
1
);
op
->
SetInput
(
"X"
,
{
inputs
[
0
]});
op
->
SetInput
(
"X"
,
{
inputs
[
0
]});
op
->
SetInput
(
"Y"
,
{
inputs
[
1
]});
op
->
SetInput
(
"Y"
,
{
inputs
[
1
]});
op
->
SetOutput
(
"Out"
,
outputs
);
}
}
op
->
SetOutput
(
"Out"
,
outputs
);
op
->
SetAttr
(
OpProtoAndCheckerMaker
::
OpRoleAttrName
(),
op
->
SetAttr
(
OpProtoAndCheckerMaker
::
OpRoleAttrName
(),
static_cast
<
int
>
(
OpRole
::
kForward
));
static_cast
<
int
>
(
OpRole
::
kForward
));
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录