Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
660e4106
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
660e4106
编写于
2月 25, 2019
作者:
D
dzhwinter
提交者:
GitHub
2月 25, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15855 from dzhwinter/fix/nightly_test
accelerate memory optimize process
上级
4bd28b30
a71f2fbe
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
47 addition
and
16 deletion
+47
-16
paddle/fluid/framework/details/memory_optimize_helper.cc
paddle/fluid/framework/details/memory_optimize_helper.cc
+36
-5
paddle/fluid/framework/details/memory_optimize_helper.h
paddle/fluid/framework/details/memory_optimize_helper.h
+6
-4
paddle/fluid/framework/details/memory_optimize_pass.cc
paddle/fluid/framework/details/memory_optimize_pass.cc
+5
-7
未找到文件。
paddle/fluid/framework/details/memory_optimize_helper.cc
浏览文件 @
660e4106
...
...
@@ -461,11 +461,21 @@ void ControlFlowGraph::LiveVariableAnalysis() {
}
}
}
for
(
auto
*
op
:
ops_
)
{
unlived_vars_
[
op
]
=
std
::
set
<
std
::
string
>
();
for
(
auto
&
var
:
this
->
LiveIn
(
op
))
{
if
(
!
this
->
LiveOut
(
op
).
count
(
var
))
{
unlived_vars_
[
op
].
insert
(
var
);
}
}
}
}
void
ControlFlowGraph
::
RenameVarInCFGGraph
(
const
std
::
string
&
old_node
,
const
std
::
string
&
new_node
,
int
begin_idx
)
{
std
::
vector
<
bool
>
need_update
(
ops_
.
size
(),
false
);
// update graph from begin idx to the end
for
(
size_t
i
=
begin_idx
;
i
!=
ops_
.
size
();
++
i
)
{
auto
*
op
=
ops_
[
i
];
...
...
@@ -480,15 +490,27 @@ void ControlFlowGraph::RenameVarInCFGGraph(const std::string& old_node,
if
(
live_in_
[
op
].
find
(
old_node
)
!=
live_in_
[
op
].
end
())
{
live_in_
[
op
].
erase
(
old_node
);
live_in_
[
op
].
insert
(
new_node
);
need_update
[
i
]
=
true
;
}
if
(
live_out_
[
op
].
find
(
old_node
)
!=
live_out_
[
op
].
end
())
{
live_out_
[
op
].
erase
(
old_node
);
live_out_
[
op
].
insert
(
new_node
);
need_update
[
i
]
=
true
;
}
}
for
(
size_t
i
=
begin_idx
;
i
<
ops_
.
size
();
++
i
)
{
if
(
!
need_update
[
i
])
continue
;
auto
*
op
=
ops_
[
i
];
for
(
auto
&
var
:
this
->
LiveIn
(
op
))
{
if
(
!
this
->
LiveOut
(
op
).
count
(
var
))
{
unlived_vars_
[
op
].
insert
(
var
);
}
}
}
}
const
std
::
set
<
std
::
string
>
ControlFlowGraph
::
LiveIn
(
ir
::
Node
*
op
)
const
{
const
std
::
set
<
std
::
string
>
&
ControlFlowGraph
::
LiveIn
(
ir
::
Node
*
op
)
const
{
auto
it
=
live_in_
.
find
(
op
);
PADDLE_ENFORCE
(
it
!=
live_in_
.
end
(),
...
...
@@ -496,7 +518,7 @@ const std::set<std::string> ControlFlowGraph::LiveIn(ir::Node* op) const {
return
it
->
second
;
}
const
std
::
set
<
std
::
string
>
ControlFlowGraph
::
LiveOut
(
ir
::
Node
*
op
)
const
{
const
std
::
set
<
std
::
string
>
&
ControlFlowGraph
::
LiveOut
(
ir
::
Node
*
op
)
const
{
auto
it
=
live_out_
.
find
(
op
);
PADDLE_ENFORCE
(
it
!=
live_out_
.
end
(),
...
...
@@ -504,15 +526,24 @@ const std::set<std::string> ControlFlowGraph::LiveOut(ir::Node* op) const {
return
it
->
second
;
}
const
std
::
set
<
std
::
string
>
ControlFlowGraph
::
Use
(
ir
::
Node
*
op
)
const
{
const
std
::
set
<
std
::
string
>
&
ControlFlowGraph
::
Use
(
ir
::
Node
*
op
)
const
{
auto
it
=
uses_
.
find
(
op
);
PADDLE_ENFORCE
(
it
!=
uses_
.
end
(),
string
::
Sprintf
(
"Expect %s in live_out, but Not Found."
,
op
->
Name
()));
string
::
Sprintf
(
"Expect %s in use, but Not Found."
,
op
->
Name
()));
return
it
->
second
;
}
const
std
::
set
<
std
::
string
>&
ControlFlowGraph
::
Unlived
(
ir
::
Node
*
op
)
const
{
auto
it
=
unlived_vars_
.
find
(
op
);
PADDLE_ENFORCE
(
it
!=
unlived_vars_
.
end
(),
string
::
Sprintf
(
"Expect %s in unlived_set, but Not Found."
,
op
->
Name
()));
return
it
->
second
;
return
it
->
second
;
}
const
std
::
vector
<
ir
::
Node
*>
ControlFlowGraph
::
Ops
()
const
{
return
ops_
;
}
const
std
::
vector
<
ir
::
Node
*>
&
ControlFlowGraph
::
Ops
()
const
{
return
ops_
;
}
std
::
vector
<
ir
::
Node
*>&
ControlFlowGraph
::
Ops
()
{
return
ops_
;
}
...
...
paddle/fluid/framework/details/memory_optimize_helper.h
浏览文件 @
660e4106
...
...
@@ -92,10 +92,11 @@ class ControlFlowGraph {
void
RenameVarInCFGGraph
(
const
std
::
string
&
old_node
,
const
std
::
string
&
new_node
,
int
begin_idx
);
const
std
::
set
<
std
::
string
>
LiveIn
(
ir
::
Node
*
op
)
const
;
const
std
::
set
<
std
::
string
>
LiveOut
(
ir
::
Node
*
op
)
const
;
const
std
::
set
<
std
::
string
>
Use
(
ir
::
Node
*
op
)
const
;
const
std
::
vector
<
ir
::
Node
*>
Ops
()
const
;
const
std
::
set
<
std
::
string
>&
LiveIn
(
ir
::
Node
*
op
)
const
;
const
std
::
set
<
std
::
string
>&
LiveOut
(
ir
::
Node
*
op
)
const
;
const
std
::
set
<
std
::
string
>&
Use
(
ir
::
Node
*
op
)
const
;
const
std
::
set
<
std
::
string
>&
Unlived
(
ir
::
Node
*
op
)
const
;
const
std
::
vector
<
ir
::
Node
*>&
Ops
()
const
;
std
::
vector
<
ir
::
Node
*>&
Ops
();
// for ssa-graph nodes
...
...
@@ -117,6 +118,7 @@ class ControlFlowGraph {
VarSetMap
live_out_
;
VarSetMap
uses_
;
// op inputs
VarSetMap
defs_
;
// op outputs
std
::
unordered_map
<
ir
::
Node
*
,
std
::
set
<
std
::
string
>>
unlived_vars_
;
std
::
vector
<
ir
::
Node
*>
ops_
;
// op sequence by topology sort
};
...
...
paddle/fluid/framework/details/memory_optimize_pass.cc
浏览文件 @
660e4106
...
...
@@ -118,13 +118,11 @@ std::unique_ptr<ir::Graph> MemoryOptimizePass::ApplyImpl(
}
}
// fill the pool
for
(
auto
var
:
cfg_
->
LiveIn
(
op
))
{
if
(
cfg_
->
LiveOut
(
op
).
count
(
var
)
==
0
)
{
ir
::
Node
*
var_node
=
cfg_
->
GetNodeByName
(
var
,
op
);
if
(
var_node
==
nullptr
||
var_node
->
IsCtrlVar
())
continue
;
if
(
NodeCanReused
(
var_node
)
&&
!
pool_
.
Has
(
var_node
))
{
pool_
.
Insert
(
var_node
);
}
for
(
auto
&
var
:
cfg_
->
Unlived
(
op
))
{
ir
::
Node
*
var_node
=
cfg_
->
GetNodeByName
(
var
,
op
);
if
(
var_node
==
nullptr
||
var_node
->
IsCtrlVar
())
continue
;
if
(
NodeCanReused
(
var_node
)
&&
!
pool_
.
Has
(
var_node
))
{
pool_
.
Insert
(
var_node
);
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录