Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
1ec18e53
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
332
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
1ec18e53
编写于
8月 23, 2019
作者:
T
tensor-tang
提交者:
GitHub
8月 23, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enable shuffle channel fuse (#1834)
test=develop
上级
6fc8574a
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
235 addition
and
2 deletion
+235
-2
lite/api/paddle_use_passes.h
lite/api/paddle_use_passes.h
+1
-0
lite/core/mir/CMakeLists.txt
lite/core/mir/CMakeLists.txt
+1
-0
lite/core/mir/fusion/CMakeLists.txt
lite/core/mir/fusion/CMakeLists.txt
+4
-0
lite/core/mir/fusion/shuffle_channel_fuse_pass.cc
lite/core/mir/fusion/shuffle_channel_fuse_pass.cc
+38
-0
lite/core/mir/fusion/shuffle_channel_fuse_pass.h
lite/core/mir/fusion/shuffle_channel_fuse_pass.h
+32
-0
lite/core/mir/fusion/shuffle_channel_fuser.cc
lite/core/mir/fusion/shuffle_channel_fuser.cc
+104
-0
lite/core/mir/fusion/shuffle_channel_fuser.h
lite/core/mir/fusion/shuffle_channel_fuser.h
+44
-0
lite/core/mir/pattern_matcher.h
lite/core/mir/pattern_matcher.h
+10
-2
lite/core/optimizer.h
lite/core/optimizer.h
+1
-0
未找到文件。
lite/api/paddle_use_passes.h
浏览文件 @
1ec18e53
...
...
@@ -29,6 +29,7 @@ USE_MIR_PASS(graph_visualze);
USE_MIR_PASS
(
lite_conv_bn_fuse_pass
);
USE_MIR_PASS
(
lite_fc_fuse_pass
);
USE_MIR_PASS
(
lite_shuffle_channel_fuse_pass
);
USE_MIR_PASS
(
identity_scale_eliminate_pass
);
USE_MIR_PASS
(
lite_conv_elementwise_fuse_pass
);
USE_MIR_PASS
(
lite_conv_activation_fuse_pass
);
...
...
lite/core/mir/CMakeLists.txt
浏览文件 @
1ec18e53
...
...
@@ -11,6 +11,7 @@ add_subdirectory(subgraph)
lite_cc_library
(
mir_passes
SRCS
fusion/fc_fuse_pass.cc
fusion/shuffle_channel_fuse_pass.cc
fusion/conv_elementwise_fuse_pass.cc
fusion/conv_activation_fuse_pass.cc
fusion/conv_bn_fuse_pass.cc
...
...
lite/core/mir/fusion/CMakeLists.txt
浏览文件 @
1ec18e53
lite_cc_library
(
fuse_fc
SRCS fc_fuser.cc
DEPS pattern_matcher_high_api
)
lite_cc_library
(
fuse_shuffle_channel
SRCS shuffle_channel_fuser.cc
DEPS pattern_matcher_high_api
)
lite_cc_library
(
fuse_conv_elementwise
SRCS conv_elementwise_fuser.cc
DEPS pattern_matcher_high_api
)
...
...
@@ -19,6 +22,7 @@ lite_cc_library(fuse_quant_dequant
set
(
mir_fusers
fuse_fc
fuse_shuffle_channel
fuse_conv_elementwise
fuse_conv_activation
fuse_conv_bn
...
...
lite/core/mir/fusion/shuffle_channel_fuse_pass.cc
0 → 100644
浏览文件 @
1ec18e53
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "lite/core/mir/fusion/shuffle_channel_fuse_pass.h"
#include <memory>
#include <vector>
#include "lite/core/mir/fusion/shuffle_channel_fuser.h"
#include "lite/core/mir/pass_registry.h"
namespace
paddle
{
namespace
lite
{
namespace
mir
{
void
ShuffleChannelFusePass
::
Apply
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
)
{
fusion
::
ShuffleChannelFuser
fuser
(
"reshape"
,
"transpose"
);
fuser
(
graph
.
get
());
fusion
::
ShuffleChannelFuser
fuser2
(
"reshape2"
,
"transpose2"
);
fuser2
(
graph
.
get
());
}
}
// namespace mir
}
// namespace lite
}
// namespace paddle
REGISTER_MIR_PASS
(
lite_shuffle_channel_fuse_pass
,
paddle
::
lite
::
mir
::
ShuffleChannelFusePass
);
lite/core/mir/fusion/shuffle_channel_fuse_pass.h
0 → 100644
浏览文件 @
1ec18e53
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <memory>
#include <string>
#include "lite/core/mir/pass.h"
namespace
paddle
{
namespace
lite
{
namespace
mir
{
class
ShuffleChannelFusePass
:
public
ProgramPass
{
public:
void
Apply
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
)
override
;
};
}
// namespace mir
}
// namespace lite
}
// namespace paddle
lite/core/mir/fusion/shuffle_channel_fuser.cc
0 → 100644
浏览文件 @
1ec18e53
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "lite/core/mir/fusion/shuffle_channel_fuser.h"
#include <memory>
#include <vector>
namespace
paddle
{
namespace
lite
{
namespace
mir
{
namespace
fusion
{
void
ShuffleChannelFuser
::
BuildPattern
()
{
// create nodes.
auto
*
x1
=
VarNode
(
"x1"
)
->
assert_is_op_input
(
reshape_type_
,
"X"
);
auto
*
y1
=
VarNode
(
"y1"
)
->
assert_is_op_output
(
reshape_type_
,
"Out"
);
auto
*
y2
=
VarNode
(
"y2"
)
->
assert_is_op_output
(
transpose_type_
,
"Out"
);
auto
*
out
=
VarNode
(
"out"
)
->
assert_is_op_output
(
reshape_type_
,
"Out"
);
auto
*
xshape1
=
VarNode
(
"xshape1"
)
->
assert_is_op_output
(
reshape_type_
,
"XShape"
);
auto
*
xshape2
=
VarNode
(
"xshape2"
)
->
assert_is_op_output
(
transpose_type_
,
"XShape"
);
auto
*
xshape3
=
VarNode
(
"xshape3"
)
->
assert_is_op_output
(
reshape_type_
,
"XShape"
);
auto
*
reshape1
=
OpNode
(
"reshape1"
,
reshape_type_
)
->
assert_op_attr_satisfied
<
std
::
vector
<
int
>>
(
"shape"
,
[](
const
std
::
vector
<
int
>&
attr
)
{
return
attr
.
size
()
>=
5
&&
attr
[
1
]
>
0
;
});
auto
*
transpose
=
OpNode
(
"transpose_op"
,
transpose_type_
)
->
assert_op_attr_satisfied
<
std
::
vector
<
int
>>
(
"axis"
,
[](
const
std
::
vector
<
int
>&
attr
)
{
return
attr
.
size
()
>=
5
&&
attr
[
1
]
==
2
&&
attr
[
2
]
==
1
;
});
auto
*
reshape2
=
OpNode
(
"reshape2"
,
reshape_type_
)
->
assert_op_attr_satisfied
<
std
::
vector
<
int
>>
(
"shape"
,
[](
const
std
::
vector
<
int
>&
attr
)
{
return
attr
.
size
()
>=
4
;
});
// create topology.
*
x1
>>
*
reshape1
>>
*
y1
>>
*
transpose
>>
*
y2
>>
*
reshape2
>>
*
out
;
*
reshape1
>>
*
xshape1
;
*
transpose
>>
*
xshape2
;
*
reshape2
>>
*
xshape3
;
// Some op specialities.
y1
->
AsIntermediate
();
y2
->
AsIntermediate
();
xshape1
->
AsIntermediate
();
xshape2
->
AsIntermediate
();
xshape3
->
AsIntermediate
();
reshape1
->
AsIntermediate
();
transpose
->
AsIntermediate
();
reshape2
->
AsIntermediate
();
}
void
ShuffleChannelFuser
::
InsertNewNode
(
SSAGraph
*
graph
,
const
key2nodes_t
&
matched
)
{
auto
op_desc
=
GenOpDesc
(
matched
);
auto
shuffle_channel_op
=
LiteOpRegistry
::
Global
().
Create
(
"shuffle_channel"
);
auto
transpose
=
matched
.
at
(
"transpose_op"
)
->
stmt
()
->
op
();
auto
*
scope
=
transpose
->
scope
();
auto
&
valid_places
=
transpose
->
valid_places
();
shuffle_channel_op
->
Attach
(
op_desc
,
scope
);
auto
*
new_op_node
=
graph
->
GraphCreateInstructNode
(
shuffle_channel_op
,
valid_places
);
IR_NODE_LINK_TO
(
matched
.
at
(
"x1"
),
new_op_node
);
IR_NODE_LINK_TO
(
new_op_node
,
matched
.
at
(
"out"
));
}
cpp
::
OpDesc
ShuffleChannelFuser
::
GenOpDesc
(
const
key2nodes_t
&
matched
)
{
cpp
::
OpDesc
op_desc
;
op_desc
.
SetType
(
"shuffle_channel"
);
op_desc
.
SetInput
(
"X"
,
{
matched
.
at
(
"x1"
)
->
arg
()
->
name
});
op_desc
.
SetOutput
(
"Out"
,
{
matched
.
at
(
"out"
)
->
arg
()
->
name
});
op_desc
.
SetAttr
(
"group"
,
matched
.
at
(
"reshape1"
)
->
stmt
()
->
op_info
()
->
GetAttr
<
std
::
vector
<
int
>>
(
"shape"
)[
1
]);
return
op_desc
;
}
}
// namespace fusion
}
// namespace mir
}
// namespace lite
}
// namespace paddle
lite/core/mir/fusion/shuffle_channel_fuser.h
0 → 100644
浏览文件 @
1ec18e53
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <memory>
#include <string>
#include "lite/core/mir/pattern_matcher_high_api.h"
namespace
paddle
{
namespace
lite
{
namespace
mir
{
namespace
fusion
{
class
ShuffleChannelFuser
:
public
FuseBase
{
public:
explicit
ShuffleChannelFuser
(
const
std
::
string
&
reshape_type
,
const
std
::
string
&
transpose_type
)
:
reshape_type_
(
reshape_type
),
transpose_type_
(
transpose_type
)
{}
void
BuildPattern
()
override
;
void
InsertNewNode
(
SSAGraph
*
graph
,
const
key2nodes_t
&
matched
)
override
;
private:
cpp
::
OpDesc
GenOpDesc
(
const
key2nodes_t
&
matched
)
override
;
std
::
string
reshape_type_
;
std
::
string
transpose_type_
;
};
}
// namespace fusion
}
// namespace mir
}
// namespace lite
}
// namespace paddle
lite/core/mir/pattern_matcher.h
浏览文件 @
1ec18e53
...
...
@@ -141,18 +141,26 @@ struct PMNode {
int
nth
);
template
<
typename
T
>
PMNode
*
assert_op_attr
(
const
std
::
string
&
attr_name
,
const
T
&
attr
)
{
PMNode
*
assert_op_attr_satisfied
(
const
std
::
string
&
attr_name
,
const
std
::
function
<
bool
(
const
T
&
)
>&
condition
)
{
asserts_
.
push_back
([
=
](
const
Node
*
x
)
{
if
(
x
&&
x
->
IsStmt
())
{
auto
*
op_info
=
x
->
stmt
()
->
op_info
();
return
op_info
->
HasAttr
(
attr_name
)
&&
op_info
->
GetAttr
<
T
>
(
attr_name
)
==
attr
;
condition
(
op_info
->
GetAttr
<
T
>
(
attr_name
))
;
}
return
false
;
});
return
this
;
}
template
<
typename
T
>
PMNode
*
assert_op_attr
(
const
std
::
string
&
attr_name
,
const
T
&
attr
)
{
return
assert_op_attr_satisfied
<
T
>
(
attr_name
,
[
&
](
const
T
&
src
)
{
return
src
==
attr
;
});
}
private:
PMNode
(
PMPattern
*
pattern
,
const
std
::
string
&
name
=
""
,
...
...
lite/core/optimizer.h
浏览文件 @
1ec18e53
...
...
@@ -64,6 +64,7 @@ class Optimizer {
"lite_conv_elementwise_fuse_pass"
,
//
"lite_conv_activation_fuse_pass"
,
//
"lite_fc_fuse_pass"
,
//
"lite_shuffle_channel_fuse_pass"
,
//
"identity_scale_eliminate_pass"
,
//
#ifdef LITE_WITH_LIGHT_WEIGHT_FRAMEWORK
"lite_elementwise_add_activation_fuse_pass"
,
//
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录