Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
331aaecd
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
331aaecd
编写于
3月 03, 2020
作者:
H
hong19860320
提交者:
GitHub
3月 03, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Core] Fix memory_optmize_pass for reshape/reshape2 op with inplace=True (#3045)
上级
6c90792b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
64 addition
and
37 deletion
+64
-37
lite/core/mir/memory_optimize_pass.cc
lite/core/mir/memory_optimize_pass.cc
+64
-37
未找到文件。
lite/core/mir/memory_optimize_pass.cc
浏览文件 @
331aaecd
...
...
@@ -39,52 +39,79 @@ void MemoryOptimizePass::CollectLifeCycleByDevice(
auto
is_host
=
[](
TargetType
x
)
->
bool
{
return
x
==
TARGET
(
kHost
)
||
x
==
TARGET
(
kX86
)
||
x
==
TARGET
(
kARM
);
};
// The vars which inputs or outputs are invalid op will not be reused.
auto
valid_var
=
[
&
](
Node
*
node
)
->
bool
{
std
::
set
<
std
::
string
>
invalid_op
=
{
"while"
,
"conditional_block"
,
"conditional_block_infer"
,
"merge_lod_tensor_infer"
,
"merge_lod_tensor"
,
"equal"
,
"lod_reset"
,
"concat"
,
"yolo_box"
,
"subgraph"
,
"feed"
,
"fetch"
};
for
(
auto
*
tmp
:
node
->
inlinks
)
{
CHECK
(
tmp
->
IsStmt
());
std
::
string
op_type
=
tmp
->
AsStmt
().
op_info
()
->
Type
();
if
(
std
::
find
(
invalid_op
.
begin
(),
invalid_op
.
end
(),
op_type
)
!=
invalid_op
.
end
())
{
return
false
;
// Collect the invalid input and output variables that will not be reused.
std
::
unordered_set
<
std
::
string
>
invalid_var_names
;
for
(
auto
&
op_node
:
graph
->
StmtTopologicalOrder
())
{
if
(
!
op_node
->
IsStmt
())
continue
;
auto
op_info
=
op_node
->
AsStmt
().
op_info
();
auto
op_type
=
op_info
->
Type
();
// The all of input and output variables of the Ops will not be reused.
std
::
unordered_set
<
std
::
string
>
invalid_op_nodes
=
{
"while"
,
"conditional_block"
,
"conditional_block_infer"
,
"merge_lod_tensor_infer"
,
"merge_lod_tensor"
,
"equal"
,
"lod_reset"
,
"concat"
,
"yolo_box"
,
"subgraph"
,
"feed"
,
"fetch"
};
auto
invalid_op_node
=
invalid_op_nodes
.
find
(
op_type
);
if
(
invalid_op_node
!=
invalid_op_nodes
.
end
())
{
for
(
auto
in_var_node
:
op_node
->
inlinks
)
{
CHECK
(
in_var_node
->
IsArg
());
invalid_var_names
.
insert
(
in_var_node
->
AsArg
().
name
);
}
for
(
auto
out_var_node
:
op_node
->
outlinks
)
{
CHECK
(
out_var_node
->
IsArg
());
invalid_var_names
.
insert
(
out_var_node
->
AsArg
().
name
);
}
continue
;
}
for
(
auto
*
tmp
:
node
->
outlinks
)
{
CHECK
(
tmp
->
IsStmt
());
std
::
string
op_type
=
tmp
->
AsStmt
().
op_info
()
->
Type
();
if
(
std
::
find
(
invalid_op
.
begin
(),
invalid_op
.
end
(),
op_type
)
!=
invalid_op
.
end
())
{
return
false
;
// The specified input and output variables of the Ops whose 'inplace' attr
// is true will not be reused, such as reshape/reshape2's X and Out
// variables
std
::
unordered_map
<
std
::
string
,
std
::
pair
<
std
::
unordered_set
<
std
::
string
>
,
std
::
unordered_set
<
std
::
string
>>>
inplace_op_nodes
=
{{
"reshape"
,
{{
"X"
},
{
"Out"
}}},
{
"reshape2"
,
{{
"X"
},
{
"Out"
}}}};
auto
inplace_op_node
=
inplace_op_nodes
.
find
(
op_type
);
if
(
inplace_op_node
!=
inplace_op_nodes
.
end
())
{
bool
inplace
=
false
;
if
(
op_info
->
HasAttr
(
"inplace"
))
{
inplace
=
op_info
->
GetAttr
<
bool
>
(
"inplace"
);
}
if
(
inplace
)
{
for
(
auto
&
in_param_name
:
inplace_op_node
->
second
.
first
)
{
const
auto
&
in_arg_names
=
op_info
->
Input
(
in_param_name
);
invalid_var_names
.
insert
(
in_arg_names
.
begin
(),
in_arg_names
.
end
());
}
for
(
auto
&
out_param_name
:
inplace_op_node
->
second
.
second
)
{
const
auto
&
out_arg_names
=
op_info
->
Output
(
out_param_name
);
invalid_var_names
.
insert
(
out_arg_names
.
begin
(),
out_arg_names
.
end
());
}
}
}
return
true
;
};
}
for
(
auto
&
op_node
:
graph
->
StmtTopologicalOrder
())
{
if
(
op_node
->
IsStmt
())
{
auto
inputs
=
op_node
->
inlinks
;
auto
outputs
=
op_node
->
outlinks
;
std
::
vector
<
Node
*>
requires
(
inputs
.
begin
(),
inputs
.
end
());
requires
.
insert
(
requires
.
end
(),
outputs
.
begin
(),
output
s
.
end
());
for
(
Node
*
node
:
requir
es
)
{
CHECK
(
node
->
IsArg
());
auto
&
arg
=
node
->
AsArg
();
std
::
vector
<
Node
*>
var_nodes
(
op_node
->
inlinks
.
begin
(),
op_node
->
inlinks
.
end
())
;
var_nodes
.
insert
(
var_nodes
.
end
(),
op_node
->
outlinks
.
begin
(),
op_node
->
outlink
s
.
end
());
for
(
auto
*
var_node
:
var_nod
es
)
{
CHECK
(
var_
node
->
IsArg
());
auto
&
arg
=
var_
node
->
AsArg
();
if
(
arg
.
is_weight
||
arg
.
is_persist
)
continue
;
if
(
!
valid_var
(
node
))
continue
;
std
::
string
var_name
=
arg
.
name
;
TargetType
target_type
=
node
->
AsArg
().
type
->
target
();
if
(
invalid_var_names
.
count
(
var_name
))
continue
;
TargetType
target_type
=
arg
.
type
->
target
();
if
(
is_host
(
target_type
))
target_type
=
TARGET
(
kHost
);
if
(
!
(
*
lifecycles
)[
TargetToStr
(
target_type
)].
count
(
var_name
))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录