Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wzpei9
Paddle
提交
68aa5004
P
Paddle
项目概览
wzpei9
/
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,发现更多精彩内容 >>
提交
68aa5004
编写于
7月 11, 2018
作者:
X
Xin Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
polish attrs
上级
9b960330
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
46 addition
and
68 deletion
+46
-68
paddle/fluid/framework/details/multi_devices_graph_builder.cc
...le/fluid/framework/details/multi_devices_graph_builder.cc
+2
-7
paddle/fluid/framework/details/multi_devices_graph_builder.h
paddle/fluid/framework/details/multi_devices_graph_builder.h
+1
-1
paddle/fluid/framework/details/ssa_graph_builder.h
paddle/fluid/framework/details/ssa_graph_builder.h
+1
-1
paddle/fluid/framework/details/ssa_graph_checker.cc
paddle/fluid/framework/details/ssa_graph_checker.cc
+4
-4
paddle/fluid/framework/details/ssa_graph_checker.h
paddle/fluid/framework/details/ssa_graph_checker.h
+2
-2
paddle/fluid/framework/details/ssa_graph_printer.cc
paddle/fluid/framework/details/ssa_graph_printer.cc
+5
-5
paddle/fluid/framework/details/ssa_graph_printer.h
paddle/fluid/framework/details/ssa_graph_printer.h
+3
-3
paddle/fluid/framework/ir/graph.h
paddle/fluid/framework/ir/graph.h
+17
-43
paddle/fluid/framework/parallel_executor.cc
paddle/fluid/framework/parallel_executor.cc
+11
-2
未找到文件。
paddle/fluid/framework/details/multi_devices_graph_builder.cc
浏览文件 @
68aa5004
...
...
@@ -167,7 +167,7 @@ size_t MultiDevSSAGraphBuilder::GetAppropriateDeviceID(
return
dev_id
;
}
std
::
unique_ptr
<
SSA
Graph
>
MultiDevSSAGraphBuilder
::
Build
(
std
::
unique_ptr
<
Graph
>
MultiDevSSAGraphBuilder
::
Build
(
const
ProgramDesc
&
program
)
const
{
std
::
unique_ptr
<
Graph
>
graph
(
new
Graph
);
for
(
auto
*
var
:
program
.
Block
(
0
).
AllVars
())
{
...
...
@@ -301,12 +301,7 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
* Only variables should be the leaves of graph.
*/
AddOutputToLeafOps
(
&
result
);
std
::
unique_ptr
<
SSAGraph
>
ssa_graph
(
new
SSAGraph
);
ssa_graph
->
vars_
=
std
::
move
(
*
graph
->
Erase
<
GraphVars
>
(
"vars"
));
ssa_graph
->
ops_
=
std
::
move
(
*
graph
->
Erase
<
GraphOps
>
(
"ops"
));
ssa_graph
->
dep_vars_
=
std
::
move
(
*
graph
->
Erase
<
GraphDepVars
>
(
"dep_vars"
));
return
std
::
move
(
ssa_graph
);
return
std
::
move
(
graph
);
}
bool
MultiDevSSAGraphBuilder
::
IsSparseGradient
(
const
std
::
string
&
og
)
const
{
...
...
paddle/fluid/framework/details/multi_devices_graph_builder.h
浏览文件 @
68aa5004
...
...
@@ -47,7 +47,7 @@ class MultiDevSSAGraphBuilder : public SSAGraphBuilder {
const
BuildStrategy
&
strategy
);
#endif
std
::
unique_ptr
<
SSA
Graph
>
Build
(
const
ProgramDesc
&
program
)
const
override
;
std
::
unique_ptr
<
Graph
>
Build
(
const
ProgramDesc
&
program
)
const
override
;
int
GetVarDeviceID
(
const
std
::
string
&
varname
)
const
override
;
private:
...
...
paddle/fluid/framework/details/ssa_graph_builder.h
浏览文件 @
68aa5004
...
...
@@ -38,7 +38,7 @@ class SSAGraphBuilder {
public:
SSAGraphBuilder
()
{}
virtual
~
SSAGraphBuilder
()
{}
virtual
std
::
unique_ptr
<
SSA
Graph
>
Build
(
const
ProgramDesc
&
program
)
const
=
0
;
virtual
std
::
unique_ptr
<
Graph
>
Build
(
const
ProgramDesc
&
program
)
const
=
0
;
virtual
int
GetVarDeviceID
(
const
std
::
string
&
var_name
)
const
=
0
;
DISABLE_COPY_AND_ASSIGN
(
SSAGraphBuilder
);
...
...
paddle/fluid/framework/details/ssa_graph_checker.cc
浏览文件 @
68aa5004
...
...
@@ -20,7 +20,7 @@ namespace paddle {
namespace
framework
{
namespace
details
{
bool
SSAGraghBuilderWithChecker
::
IsValidGraph
(
const
SSA
Graph
*
graph
)
const
{
bool
SSAGraghBuilderWithChecker
::
IsValidGraph
(
const
Graph
*
graph
)
const
{
std
::
unordered_map
<
OpHandleBase
*
,
size_t
>
pending_ops
;
std
::
unordered_set
<
VarHandleBase
*>
pending_vars
;
std
::
unordered_set
<
VarHandleBase
*>
ready_vars
;
...
...
@@ -33,7 +33,7 @@ bool SSAGraghBuilderWithChecker::IsValidGraph(const SSAGraph *graph) const {
}
};
for
(
auto
&
var_map
:
graph
->
vars_
)
{
for
(
auto
&
var_map
:
graph
->
Get
<
GraphVars
>
(
"vars"
)
)
{
for
(
auto
&
name_pair
:
var_map
)
{
for
(
auto
&
version_pair
:
name_pair
.
second
)
{
insert_pending_var
(
version_pair
.
get
());
...
...
@@ -41,11 +41,11 @@ bool SSAGraghBuilderWithChecker::IsValidGraph(const SSAGraph *graph) const {
}
}
for
(
auto
&
var
:
graph
->
dep_vars_
)
{
for
(
auto
&
var
:
graph
->
Get
<
GraphDepVars
>
(
"dep_vars"
)
)
{
insert_pending_var
(
var
.
get
());
}
for
(
auto
&
op
:
graph
->
ops_
)
{
for
(
auto
&
op
:
graph
->
Get
<
GraphOps
>
(
"ops"
)
)
{
if
(
op
->
Inputs
().
empty
())
{
ready_ops
.
insert
(
op
.
get
());
}
else
{
...
...
paddle/fluid/framework/details/ssa_graph_checker.h
浏览文件 @
68aa5004
...
...
@@ -29,7 +29,7 @@ class SSAGraghBuilderWithChecker : public SSAGraphBuilder {
std
::
unique_ptr
<
SSAGraphBuilder
>&&
builder
)
:
builder_
(
std
::
move
(
builder
))
{}
std
::
unique_ptr
<
SSA
Graph
>
Build
(
const
ProgramDesc
&
program
)
const
override
{
std
::
unique_ptr
<
Graph
>
Build
(
const
ProgramDesc
&
program
)
const
override
{
auto
graph
=
builder_
->
Build
(
program
);
PADDLE_ENFORCE
(
IsValidGraph
(
graph
.
get
()));
return
graph
;
...
...
@@ -39,7 +39,7 @@ class SSAGraghBuilderWithChecker : public SSAGraphBuilder {
return
builder_
->
GetVarDeviceID
(
var_name
);
}
bool
IsValidGraph
(
const
SSA
Graph
*
graph
)
const
;
bool
IsValidGraph
(
const
Graph
*
graph
)
const
;
private:
std
::
unique_ptr
<
SSAGraphBuilder
>
builder_
;
...
...
paddle/fluid/framework/details/ssa_graph_printer.cc
浏览文件 @
68aa5004
...
...
@@ -21,8 +21,8 @@ namespace framework {
namespace
details
{
template
<
typename
Callback
>
static
inline
void
IterAllVar
(
const
SSA
Graph
&
graph
,
Callback
callback
)
{
for
(
auto
&
each
:
graph
.
vars_
)
{
static
inline
void
IterAllVar
(
const
Graph
&
graph
,
Callback
callback
)
{
for
(
auto
&
each
:
graph
.
Get
<
GraphVars
>
(
"vars"
)
)
{
for
(
auto
&
pair1
:
each
)
{
for
(
auto
&
pair2
:
pair1
.
second
)
{
callback
(
*
pair2
);
...
...
@@ -30,12 +30,12 @@ static inline void IterAllVar(const SSAGraph &graph, Callback callback) {
}
}
for
(
auto
&
var
:
graph
.
dep_vars_
)
{
for
(
auto
&
var
:
graph
.
Get
<
GraphDepVars
>
(
"dep_vars"
)
)
{
callback
(
*
var
);
}
}
void
GraphvizSSAGraphPrinter
::
Print
(
const
SSA
Graph
&
graph
,
void
GraphvizSSAGraphPrinter
::
Print
(
const
Graph
&
graph
,
std
::
ostream
&
sout
)
const
{
size_t
var_id
=
0
;
std
::
unordered_map
<
const
VarHandleBase
*
,
size_t
>
vars
;
...
...
@@ -61,7 +61,7 @@ void GraphvizSSAGraphPrinter::Print(const SSAGraph &graph,
});
size_t
op_id
=
0
;
for
(
auto
&
op
:
graph
.
ops_
)
{
for
(
auto
&
op
:
graph
.
Get
<
GraphOps
>
(
"ops"
)
)
{
std
::
string
op_name
=
"op_"
+
std
::
to_string
(
op_id
++
);
sout
<<
op_name
<<
" [label=
\"
"
<<
op
->
Name
()
<<
"
\"
, shape=rect]"
<<
std
::
endl
;
...
...
paddle/fluid/framework/details/ssa_graph_printer.h
浏览文件 @
68aa5004
...
...
@@ -25,12 +25,12 @@ struct SSAGraph;
class
SSAGraphPrinter
{
public:
virtual
~
SSAGraphPrinter
()
{}
virtual
void
Print
(
const
SSA
Graph
&
graph
,
std
::
ostream
&
sout
)
const
=
0
;
virtual
void
Print
(
const
Graph
&
graph
,
std
::
ostream
&
sout
)
const
=
0
;
};
class
GraphvizSSAGraphPrinter
:
public
SSAGraphPrinter
{
public:
void
Print
(
const
SSA
Graph
&
graph
,
std
::
ostream
&
sout
)
const
override
;
void
Print
(
const
Graph
&
graph
,
std
::
ostream
&
sout
)
const
override
;
};
class
SSAGraghBuilderWithPrinter
:
public
SSAGraphBuilder
{
...
...
@@ -50,7 +50,7 @@ class SSAGraghBuilderWithPrinter : public SSAGraphBuilder {
stream_ptr_
(
std
::
move
(
sout
)),
stream_ref_
(
*
stream_ptr_
)
{}
std
::
unique_ptr
<
SSA
Graph
>
Build
(
const
ProgramDesc
&
program
)
const
override
{
std
::
unique_ptr
<
Graph
>
Build
(
const
ProgramDesc
&
program
)
const
override
{
auto
graph
=
builder_
->
Build
(
program
);
printer_
->
Print
(
*
graph
,
stream_ref_
);
return
graph
;
...
...
paddle/fluid/framework/ir/graph.h
浏览文件 @
68aa5004
...
...
@@ -26,71 +26,45 @@ limitations under the License. */
namespace
paddle
{
namespace
framework
{
class
Graph
;
template
<
typename
AttrType
>
struct
AnyAttr
{
public:
explicit
AnyAttr
(
AttrType
*
attr
)
:
attr_
(
attr
)
{}
AttrType
&
Get
()
{
return
*
boost
::
any_cast
<
AttrType
*>
(
attr_
);
}
private:
friend
Graph
;
AttrType
*
Release
()
{
released_
=
true
;
return
boost
::
any_cast
<
AttrType
*>
(
attr_
);
}
void
Delete
()
{
if
(
!
released_
)
{
delete
boost
::
any_cast
<
AttrType
*>
(
attr_
);
}
}
bool
released_
=
false
;
boost
::
any
attr_
;
};
class
Graph
{
public:
virtual
~
Graph
()
{
for
(
auto
&
attr
:
attrs
)
{
attr_dels
[
attr
.
first
]();
for
(
auto
&
attr
:
attrs
_
)
{
attr_dels
_
[
attr
.
first
]();
}
attrs
.
clear
();
attr_dels
.
clear
();
attrs
_
.
clear
();
attr_dels
_
.
clear
();
}
template
<
typename
AttrType
>
AttrType
&
Get
(
const
std
::
string
&
attr_name
)
{
return
boost
::
any_cast
<
AnyAttr
<
AttrType
>>
(
attrs
[
attr_name
]).
Get
(
);
AttrType
&
Get
(
const
std
::
string
&
attr_name
)
const
{
return
*
boost
::
any_cast
<
AttrType
*>
(
attrs_
.
at
(
attr_name
)
);
}
template
<
typename
AttrType
>
void
Set
(
const
std
::
string
&
attr_name
,
AttrType
*
attr
)
{
AnyAttr
<
AttrType
>
any_attr
=
AnyAttr
<
AttrType
>
(
attr
);
attrs
[
attr_name
]
=
any_attr
;
attr_dels
[
attr_name
]
=
[
&
any_attr
]()
{
any_attr
.
Delete
();
};
attrs_
[
attr_name
]
=
attr
;
attr_dels_
[
attr_name
]
=
[
attr
,
attr_name
]()
{
VLOG
(
3
)
<<
"deleting "
<<
attr_name
;
delete
attr
;
};
}
template
<
typename
AttrType
>
AttrType
*
Erase
(
const
std
::
string
&
attr_name
)
{
AnyAttr
<
AttrType
>
attr_type
=
boost
::
any_cast
<
AnyAttr
<
AttrType
>>
(
attrs
[
attr_name
]);
attrs
.
erase
(
attr_name
);
attr_dels
.
erase
(
attr_name
);
return
attr_type
.
Release
();
AttrType
*
attr
=
boost
::
any_cast
<
AttrType
*>
(
attrs_
[
attr_name
]);
attrs_
.
erase
(
attr_name
);
attr_dels_
.
erase
(
attr_name
);
return
attr
;
}
std
::
vector
<
Node
*>
inputs
;
std
::
vector
<
Node
*>
outputs
;
std
::
vector
<
std
::
unique_ptr
<
Node
>>
nodes
;
std
::
map
<
std
::
string
,
boost
::
any
>
attrs
;
std
::
map
<
std
::
string
,
std
::
function
<
void
(
void
)
>>
attr_dels
;
private:
std
::
map
<
std
::
string
,
boost
::
any
>
attrs_
;
std
::
map
<
std
::
string
,
std
::
function
<
void
(
void
)
>>
attr_dels_
;
};
}
// namespace framework
...
...
paddle/fluid/framework/parallel_executor.cc
浏览文件 @
68aa5004
...
...
@@ -18,6 +18,8 @@ limitations under the License. */
#include <tuple>
#include <vector>
#include "paddle/fluid/framework/details/ssa_graph.h"
#ifdef PADDLE_WITH_CUDA
#include "paddle/fluid/platform/nccl_helper.h"
#endif
...
...
@@ -131,9 +133,16 @@ ParallelExecutor::ParallelExecutor(
}
builder_
=
builder_factory
.
Create
();
std
::
unique_ptr
<
Graph
>
graph
=
builder_
->
Build
(
main_program
);
std
::
unique_ptr
<
details
::
SSAGraph
>
ssa_graph
(
new
details
::
SSAGraph
);
ssa_graph
->
vars_
=
std
::
move
(
graph
->
Get
<
details
::
GraphVars
>
(
"vars"
));
ssa_graph
->
ops_
=
std
::
move
(
graph
->
Get
<
details
::
GraphOps
>
(
"ops"
));
ssa_graph
->
dep_vars_
=
std
::
move
(
graph
->
Get
<
details
::
GraphDepVars
>
(
"dep_vars"
));
member_
->
executor_
.
reset
(
new
details
::
ThreadedSSAGraphExecutor
(
exec_strategy
,
member_
->
local_scopes_
,
places
,
builder_
->
Build
(
main_program
)));
exec_strategy
,
member_
->
local_scopes_
,
places
,
std
::
move
(
ssa_graph
)));
member_
->
executor_
.
reset
(
new
details
::
ScopeBufferedSSAGraphExecutor
(
exec_strategy
,
member_
->
local_scopes_
,
std
::
move
(
var_infos
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录