Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
63471c83
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看板
未验证
提交
63471c83
编写于
3月 29, 2022
作者:
L
liutiexing
提交者:
GitHub
3月 29, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine AsyncWorkQueue (#40977)
上级
733d8168
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
29 addition
and
28 deletion
+29
-28
paddle/fluid/framework/new_executor/interpretercore_util.cc
paddle/fluid/framework/new_executor/interpretercore_util.cc
+22
-23
paddle/fluid/framework/new_executor/workqueue/thread_data_registry.h
...d/framework/new_executor/workqueue/thread_data_registry.h
+7
-5
未找到文件。
paddle/fluid/framework/new_executor/interpretercore_util.cc
浏览文件 @
63471c83
...
@@ -29,6 +29,8 @@ namespace paddle {
...
@@ -29,6 +29,8 @@ namespace paddle {
namespace
framework
{
namespace
framework
{
namespace
interpreter
{
namespace
interpreter
{
constexpr
size_t
kPrepareWorkQueueIdx
=
2
;
void
AsyncWorkQueue
::
AddTask
(
const
OpFuncType
&
op_func_type
,
void
AsyncWorkQueue
::
AddTask
(
const
OpFuncType
&
op_func_type
,
std
::
function
<
void
()
>
fn
)
{
std
::
function
<
void
()
>
fn
)
{
// NOTE(zhiqiu): use thhe second queue of size of, so only one thread is used.
// NOTE(zhiqiu): use thhe second queue of size of, so only one thread is used.
...
@@ -47,33 +49,30 @@ using VariableIdMap = std::map<std::string, std::vector<int>>;
...
@@ -47,33 +49,30 @@ using VariableIdMap = std::map<std::string, std::vector<int>>;
void
AsyncWorkQueue
::
PrepareAtomicDeps
(
void
AsyncWorkQueue
::
PrepareAtomicDeps
(
const
std
::
vector
<
size_t
>&
dependecy_count
)
{
const
std
::
vector
<
size_t
>&
dependecy_count
)
{
VLOG
(
4
)
<<
"PrepareAtomicDeps"
;
VLOG
(
4
)
<<
"PrepareAtomicDeps"
;
auto
p
=
std
::
make_shared
<
atomic_deps_
=
std
::
promise
<
std
::
unique_ptr
<
std
::
vector
<
std
::
atomic
<
size_t
>>>>>
();
queue_group_
->
AddAwaitableTask
(
kPrepareWorkQueueIdx
,
[
&
dependecy_count
]
{
atomic_deps_
=
p
->
get_future
();
auto
op_deps
=
std
::
make_unique
<
std
::
vector
<
std
::
atomic
<
size_t
>>>
(
queue_group_
->
AddTask
(
2
,
[
&
dependecy_count
,
p
]
{
dependecy_count
.
size
());
auto
*
op_deps
=
new
std
::
vector
<
std
::
atomic
<
size_t
>>
(
dependecy_count
.
size
());
for
(
size_t
i
=
0
;
i
<
dependecy_count
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
dependecy_count
.
size
();
++
i
)
{
(
*
op_deps
)[
i
]
=
dependecy_count
[
i
];
(
*
op_deps
)[
i
]
=
dependecy_count
[
i
];
}
}
VLOG
(
4
)
<<
"AtomicDeps:"
<<
op_deps
<<
" "
<<
(
*
op_deps
).
size
();
VLOG
(
4
)
<<
"AtomicDeps:"
<<
op_deps
.
get
()
<<
" "
<<
op_deps
->
size
();
p
->
set_value
(
std
::
unique_ptr
<
std
::
vector
<
std
::
atomic
<
size_t
>>>
(
op_deps
))
;
return
op_deps
;
});
});
}
}
void
AsyncWorkQueue
::
PrepareAtomicVarRef
(
void
AsyncWorkQueue
::
PrepareAtomicVarRef
(
const
std
::
vector
<
VariableMetaInfo
>&
vec_meta_info
)
{
const
std
::
vector
<
VariableMetaInfo
>&
vec_meta_info
)
{
VLOG
(
4
)
<<
"PrepareAtomicVarRef"
;
VLOG
(
4
)
<<
"PrepareAtomicVarRef"
;
auto
p
=
std
::
make_shared
<
atomic_var_ref_
=
std
::
promise
<
std
::
unique_ptr
<
std
::
vector
<
std
::
atomic
<
size_t
>>>>>
();
queue_group_
->
AddAwaitableTask
(
kPrepareWorkQueueIdx
,
[
&
vec_meta_info
]
{
atomic_var_ref_
=
p
->
get_future
();
auto
var_ref
=
std
::
make_unique
<
std
::
vector
<
std
::
atomic
<
size_t
>>>
(
queue_group_
->
AddTask
(
2
,
[
&
vec_meta_info
,
p
]
{
vec_meta_info
.
size
());
auto
*
var_ref
=
new
std
::
vector
<
std
::
atomic
<
size_t
>>
(
vec_meta_info
.
size
());
for
(
size_t
i
=
0
;
i
<
vec_meta_info
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
vec_meta_info
.
size
();
++
i
)
{
(
*
var_ref
)[
i
]
=
vec_meta_info
[
i
].
var_ref_count_
;
(
*
var_ref
)[
i
]
=
vec_meta_info
[
i
].
var_ref_count_
;
}
}
VLOG
(
4
)
<<
"AtomicVarRef:"
<<
var_ref
<<
" "
<<
(
*
var_ref
).
size
();
VLOG
(
4
)
<<
"AtomicVarRef:"
<<
var_ref
.
get
()
<<
" "
<<
var_ref
->
size
();
p
->
set_value
(
std
::
unique_ptr
<
std
::
vector
<
std
::
atomic
<
size_t
>>>
(
var_ref
))
;
return
var_ref
;
});
});
}
}
...
...
paddle/fluid/framework/new_executor/workqueue/thread_data_registry.h
浏览文件 @
63471c83
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
#include <functional>
#include <functional>
#include <memory>
#include <memory>
#include <mutex>
#include <mutex>
#include <shared_mutex>
#include <thread>
#include <thread>
#include <type_traits>
#include <type_traits>
#include <unordered_map>
#include <unordered_map>
...
@@ -60,16 +61,17 @@ class ThreadDataRegistry {
...
@@ -60,16 +61,17 @@ class ThreadDataRegistry {
private:
private:
// types
// types
using
LockType
=
std
::
shared_timed_mutex
;
class
ThreadDataHolder
;
class
ThreadDataHolder
;
class
ThreadDataRegistryImpl
{
class
ThreadDataRegistryImpl
{
public:
public:
void
RegisterData
(
uint64_t
tid
,
ThreadDataHolder
*
tls_obj
)
{
void
RegisterData
(
uint64_t
tid
,
ThreadDataHolder
*
tls_obj
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
lock_
);
std
::
lock_guard
<
LockType
>
lock
(
lock_
);
tid_map_
[
tid
]
=
tls_obj
;
tid_map_
[
tid
]
=
tls_obj
;
}
}
void
UnregisterData
(
uint64_t
tid
)
{
void
UnregisterData
(
uint64_t
tid
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
lock_
);
std
::
lock_guard
<
LockType
>
lock
(
lock_
);
tid_map_
.
erase
(
tid
);
tid_map_
.
erase
(
tid
);
}
}
...
@@ -77,7 +79,7 @@ class ThreadDataRegistry {
...
@@ -77,7 +79,7 @@ class ThreadDataRegistry {
std
::
is_copy_constructible
<
Alias
>
::
value
>>
std
::
is_copy_constructible
<
Alias
>
::
value
>>
std
::
unordered_map
<
uint64_t
,
T
>
GetAllThreadDataByValue
()
{
std
::
unordered_map
<
uint64_t
,
T
>
GetAllThreadDataByValue
()
{
std
::
unordered_map
<
uint64_t
,
T
>
data_copy
;
std
::
unordered_map
<
uint64_t
,
T
>
data_copy
;
std
::
lock_guard
<
std
::
mutex
>
lock
(
lock_
);
std
::
shared_lock
<
LockType
>
lock
(
lock_
);
data_copy
.
reserve
(
tid_map_
.
size
());
data_copy
.
reserve
(
tid_map_
.
size
());
for
(
auto
&
kv
:
tid_map_
)
{
for
(
auto
&
kv
:
tid_map_
)
{
data_copy
.
emplace
(
kv
.
first
,
kv
.
second
->
GetData
());
data_copy
.
emplace
(
kv
.
first
,
kv
.
second
->
GetData
());
...
@@ -88,7 +90,7 @@ class ThreadDataRegistry {
...
@@ -88,7 +90,7 @@ class ThreadDataRegistry {
std
::
unordered_map
<
uint64_t
,
std
::
reference_wrapper
<
T
>>
std
::
unordered_map
<
uint64_t
,
std
::
reference_wrapper
<
T
>>
GetAllThreadDataByRef
()
{
GetAllThreadDataByRef
()
{
std
::
unordered_map
<
uint64_t
,
std
::
reference_wrapper
<
T
>>
data_ref
;
std
::
unordered_map
<
uint64_t
,
std
::
reference_wrapper
<
T
>>
data_ref
;
std
::
lock_guard
<
std
::
mutex
>
lock
(
lock_
);
std
::
shared_lock
<
LockType
>
lock
(
lock_
);
data_ref
.
reserve
(
tid_map_
.
size
());
data_ref
.
reserve
(
tid_map_
.
size
());
for
(
auto
&
kv
:
tid_map_
)
{
for
(
auto
&
kv
:
tid_map_
)
{
data_ref
.
emplace
(
kv
.
first
,
std
::
ref
(
kv
.
second
->
GetData
()));
data_ref
.
emplace
(
kv
.
first
,
std
::
ref
(
kv
.
second
->
GetData
()));
...
@@ -97,7 +99,7 @@ class ThreadDataRegistry {
...
@@ -97,7 +99,7 @@ class ThreadDataRegistry {
}
}
private:
private:
std
::
mutex
lock_
;
LockType
lock_
;
std
::
unordered_map
<
uint64_t
,
ThreadDataHolder
*>
tid_map_
;
// not owned
std
::
unordered_map
<
uint64_t
,
ThreadDataHolder
*>
tid_map_
;
// not owned
};
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录