Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
7ac969b8
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
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. */
#include "lod_tensor.h"
#include "lod_tensor_array.h"
#include "op_registry.h"
#include "paddle/fluid/framework/feed_fetch_type.h"
#include "paddle/fluid/operators/math/concat.h"
namespace
paddle
{
...
...
@@ -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
{
std
::
shared_ptr
<
FetchedData
>
data_
;
FeedFetchList
*
data_
;
size_t
offset_
;
std
::
vector
<
Scope
*>
*
local_scopes_
;
std
::
vector
<
LoDTensor
>
tensors_
;
...
...
@@ -175,15 +169,26 @@ struct FetchOpHandle : public OpHandle {
for
(
auto
*
input_var
:
inputs_
)
{
input_var
->
pending_ops_
.
erase
(
this
);
}
// Lazily merge tensors. Will faster code.
MergeTensors
();
}
void
Wait
(
platform
::
DeviceContext
*
waited_dev
)
override
{
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:
void
RunImpl
()
override
{
for
(
auto
*
input
:
inputs_
)
{
...
...
@@ -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
{
...
...
@@ -325,7 +321,6 @@ struct NCCLAllReduceOpHandle : public OpHandle {
:
member_
(
member
)
{}
void
Wait
(
platform
::
DeviceContext
*
waited_dev
)
override
{
VLOG
(
3
)
<<
"Wait nccl all reduce op"
;
OpHandle
::
Wait
(
waited_dev
);
}
...
...
@@ -355,6 +350,11 @@ struct NCCLAllReduceOpHandle : public OpHandle {
auto
&
lod_tensor
=
s
->
FindVar
(
var_name
)
->
Get
<
framework
::
LoDTensor
>
();
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
)
{
dtype
=
ToNCCLDataType
(
lod_tensor
.
type
());
}
...
...
@@ -680,7 +680,7 @@ void ParallelExecutor::BuildNCCLCommunicator() const {
void
ParallelExecutor
::
Run
(
const
std
::
vector
<
std
::
string
>
&
fetch_tensors
,
const
std
::
string
&
fetched_var_name
)
{
bool
use_event
=
true
;
auto
fetched_data
=
std
::
make_shared
<
FetchedData
>
(
fetch_tensors
.
size
());
FeedFetchList
fetched_data
(
fetch_tensors
.
size
());
// Version --> VarHandle
member_
->
exception_
.
reset
();
std
::
unordered_map
<
VarHandleBase
*
,
std
::
atomic
<
bool
>>
pending_vars
;
...
...
@@ -728,7 +728,7 @@ void ParallelExecutor::Run(const std::vector<std::string> &fetch_tensors,
auto
&
vars
=
fetched_vars
[
var_name
];
fetch_ops
.
emplace_back
();
FetchOpHandle
*
op
=
&
fetch_ops
.
back
();
op
->
data_
=
fetched_data
;
op
->
data_
=
&
fetched_data
;
op
->
offset_
=
i
;
op
->
local_scopes_
=
&
member_
->
local_scopes_
;
for
(
auto
&
p
:
member_
->
places_
)
{
...
...
@@ -786,9 +786,12 @@ void ParallelExecutor::Run(const std::vector<std::string> &fetch_tensors,
platform
::
DeviceContextPool
::
Instance
().
Get
(
p
)
->
Wait
();
}
fetch_ops
.
clear
();
*
member_
->
global_scope_
->
Var
(
fetched_var_name
)
->
GetMutable
<
LoDTensorArray
>
()
=
fetched_data
->
tensors_
;
for
(
auto
&
fetch_op
:
fetch_ops
)
{
fetch_op
.
WaitAndMergeCPUTensors
();
}
*
member_
->
global_scope_
->
Var
(
fetched_var_name
)
->
GetMutable
<
FeedFetchList
>
()
=
fetched_data
;
}
void
ParallelExecutor
::
RunOp
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录