Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
5f6d8ce6
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
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看板
未验证
提交
5f6d8ce6
编写于
8月 17, 2020
作者:
myq406450149
提交者:
GitHub
8月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add reshape pass. test=develop (#4073)
上级
d9c72521
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
191 addition
and
0 deletion
+191
-0
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/reshape_fuse_pass.cc
lite/core/mir/fusion/reshape_fuse_pass.cc
+43
-0
lite/core/mir/fusion/reshape_fuse_pass.h
lite/core/mir/fusion/reshape_fuse_pass.h
+32
-0
lite/core/mir/fusion/reshape_fuser.cc
lite/core/mir/fusion/reshape_fuser.cc
+59
-0
lite/core/mir/fusion/reshape_fuser.h
lite/core/mir/fusion/reshape_fuser.h
+50
-0
lite/core/optimizer.h
lite/core/optimizer.h
+1
-0
未找到文件。
lite/api/paddle_use_passes.h
浏览文件 @
5f6d8ce6
...
@@ -48,6 +48,7 @@ USE_MIR_PASS(type_precision_cast_pass);
...
@@ -48,6 +48,7 @@ USE_MIR_PASS(type_precision_cast_pass);
USE_MIR_PASS
(
type_layout_cast_pass
);
USE_MIR_PASS
(
type_layout_cast_pass
);
USE_MIR_PASS
(
type_layout_cast_preprocess_pass
);
USE_MIR_PASS
(
type_layout_cast_preprocess_pass
);
USE_MIR_PASS
(
memory_optimize_pass
);
USE_MIR_PASS
(
memory_optimize_pass
);
USE_MIR_PASS
(
lite_reshape_fuse_pass
);
USE_MIR_PASS
(
multi_stream_analysis_pass
);
USE_MIR_PASS
(
multi_stream_analysis_pass
);
USE_MIR_PASS
(
elementwise_mul_constant_eliminate_pass
)
USE_MIR_PASS
(
elementwise_mul_constant_eliminate_pass
)
USE_MIR_PASS
(
npu_subgraph_pass
);
USE_MIR_PASS
(
npu_subgraph_pass
);
...
...
lite/core/mir/CMakeLists.txt
浏览文件 @
5f6d8ce6
...
@@ -23,6 +23,7 @@ lite_cc_library(mir_passes
...
@@ -23,6 +23,7 @@ lite_cc_library(mir_passes
fusion/quant_dequant_fuse_pass.cc
fusion/quant_dequant_fuse_pass.cc
fusion/sequence_pool_concat_fuse_pass.cc
fusion/sequence_pool_concat_fuse_pass.cc
fusion/scale_activation_fuse_pass.cc
fusion/scale_activation_fuse_pass.cc
fusion/reshape_fuse_pass.cc
fusion/__xpu__resnet_fuse_pass.cc
fusion/__xpu__resnet_fuse_pass.cc
fusion/__xpu__resnet_cbam_fuse_pass.cc
fusion/__xpu__resnet_cbam_fuse_pass.cc
fusion/__xpu__multi_encoder_fuse_pass.cc
fusion/__xpu__multi_encoder_fuse_pass.cc
...
...
lite/core/mir/fusion/CMakeLists.txt
浏览文件 @
5f6d8ce6
...
@@ -37,6 +37,9 @@ lite_cc_library(fuse_sequence_pool_concat
...
@@ -37,6 +37,9 @@ lite_cc_library(fuse_sequence_pool_concat
lite_cc_library
(
fuse_scale_activation
lite_cc_library
(
fuse_scale_activation
SRCS scale_activation_fuser.cc
SRCS scale_activation_fuser.cc
DEPS pattern_matcher_high_api
)
DEPS pattern_matcher_high_api
)
lite_cc_library
(
fuse_reshape
SRCS reshape_fuser.cc
DEPS pattern_matcher_high_api
)
lite_cc_library
(
fuse_match_matrix_activation
lite_cc_library
(
fuse_match_matrix_activation
SRCS match_matrix_activation_fuser.cc
SRCS match_matrix_activation_fuser.cc
DEPS pattern_matcher_high_api
)
DEPS pattern_matcher_high_api
)
...
@@ -61,6 +64,7 @@ set(mir_fusers
...
@@ -61,6 +64,7 @@ set(mir_fusers
fuse_interpolate
fuse_interpolate
fuse_sequence_pool_concat
fuse_sequence_pool_concat
fuse_scale_activation
fuse_scale_activation
fuse_reshape
fuse_match_matrix_activation
fuse_match_matrix_activation
fuse_scales
fuse_scales
fuse_sequence_reverse_embedding
fuse_sequence_reverse_embedding
...
...
lite/core/mir/fusion/reshape_fuse_pass.cc
0 → 100644
浏览文件 @
5f6d8ce6
// 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/reshape_fuse_pass.h"
#include <memory>
#include <vector>
#include "lite/core/mir/fusion/reshape_fuser.h"
#include "lite/core/mir/pass_registry.h"
namespace
paddle
{
namespace
lite
{
namespace
mir
{
void
ReshapeFusePass
::
Apply
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
)
{
std
::
vector
<
std
::
string
>
reshape_type_cases
{
"reshape"
,
"reshape2"
};
for
(
auto
type_
:
reshape_type_cases
)
{
fusion
::
ReshapeFuser
reshape_fuser
(
type_
);
reshape_fuser
(
graph
.
get
());
}
for
(
auto
type_
:
reshape_type_cases
)
{
fusion
::
Reshape2OutFuser
reshape2Out_fuser
(
type_
);
reshape2Out_fuser
(
graph
.
get
());
}
}
}
// namespace mir
}
// namespace lite
}
// namespace paddle
REGISTER_MIR_PASS
(
lite_reshape_fuse_pass
,
paddle
::
lite
::
mir
::
ReshapeFusePass
)
.
BindTargets
({
TARGET
(
kAny
)});
lite/core/mir/fusion/reshape_fuse_pass.h
0 → 100644
浏览文件 @
5f6d8ce6
// 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
ReshapeFusePass
:
public
ProgramPass
{
public:
void
Apply
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
)
override
;
};
}
// namespace mir
}
// namespace lite
}
// namespace paddle
lite/core/mir/fusion/reshape_fuser.cc
0 → 100644
浏览文件 @
5f6d8ce6
// 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/reshape_fuser.h"
#include <memory>
#include <vector>
namespace
paddle
{
namespace
lite
{
namespace
mir
{
namespace
fusion
{
void
ReshapeFuser
::
BuildPattern
()
{
auto
*
x
=
VarNode
(
"x"
);
auto
*
reshape
=
OpNode
(
"reshape"
,
type_
);
auto
*
reshape_out
=
VarNode
(
"Out"
);
auto
*
out1
=
OpNode
(
"out1"
);
*
x
>>
*
reshape
>>
*
reshape_out
>>
*
out1
;
}
void
ReshapeFuser
::
InsertNewNode
(
SSAGraph
*
graph
,
const
key2nodes_t
&
matched
)
{
auto
op_desc
=
const_cast
<
OpInfo
*>
(
matched
.
at
(
"reshape"
)
->
stmt
()
->
op_info
());
op_desc
->
SetAttr
<
bool
>
(
"inplace"
,
true
);
}
void
Reshape2OutFuser
::
BuildPattern
()
{
auto
*
x
=
VarNode
(
"x"
);
auto
*
reshape
=
OpNode
(
"reshape"
,
type_
)
->
assert_op_attr
<
bool
>
(
"inplace"
,
true
);
auto
*
reshape_out
=
VarNode
(
"Out"
);
auto
*
out1
=
OpNode
(
"out1"
);
auto
*
out2
=
OpNode
(
"out2"
);
*
x
>>
*
reshape
>>
*
reshape_out
>>
*
out1
;
*
reshape_out
>>
*
out2
;
}
void
Reshape2OutFuser
::
InsertNewNode
(
SSAGraph
*
graph
,
const
key2nodes_t
&
matched
)
{
auto
op_desc
=
const_cast
<
OpInfo
*>
(
matched
.
at
(
"reshape"
)
->
stmt
()
->
op_info
());
op_desc
->
SetAttr
<
bool
>
(
"inplace"
,
false
);
}
}
// namespace fusion
}
// namespace mir
}
// namespace lite
}
// namespace paddle
lite/core/mir/fusion/reshape_fuser.h
0 → 100644
浏览文件 @
5f6d8ce6
// 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
ReshapeFuser
:
public
FuseBase
{
public:
explicit
ReshapeFuser
(
const
std
::
string
&
type
)
:
type_
(
type
)
{}
void
BuildPattern
()
override
;
void
InsertNewNode
(
SSAGraph
*
graph
,
const
key2nodes_t
&
matched
)
override
;
private:
std
::
string
type_
;
};
class
Reshape2OutFuser
:
public
FuseBase
{
public:
explicit
Reshape2OutFuser
(
const
std
::
string
&
type
)
:
type_
(
type
)
{}
void
BuildPattern
()
override
;
void
InsertNewNode
(
SSAGraph
*
graph
,
const
key2nodes_t
&
matched
)
override
;
private:
std
::
string
type_
;
};
}
// namespace fusion
}
// namespace mir
}
// namespace lite
}
// namespace paddle
lite/core/optimizer.h
浏览文件 @
5f6d8ce6
...
@@ -164,6 +164,7 @@ class Optimizer {
...
@@ -164,6 +164,7 @@ class Optimizer {
"runtime_context_assign_pass"
,
"runtime_context_assign_pass"
,
"argument_type_display_pass"
,
"argument_type_display_pass"
,
"lite_reshape_fuse_pass"
,
"memory_optimize_pass"
}};
"memory_optimize_pass"
}};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录