Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
161344bf
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
161344bf
编写于
4月 10, 2018
作者:
Y
Yu Yang
提交者:
GitHub
4月 10, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9774 from reyoung/feature/simplify_data_structures
Simplify DataStructure in SSAGraph
上级
0f38bb45
17bfe3f6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
36 addition
and
25 deletion
+36
-25
paddle/fluid/framework/details/multi_devices_graph_builder.cc
...le/fluid/framework/details/multi_devices_graph_builder.cc
+13
-8
paddle/fluid/framework/details/ssa_graph.h
paddle/fluid/framework/details/ssa_graph.h
+5
-1
paddle/fluid/framework/details/ssa_graph_builder.cc
paddle/fluid/framework/details/ssa_graph_builder.cc
+16
-14
paddle/fluid/framework/details/threaded_ssa_graph_executor.cc
...le/fluid/framework/details/threaded_ssa_graph_executor.cc
+2
-2
未找到文件。
paddle/fluid/framework/details/multi_devices_graph_builder.cc
浏览文件 @
161344bf
...
@@ -59,7 +59,11 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
...
@@ -59,7 +59,11 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
auto
graph
=
new
SSAGraph
();
auto
graph
=
new
SSAGraph
();
SSAGraph
&
result
=
*
graph
;
SSAGraph
&
result
=
*
graph
;
std
::
unordered_set
<
std
::
string
>
og_has_been_broadcast
;
std
::
unordered_set
<
std
::
string
>
og_has_been_broadcast
;
result
.
vars_
.
resize
(
places_
.
size
());
// We cannot invoke resize. It is a bug of GCC 4.8
result
.
vars_
=
std
::
vector
<
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
unique_ptr
<
VarHandle
>>>>
(
places_
.
size
());
bool
is_forwarding
=
true
;
bool
is_forwarding
=
true
;
for
(
auto
*
op
:
program
.
Block
(
0
).
AllOps
())
{
for
(
auto
*
op
:
program
.
Block
(
0
).
AllOps
())
{
...
@@ -147,15 +151,16 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
...
@@ -147,15 +151,16 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
if
(
vars
.
empty
())
{
// This device has no data. continue.
if
(
vars
.
empty
())
{
// This device has no data. continue.
continue
;
continue
;
}
}
auto
*
prev_grad
=
&
vars
[
vars
.
size
()
-
1
];
auto
&
prev_grad
=
vars
[
vars
.
size
()
-
1
];
op_handle
->
AddInput
(
prev_grad
);
op_handle
->
AddInput
(
prev_grad
.
get
()
);
auto
&
var
=
vars
[
vars
.
size
()];
vars
.
emplace_back
(
new
VarHandle
);
var
.
place_
=
p
;
auto
&
var
=
vars
.
back
();
var
.
name_
=
og
;
var
->
place_
=
p
;
var
.
version_
=
vars
.
size
()
-
1
;
var
->
name_
=
og
;
var
->
version_
=
vars
.
size
()
-
1
;
op_handle
->
AddOutput
(
&
var
);
op_handle
->
AddOutput
(
var
.
get
()
);
}
}
#else
#else
PADDLE_ENFORCE
(
"Not implemented"
);
PADDLE_ENFORCE
(
"Not implemented"
);
...
...
paddle/fluid/framework/details/ssa_graph.h
浏览文件 @
161344bf
...
@@ -16,6 +16,8 @@
...
@@ -16,6 +16,8 @@
#include <map>
#include <map>
#include <string>
#include <string>
#include <vector>
#include "paddle/fluid/framework/details/op_handle_base.h"
#include "paddle/fluid/framework/details/op_handle_base.h"
#include "paddle/fluid/framework/details/var_handle.h"
#include "paddle/fluid/framework/details/var_handle.h"
...
@@ -24,7 +26,9 @@ namespace framework {
...
@@ -24,7 +26,9 @@ namespace framework {
namespace
details
{
namespace
details
{
struct
SSAGraph
{
struct
SSAGraph
{
std
::
vector
<
std
::
unordered_map
<
std
::
string
,
std
::
map
<
int
,
VarHandle
>>>
vars_
;
std
::
vector
<
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
unique_ptr
<
VarHandle
>>>>
vars_
;
// aux variables to represent dependency. Useful to resolve data hazard.
// aux variables to represent dependency. Useful to resolve data hazard.
std
::
unordered_set
<
std
::
unique_ptr
<
VarHandleBase
>>
dep_vars_
;
std
::
unordered_set
<
std
::
unique_ptr
<
VarHandleBase
>>
dep_vars_
;
std
::
vector
<
std
::
unique_ptr
<
OpHandleBase
>>
ops_
;
std
::
vector
<
std
::
unique_ptr
<
OpHandleBase
>>
ops_
;
...
...
paddle/fluid/framework/details/ssa_graph_builder.cc
浏览文件 @
161344bf
...
@@ -27,8 +27,8 @@ void SSAGraphBuilder::PolishGraphToSupportDataHazards(SSAGraph *graph) {
...
@@ -27,8 +27,8 @@ void SSAGraphBuilder::PolishGraphToSupportDataHazards(SSAGraph *graph) {
auto
it_old
=
name_pair
.
second
.
rbegin
();
auto
it_old
=
name_pair
.
second
.
rbegin
();
++
it_old
;
++
it_old
;
for
(;
it_old
!=
name_pair
.
second
.
rend
();
it_new
=
it_old
,
++
it_old
)
{
for
(;
it_old
!=
name_pair
.
second
.
rend
();
it_new
=
it_old
,
++
it_old
)
{
auto
*
write_op
=
it_new
->
second
.
generated_op_
;
auto
*
write_op
=
(
*
it_new
)
->
generated_op_
;
auto
&
read_ops
=
it_old
->
second
.
pending_ops_
;
auto
&
read_ops
=
(
*
it_old
)
->
pending_ops_
;
for
(
auto
*
read_op
:
read_ops
)
{
for
(
auto
*
read_op
:
read_ops
)
{
// Manually add a dependency var from read_op to write_op;
// Manually add a dependency var from read_op to write_op;
...
@@ -54,14 +54,15 @@ VarHandle *SSAGraphBuilder::CreateOrGetLatestVarHandle(
...
@@ -54,14 +54,15 @@ VarHandle *SSAGraphBuilder::CreateOrGetLatestVarHandle(
auto
&
var_holder
=
var_holders
[
each_var_name
];
auto
&
var_holder
=
var_holders
[
each_var_name
];
VarHandle
*
var
=
nullptr
;
VarHandle
*
var
=
nullptr
;
if
(
var_holder
.
empty
())
{
if
(
var_holder
.
empty
())
{
var_holder
.
emplace_back
(
new
VarHandle
);
auto
&
init_var
=
var_holder
[
0
];
auto
&
init_var
=
var_holder
[
0
];
init_var
.
place_
=
place
;
init_var
->
place_
=
place
;
init_var
.
name_
=
each_var_name
;
init_var
->
name_
=
each_var_name
;
init_var
.
generated_op_
=
nullptr
;
init_var
->
generated_op_
=
nullptr
;
init_var
.
version_
=
0
;
init_var
->
version_
=
0
;
var
=
&
init_var
;
var
=
init_var
.
get
()
;
}
else
{
}
else
{
var
=
&
var_holder
.
rbegin
()
->
second
;
var
=
var_holder
.
rbegin
()
->
get
()
;
}
}
return
var
;
return
var
;
}
}
...
@@ -72,11 +73,12 @@ void SSAGraphBuilder::CreateOpOutput(SSAGraph *graph, OpHandleBase *op_handle,
...
@@ -72,11 +73,12 @@ void SSAGraphBuilder::CreateOpOutput(SSAGraph *graph, OpHandleBase *op_handle,
size_t
place_offset
)
{
size_t
place_offset
)
{
auto
&
vars
=
graph
->
vars_
[
place_offset
][
each_var_name
];
auto
&
vars
=
graph
->
vars_
[
place_offset
][
each_var_name
];
size_t
version
=
vars
.
size
();
size_t
version
=
vars
.
size
();
auto
&
var
=
vars
[
version
];
vars
.
emplace_back
(
new
VarHandle
());
var
.
version_
=
version
;
auto
&
var
=
vars
.
back
();
var
.
name_
=
each_var_name
;
var
->
version_
=
version
;
var
.
place_
=
place
;
var
->
name_
=
each_var_name
;
op_handle
->
AddOutput
(
&
var
);
var
->
place_
=
place
;
op_handle
->
AddOutput
(
var
.
get
());
}
}
template
<
typename
Callback
>
template
<
typename
Callback
>
...
@@ -84,7 +86,7 @@ void IterAllVar(const SSAGraph &graph, Callback callback) {
...
@@ -84,7 +86,7 @@ void IterAllVar(const SSAGraph &graph, Callback callback) {
for
(
auto
&
each
:
graph
.
vars_
)
{
for
(
auto
&
each
:
graph
.
vars_
)
{
for
(
auto
&
pair1
:
each
)
{
for
(
auto
&
pair1
:
each
)
{
for
(
auto
&
pair2
:
pair1
.
second
)
{
for
(
auto
&
pair2
:
pair1
.
second
)
{
callback
(
pair2
.
second
);
callback
(
*
pair2
);
}
}
}
}
}
}
...
...
paddle/fluid/framework/details/threaded_ssa_graph_executor.cc
浏览文件 @
161344bf
...
@@ -69,7 +69,7 @@ FeedFetchList ThreadedSSAGraphExecutor::Run(
...
@@ -69,7 +69,7 @@ FeedFetchList ThreadedSSAGraphExecutor::Run(
for
(
auto
&
var_map
:
graph_
->
vars_
)
{
for
(
auto
&
var_map
:
graph_
->
vars_
)
{
for
(
auto
&
name_pair
:
var_map
)
{
for
(
auto
&
name_pair
:
var_map
)
{
for
(
auto
&
version_pair
:
name_pair
.
second
)
{
for
(
auto
&
version_pair
:
name_pair
.
second
)
{
InsertPendingVar
(
version_pair
.
second
);
InsertPendingVar
(
*
version_pair
);
}
}
}
}
}
}
...
@@ -95,7 +95,7 @@ FeedFetchList ThreadedSSAGraphExecutor::Run(
...
@@ -95,7 +95,7 @@ FeedFetchList ThreadedSSAGraphExecutor::Run(
for
(
auto
&
var_map
:
graph_
->
vars_
)
{
for
(
auto
&
var_map
:
graph_
->
vars_
)
{
auto
it
=
var_map
.
find
(
fetch_var_name
);
auto
it
=
var_map
.
find
(
fetch_var_name
);
if
(
it
!=
var_map
.
end
())
{
if
(
it
!=
var_map
.
end
())
{
fetched_vars
[
fetch_var_name
].
push_back
(
&
it
->
second
.
rbegin
()
->
second
);
fetched_vars
[
fetch_var_name
].
push_back
(
it
->
second
.
rbegin
()
->
get
()
);
}
}
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录