Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7ac969b8
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看板
提交
7ac969b8
编写于
3月 21, 2018
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Debug
* add Check align * Make FetchData not shared_ptr * Remove FetchData * Wait & Fetch Data
上级
599f7a87
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
29 addition
and
26 deletion
+29
-26
paddle/fluid/framework/parallel_executor.cc
paddle/fluid/framework/parallel_executor.cc
+29
-26
未找到文件。
paddle/fluid/framework/parallel_executor.cc
浏览文件 @
7ac969b8
...
@@ -18,6 +18,7 @@ limitations under the License. */
...
@@ -18,6 +18,7 @@ limitations under the License. */
#include "lod_tensor.h"
#include "lod_tensor.h"
#include "lod_tensor_array.h"
#include "lod_tensor_array.h"
#include "op_registry.h"
#include "op_registry.h"
#include "paddle/fluid/framework/feed_fetch_type.h"
#include "paddle/fluid/operators/math/concat.h"
#include "paddle/fluid/operators/math/concat.h"
namespace
paddle
{
namespace
paddle
{
...
@@ -158,15 +159,8 @@ struct ScaleLossGradOpHandle : public OpHandle {
...
@@ -158,15 +159,8 @@ struct ScaleLossGradOpHandle : public OpHandle {
}
}
};
};
struct
FetchedData
{
public:
std
::
vector
<
framework
::
LoDTensor
>
tensors_
;
explicit
FetchedData
(
size_t
num_fetched
)
{
tensors_
.
resize
(
num_fetched
);
}
};
struct
FetchOpHandle
:
public
OpHandle
{
struct
FetchOpHandle
:
public
OpHandle
{
std
::
shared_ptr
<
FetchedData
>
data_
;
FeedFetchList
*
data_
;
size_t
offset_
;
size_t
offset_
;
std
::
vector
<
Scope
*>
*
local_scopes_
;
std
::
vector
<
Scope
*>
*
local_scopes_
;
std
::
vector
<
LoDTensor
>
tensors_
;
std
::
vector
<
LoDTensor
>
tensors_
;
...
@@ -175,15 +169,26 @@ struct FetchOpHandle : public OpHandle {
...
@@ -175,15 +169,26 @@ struct FetchOpHandle : public OpHandle {
for
(
auto
*
input_var
:
inputs_
)
{
for
(
auto
*
input_var
:
inputs_
)
{
input_var
->
pending_ops_
.
erase
(
this
);
input_var
->
pending_ops_
.
erase
(
this
);
}
}
// Lazily merge tensors. Will faster code.
MergeTensors
();
}
}
void
Wait
(
platform
::
DeviceContext
*
waited_dev
)
override
{
void
Wait
(
platform
::
DeviceContext
*
waited_dev
)
override
{
PADDLE_THROW
(
"Nobody should wait FetchOp. Unexpceted Error"
);
PADDLE_THROW
(
"Nobody should wait FetchOp. Unexpceted Error"
);
}
}
void
WaitAndMergeCPUTensors
()
const
{
// Wait fetch stream done.
for
(
auto
&
ctx
:
dev_ctx_
)
{
ctx
.
second
->
Wait
();
}
std
::
vector
<
const
LoDTensor
*>
tensors_ptr
;
tensors_ptr
.
reserve
(
tensors_
.
size
());
for
(
auto
&
t
:
tensors_
)
{
tensors_ptr
.
emplace_back
(
&
t
);
}
data_
->
at
(
offset_
).
MergeLoDTensor
(
tensors_ptr
,
platform
::
CPUPlace
());
}
protected:
protected:
void
RunImpl
()
override
{
void
RunImpl
()
override
{
for
(
auto
*
input
:
inputs_
)
{
for
(
auto
*
input
:
inputs_
)
{
...
@@ -208,15 +213,6 @@ struct FetchOpHandle : public OpHandle {
...
@@ -208,15 +213,6 @@ struct FetchOpHandle : public OpHandle {
}
}
}
}
}
}
private:
void
MergeTensors
()
const
{
std
::
vector
<
const
LoDTensor
*>
tensors_ptr
;
for
(
auto
&
t
:
tensors_
)
{
tensors_ptr
.
emplace_back
(
&
t
);
}
data_
->
tensors_
[
offset_
].
MergeLoDTensor
(
tensors_ptr
,
platform
::
CPUPlace
());
}
};
};
class
ParallelExecutorPrivate
{
class
ParallelExecutorPrivate
{
...
@@ -325,7 +321,6 @@ struct NCCLAllReduceOpHandle : public OpHandle {
...
@@ -325,7 +321,6 @@ struct NCCLAllReduceOpHandle : public OpHandle {
:
member_
(
member
)
{}
:
member_
(
member
)
{}
void
Wait
(
platform
::
DeviceContext
*
waited_dev
)
override
{
void
Wait
(
platform
::
DeviceContext
*
waited_dev
)
override
{
VLOG
(
3
)
<<
"Wait nccl all reduce op"
;
OpHandle
::
Wait
(
waited_dev
);
OpHandle
::
Wait
(
waited_dev
);
}
}
...
@@ -355,6 +350,11 @@ struct NCCLAllReduceOpHandle : public OpHandle {
...
@@ -355,6 +350,11 @@ struct NCCLAllReduceOpHandle : public OpHandle {
auto
&
lod_tensor
=
s
->
FindVar
(
var_name
)
->
Get
<
framework
::
LoDTensor
>
();
auto
&
lod_tensor
=
s
->
FindVar
(
var_name
)
->
Get
<
framework
::
LoDTensor
>
();
void
*
buffer
=
const_cast
<
void
*>
(
lod_tensor
.
data
<
void
>
());
void
*
buffer
=
const_cast
<
void
*>
(
lod_tensor
.
data
<
void
>
());
uintptr_t
buf
=
reinterpret_cast
<
uintptr_t
>
(
buffer
);
if
(
buf
%
sizeof
(
float
)
!=
0
)
{
VLOG
(
3
)
<<
"Buffer is not aligned "
<<
buf
;
}
if
(
dtype
==
-
1
)
{
if
(
dtype
==
-
1
)
{
dtype
=
ToNCCLDataType
(
lod_tensor
.
type
());
dtype
=
ToNCCLDataType
(
lod_tensor
.
type
());
}
}
...
@@ -680,7 +680,7 @@ void ParallelExecutor::BuildNCCLCommunicator() const {
...
@@ -680,7 +680,7 @@ void ParallelExecutor::BuildNCCLCommunicator() const {
void
ParallelExecutor
::
Run
(
const
std
::
vector
<
std
::
string
>
&
fetch_tensors
,
void
ParallelExecutor
::
Run
(
const
std
::
vector
<
std
::
string
>
&
fetch_tensors
,
const
std
::
string
&
fetched_var_name
)
{
const
std
::
string
&
fetched_var_name
)
{
bool
use_event
=
true
;
bool
use_event
=
true
;
auto
fetched_data
=
std
::
make_shared
<
FetchedData
>
(
fetch_tensors
.
size
());
FeedFetchList
fetched_data
(
fetch_tensors
.
size
());
// Version --> VarHandle
// Version --> VarHandle
member_
->
exception_
.
reset
();
member_
->
exception_
.
reset
();
std
::
unordered_map
<
VarHandleBase
*
,
std
::
atomic
<
bool
>>
pending_vars
;
std
::
unordered_map
<
VarHandleBase
*
,
std
::
atomic
<
bool
>>
pending_vars
;
...
@@ -728,7 +728,7 @@ void ParallelExecutor::Run(const std::vector<std::string> &fetch_tensors,
...
@@ -728,7 +728,7 @@ void ParallelExecutor::Run(const std::vector<std::string> &fetch_tensors,
auto
&
vars
=
fetched_vars
[
var_name
];
auto
&
vars
=
fetched_vars
[
var_name
];
fetch_ops
.
emplace_back
();
fetch_ops
.
emplace_back
();
FetchOpHandle
*
op
=
&
fetch_ops
.
back
();
FetchOpHandle
*
op
=
&
fetch_ops
.
back
();
op
->
data_
=
fetched_data
;
op
->
data_
=
&
fetched_data
;
op
->
offset_
=
i
;
op
->
offset_
=
i
;
op
->
local_scopes_
=
&
member_
->
local_scopes_
;
op
->
local_scopes_
=
&
member_
->
local_scopes_
;
for
(
auto
&
p
:
member_
->
places_
)
{
for
(
auto
&
p
:
member_
->
places_
)
{
...
@@ -786,9 +786,12 @@ void ParallelExecutor::Run(const std::vector<std::string> &fetch_tensors,
...
@@ -786,9 +786,12 @@ void ParallelExecutor::Run(const std::vector<std::string> &fetch_tensors,
platform
::
DeviceContextPool
::
Instance
().
Get
(
p
)
->
Wait
();
platform
::
DeviceContextPool
::
Instance
().
Get
(
p
)
->
Wait
();
}
}
fetch_ops
.
clear
();
for
(
auto
&
fetch_op
:
fetch_ops
)
{
*
member_
->
global_scope_
->
Var
(
fetched_var_name
)
->
GetMutable
<
LoDTensorArray
>
()
=
fetch_op
.
WaitAndMergeCPUTensors
();
fetched_data
->
tensors_
;
}
*
member_
->
global_scope_
->
Var
(
fetched_var_name
)
->
GetMutable
<
FeedFetchList
>
()
=
fetched_data
;
}
}
void
ParallelExecutor
::
RunOp
(
void
ParallelExecutor
::
RunOp
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录