Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
极客李华
Paddle
提交
63471c83
P
Paddle
项目概览
极客李华
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
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 {
namespace
framework
{
namespace
interpreter
{
constexpr
size_t
kPrepareWorkQueueIdx
=
2
;
void
AsyncWorkQueue
::
AddTask
(
const
OpFuncType
&
op_func_type
,
std
::
function
<
void
()
>
fn
)
{
// NOTE(zhiqiu): use thhe second queue of size of, so only one thread is used.
...
...
@@ -47,34 +49,31 @@ using VariableIdMap = std::map<std::string, std::vector<int>>;
void
AsyncWorkQueue
::
PrepareAtomicDeps
(
const
std
::
vector
<
size_t
>&
dependecy_count
)
{
VLOG
(
4
)
<<
"PrepareAtomicDeps"
;
auto
p
=
std
::
make_shared
<
std
::
promise
<
std
::
unique_ptr
<
std
::
vector
<
std
::
atomic
<
size_t
>>>>>
();
atomic_deps_
=
p
->
get_future
();
queue_group_
->
AddTask
(
2
,
[
&
dependecy_count
,
p
]
{
auto
*
op_deps
=
new
std
::
vector
<
std
::
atomic
<
size_t
>>
(
dependecy_count
.
size
());
for
(
size_t
i
=
0
;
i
<
dependecy_count
.
size
();
++
i
)
{
(
*
op_deps
)[
i
]
=
dependecy_count
[
i
];
}
VLOG
(
4
)
<<
"AtomicDeps:"
<<
op_deps
<<
" "
<<
(
*
op_deps
).
size
();
p
->
set_value
(
std
::
unique_ptr
<
std
::
vector
<
std
::
atomic
<
size_t
>>>
(
op_deps
));
});
atomic_deps_
=
queue_group_
->
AddAwaitableTask
(
kPrepareWorkQueueIdx
,
[
&
dependecy_count
]
{
auto
op_deps
=
std
::
make_unique
<
std
::
vector
<
std
::
atomic
<
size_t
>>>
(
dependecy_count
.
size
());
for
(
size_t
i
=
0
;
i
<
dependecy_count
.
size
();
++
i
)
{
(
*
op_deps
)[
i
]
=
dependecy_count
[
i
];
}
VLOG
(
4
)
<<
"AtomicDeps:"
<<
op_deps
.
get
()
<<
" "
<<
op_deps
->
size
();
return
op_deps
;
});
}
void
AsyncWorkQueue
::
PrepareAtomicVarRef
(
const
std
::
vector
<
VariableMetaInfo
>&
vec_meta_info
)
{
VLOG
(
4
)
<<
"PrepareAtomicVarRef"
;
auto
p
=
std
::
make_shared
<
std
::
promise
<
std
::
unique_ptr
<
std
::
vector
<
std
::
atomic
<
size_t
>>>>>
();
atomic_var_ref_
=
p
->
get_future
();
queue_group_
->
AddTask
(
2
,
[
&
vec_meta_info
,
p
]
{
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
)
{
(
*
var_ref
)[
i
]
=
vec_meta_info
[
i
].
var_ref_count_
;
}
VLOG
(
4
)
<<
"AtomicVarRef:"
<<
var_ref
<<
" "
<<
(
*
var_ref
).
size
();
p
->
set_value
(
std
::
unique_ptr
<
std
::
vector
<
std
::
atomic
<
size_t
>>>
(
var_ref
));
});
atomic_var_ref_
=
queue_group_
->
AddAwaitableTask
(
kPrepareWorkQueueIdx
,
[
&
vec_meta_info
]
{
auto
var_ref
=
std
::
make_unique
<
std
::
vector
<
std
::
atomic
<
size_t
>>>
(
vec_meta_info
.
size
());
for
(
size_t
i
=
0
;
i
<
vec_meta_info
.
size
();
++
i
)
{
(
*
var_ref
)[
i
]
=
vec_meta_info
[
i
].
var_ref_count_
;
}
VLOG
(
4
)
<<
"AtomicVarRef:"
<<
var_ref
.
get
()
<<
" "
<<
var_ref
->
size
();
return
var_ref
;
});
}
bool
var_can_be_deleted
(
const
std
::
string
&
name
,
const
BlockDesc
&
block
)
{
...
...
paddle/fluid/framework/new_executor/workqueue/thread_data_registry.h
浏览文件 @
63471c83
...
...
@@ -17,6 +17,7 @@
#include <functional>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <thread>
#include <type_traits>
#include <unordered_map>
...
...
@@ -60,16 +61,17 @@ class ThreadDataRegistry {
private:
// types
using
LockType
=
std
::
shared_timed_mutex
;
class
ThreadDataHolder
;
class
ThreadDataRegistryImpl
{
public:
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
;
}
void
UnregisterData
(
uint64_t
tid
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
lock_
);
std
::
lock_guard
<
LockType
>
lock
(
lock_
);
tid_map_
.
erase
(
tid
);
}
...
...
@@ -77,7 +79,7 @@ class ThreadDataRegistry {
std
::
is_copy_constructible
<
Alias
>
::
value
>>
std
::
unordered_map
<
uint64_t
,
T
>
GetAllThreadDataByValue
()
{
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
());
for
(
auto
&
kv
:
tid_map_
)
{
data_copy
.
emplace
(
kv
.
first
,
kv
.
second
->
GetData
());
...
...
@@ -88,7 +90,7 @@ class ThreadDataRegistry {
std
::
unordered_map
<
uint64_t
,
std
::
reference_wrapper
<
T
>>
GetAllThreadDataByRef
()
{
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
());
for
(
auto
&
kv
:
tid_map_
)
{
data_ref
.
emplace
(
kv
.
first
,
std
::
ref
(
kv
.
second
->
GetData
()));
...
...
@@ -97,7 +99,7 @@ class ThreadDataRegistry {
}
private:
std
::
mutex
lock_
;
LockType
lock_
;
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录