Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
68aa5004
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
提交
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(
...
@@ -167,7 +167,7 @@ size_t MultiDevSSAGraphBuilder::GetAppropriateDeviceID(
return
dev_id
;
return
dev_id
;
}
}
std
::
unique_ptr
<
SSA
Graph
>
MultiDevSSAGraphBuilder
::
Build
(
std
::
unique_ptr
<
Graph
>
MultiDevSSAGraphBuilder
::
Build
(
const
ProgramDesc
&
program
)
const
{
const
ProgramDesc
&
program
)
const
{
std
::
unique_ptr
<
Graph
>
graph
(
new
Graph
);
std
::
unique_ptr
<
Graph
>
graph
(
new
Graph
);
for
(
auto
*
var
:
program
.
Block
(
0
).
AllVars
())
{
for
(
auto
*
var
:
program
.
Block
(
0
).
AllVars
())
{
...
@@ -301,12 +301,7 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
...
@@ -301,12 +301,7 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
* Only variables should be the leaves of graph.
* Only variables should be the leaves of graph.
*/
*/
AddOutputToLeafOps
(
&
result
);
AddOutputToLeafOps
(
&
result
);
return
std
::
move
(
graph
);
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
);
}
}
bool
MultiDevSSAGraphBuilder
::
IsSparseGradient
(
const
std
::
string
&
og
)
const
{
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 {
...
@@ -47,7 +47,7 @@ class MultiDevSSAGraphBuilder : public SSAGraphBuilder {
const
BuildStrategy
&
strategy
);
const
BuildStrategy
&
strategy
);
#endif
#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
;
int
GetVarDeviceID
(
const
std
::
string
&
varname
)
const
override
;
private:
private:
...
...
paddle/fluid/framework/details/ssa_graph_builder.h
浏览文件 @
68aa5004
...
@@ -38,7 +38,7 @@ class SSAGraphBuilder {
...
@@ -38,7 +38,7 @@ class SSAGraphBuilder {
public:
public:
SSAGraphBuilder
()
{}
SSAGraphBuilder
()
{}
virtual
~
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
;
virtual
int
GetVarDeviceID
(
const
std
::
string
&
var_name
)
const
=
0
;
DISABLE_COPY_AND_ASSIGN
(
SSAGraphBuilder
);
DISABLE_COPY_AND_ASSIGN
(
SSAGraphBuilder
);
...
...
paddle/fluid/framework/details/ssa_graph_checker.cc
浏览文件 @
68aa5004
...
@@ -20,7 +20,7 @@ namespace paddle {
...
@@ -20,7 +20,7 @@ namespace paddle {
namespace
framework
{
namespace
framework
{
namespace
details
{
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_map
<
OpHandleBase
*
,
size_t
>
pending_ops
;
std
::
unordered_set
<
VarHandleBase
*>
pending_vars
;
std
::
unordered_set
<
VarHandleBase
*>
pending_vars
;
std
::
unordered_set
<
VarHandleBase
*>
ready_vars
;
std
::
unordered_set
<
VarHandleBase
*>
ready_vars
;
...
@@ -33,7 +33,7 @@ bool SSAGraghBuilderWithChecker::IsValidGraph(const SSAGraph *graph) const {
...
@@ -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
&
name_pair
:
var_map
)
{
for
(
auto
&
version_pair
:
name_pair
.
second
)
{
for
(
auto
&
version_pair
:
name_pair
.
second
)
{
insert_pending_var
(
version_pair
.
get
());
insert_pending_var
(
version_pair
.
get
());
...
@@ -41,11 +41,11 @@ bool SSAGraghBuilderWithChecker::IsValidGraph(const SSAGraph *graph) const {
...
@@ -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
());
insert_pending_var
(
var
.
get
());
}
}
for
(
auto
&
op
:
graph
->
ops_
)
{
for
(
auto
&
op
:
graph
->
Get
<
GraphOps
>
(
"ops"
)
)
{
if
(
op
->
Inputs
().
empty
())
{
if
(
op
->
Inputs
().
empty
())
{
ready_ops
.
insert
(
op
.
get
());
ready_ops
.
insert
(
op
.
get
());
}
else
{
}
else
{
...
...
paddle/fluid/framework/details/ssa_graph_checker.h
浏览文件 @
68aa5004
...
@@ -29,7 +29,7 @@ class SSAGraghBuilderWithChecker : public SSAGraphBuilder {
...
@@ -29,7 +29,7 @@ class SSAGraghBuilderWithChecker : public SSAGraphBuilder {
std
::
unique_ptr
<
SSAGraphBuilder
>&&
builder
)
std
::
unique_ptr
<
SSAGraphBuilder
>&&
builder
)
:
builder_
(
std
::
move
(
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
);
auto
graph
=
builder_
->
Build
(
program
);
PADDLE_ENFORCE
(
IsValidGraph
(
graph
.
get
()));
PADDLE_ENFORCE
(
IsValidGraph
(
graph
.
get
()));
return
graph
;
return
graph
;
...
@@ -39,7 +39,7 @@ class SSAGraghBuilderWithChecker : public SSAGraphBuilder {
...
@@ -39,7 +39,7 @@ class SSAGraghBuilderWithChecker : public SSAGraphBuilder {
return
builder_
->
GetVarDeviceID
(
var_name
);
return
builder_
->
GetVarDeviceID
(
var_name
);
}
}
bool
IsValidGraph
(
const
SSA
Graph
*
graph
)
const
;
bool
IsValidGraph
(
const
Graph
*
graph
)
const
;
private:
private:
std
::
unique_ptr
<
SSAGraphBuilder
>
builder_
;
std
::
unique_ptr
<
SSAGraphBuilder
>
builder_
;
...
...
paddle/fluid/framework/details/ssa_graph_printer.cc
浏览文件 @
68aa5004
...
@@ -21,8 +21,8 @@ namespace framework {
...
@@ -21,8 +21,8 @@ namespace framework {
namespace
details
{
namespace
details
{
template
<
typename
Callback
>
template
<
typename
Callback
>
static
inline
void
IterAllVar
(
const
SSA
Graph
&
graph
,
Callback
callback
)
{
static
inline
void
IterAllVar
(
const
Graph
&
graph
,
Callback
callback
)
{
for
(
auto
&
each
:
graph
.
vars_
)
{
for
(
auto
&
each
:
graph
.
Get
<
GraphVars
>
(
"vars"
)
)
{
for
(
auto
&
pair1
:
each
)
{
for
(
auto
&
pair1
:
each
)
{
for
(
auto
&
pair2
:
pair1
.
second
)
{
for
(
auto
&
pair2
:
pair1
.
second
)
{
callback
(
*
pair2
);
callback
(
*
pair2
);
...
@@ -30,12 +30,12 @@ static inline void IterAllVar(const SSAGraph &graph, Callback callback) {
...
@@ -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
);
callback
(
*
var
);
}
}
}
}
void
GraphvizSSAGraphPrinter
::
Print
(
const
SSA
Graph
&
graph
,
void
GraphvizSSAGraphPrinter
::
Print
(
const
Graph
&
graph
,
std
::
ostream
&
sout
)
const
{
std
::
ostream
&
sout
)
const
{
size_t
var_id
=
0
;
size_t
var_id
=
0
;
std
::
unordered_map
<
const
VarHandleBase
*
,
size_t
>
vars
;
std
::
unordered_map
<
const
VarHandleBase
*
,
size_t
>
vars
;
...
@@ -61,7 +61,7 @@ void GraphvizSSAGraphPrinter::Print(const SSAGraph &graph,
...
@@ -61,7 +61,7 @@ void GraphvizSSAGraphPrinter::Print(const SSAGraph &graph,
});
});
size_t
op_id
=
0
;
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
++
);
std
::
string
op_name
=
"op_"
+
std
::
to_string
(
op_id
++
);
sout
<<
op_name
<<
" [label=
\"
"
<<
op
->
Name
()
<<
"
\"
, shape=rect]"
sout
<<
op_name
<<
" [label=
\"
"
<<
op
->
Name
()
<<
"
\"
, shape=rect]"
<<
std
::
endl
;
<<
std
::
endl
;
...
...
paddle/fluid/framework/details/ssa_graph_printer.h
浏览文件 @
68aa5004
...
@@ -25,12 +25,12 @@ struct SSAGraph;
...
@@ -25,12 +25,12 @@ struct SSAGraph;
class
SSAGraphPrinter
{
class
SSAGraphPrinter
{
public:
public:
virtual
~
SSAGraphPrinter
()
{}
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
{
class
GraphvizSSAGraphPrinter
:
public
SSAGraphPrinter
{
public:
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
{
class
SSAGraghBuilderWithPrinter
:
public
SSAGraphBuilder
{
...
@@ -50,7 +50,7 @@ class SSAGraghBuilderWithPrinter : public SSAGraphBuilder {
...
@@ -50,7 +50,7 @@ class SSAGraghBuilderWithPrinter : public SSAGraphBuilder {
stream_ptr_
(
std
::
move
(
sout
)),
stream_ptr_
(
std
::
move
(
sout
)),
stream_ref_
(
*
stream_ptr_
)
{}
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
);
auto
graph
=
builder_
->
Build
(
program
);
printer_
->
Print
(
*
graph
,
stream_ref_
);
printer_
->
Print
(
*
graph
,
stream_ref_
);
return
graph
;
return
graph
;
...
...
paddle/fluid/framework/ir/graph.h
浏览文件 @
68aa5004
...
@@ -26,71 +26,45 @@ limitations under the License. */
...
@@ -26,71 +26,45 @@ limitations under the License. */
namespace
paddle
{
namespace
paddle
{
namespace
framework
{
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
{
class
Graph
{
public:
public:
virtual
~
Graph
()
{
virtual
~
Graph
()
{
for
(
auto
&
attr
:
attrs
)
{
for
(
auto
&
attr
:
attrs
_
)
{
attr_dels
[
attr
.
first
]();
attr_dels
_
[
attr
.
first
]();
}
}
attrs
.
clear
();
attrs
_
.
clear
();
attr_dels
.
clear
();
attr_dels
_
.
clear
();
}
}
template
<
typename
AttrType
>
template
<
typename
AttrType
>
AttrType
&
Get
(
const
std
::
string
&
attr_name
)
{
AttrType
&
Get
(
const
std
::
string
&
attr_name
)
const
{
return
boost
::
any_cast
<
AnyAttr
<
AttrType
>>
(
attrs
[
attr_name
]).
Get
(
);
return
*
boost
::
any_cast
<
AttrType
*>
(
attrs_
.
at
(
attr_name
)
);
}
}
template
<
typename
AttrType
>
template
<
typename
AttrType
>
void
Set
(
const
std
::
string
&
attr_name
,
AttrType
*
attr
)
{
void
Set
(
const
std
::
string
&
attr_name
,
AttrType
*
attr
)
{
AnyAttr
<
AttrType
>
any_attr
=
AnyAttr
<
AttrType
>
(
attr
);
attrs_
[
attr_name
]
=
attr
;
attrs
[
attr_name
]
=
any_attr
;
attr_dels_
[
attr_name
]
=
[
attr
,
attr_name
]()
{
attr_dels
[
attr_name
]
=
[
&
any_attr
]()
{
any_attr
.
Delete
();
};
VLOG
(
3
)
<<
"deleting "
<<
attr_name
;
delete
attr
;
};
}
}
template
<
typename
AttrType
>
template
<
typename
AttrType
>
AttrType
*
Erase
(
const
std
::
string
&
attr_name
)
{
AttrType
*
Erase
(
const
std
::
string
&
attr_name
)
{
AnyAttr
<
AttrType
>
attr_type
=
AttrType
*
attr
=
boost
::
any_cast
<
AttrType
*>
(
attrs_
[
attr_name
]);
boost
::
any_cast
<
AnyAttr
<
AttrType
>>
(
attrs
[
attr_name
]);
attrs_
.
erase
(
attr_name
);
attrs
.
erase
(
attr_name
);
attr_dels_
.
erase
(
attr_name
);
attr_dels
.
erase
(
attr_name
);
return
attr
;
return
attr_type
.
Release
();
}
}
std
::
vector
<
Node
*>
inputs
;
std
::
vector
<
Node
*>
inputs
;
std
::
vector
<
Node
*>
outputs
;
std
::
vector
<
Node
*>
outputs
;
std
::
vector
<
std
::
unique_ptr
<
Node
>>
nodes
;
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:
private:
std
::
map
<
std
::
string
,
boost
::
any
>
attrs_
;
std
::
map
<
std
::
string
,
std
::
function
<
void
(
void
)
>>
attr_dels_
;
};
};
}
// namespace framework
}
// namespace framework
...
...
paddle/fluid/framework/parallel_executor.cc
浏览文件 @
68aa5004
...
@@ -18,6 +18,8 @@ limitations under the License. */
...
@@ -18,6 +18,8 @@ limitations under the License. */
#include <tuple>
#include <tuple>
#include <vector>
#include <vector>
#include "paddle/fluid/framework/details/ssa_graph.h"
#ifdef PADDLE_WITH_CUDA
#ifdef PADDLE_WITH_CUDA
#include "paddle/fluid/platform/nccl_helper.h"
#include "paddle/fluid/platform/nccl_helper.h"
#endif
#endif
...
@@ -131,9 +133,16 @@ ParallelExecutor::ParallelExecutor(
...
@@ -131,9 +133,16 @@ ParallelExecutor::ParallelExecutor(
}
}
builder_
=
builder_factory
.
Create
();
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
(
member_
->
executor_
.
reset
(
new
details
::
ThreadedSSAGraphExecutor
(
exec_strategy
,
member_
->
local_scopes_
,
places
,
exec_strategy
,
member_
->
local_scopes_
,
places
,
std
::
move
(
ssa_graph
)));
builder_
->
Build
(
main_program
)));
member_
->
executor_
.
reset
(
new
details
::
ScopeBufferedSSAGraphExecutor
(
member_
->
executor_
.
reset
(
new
details
::
ScopeBufferedSSAGraphExecutor
(
exec_strategy
,
member_
->
local_scopes_
,
std
::
move
(
var_infos
),
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录