Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
f0f4dd1e
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
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看板
未验证
提交
f0f4dd1e
编写于
12月 26, 2022
作者:
R
Ruibiao Chen
提交者:
GitHub
12月 26, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve stream analyzer (#49314)
* Memory search for stream analyzer * Shrink redundant waiters
上级
3d09bd53
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
58 addition
and
11 deletion
+58
-11
paddle/fluid/framework/new_executor/interpreter/stream_analyzer.cc
...uid/framework/new_executor/interpreter/stream_analyzer.cc
+56
-10
paddle/fluid/framework/new_executor/interpreter/stream_analyzer.h
...luid/framework/new_executor/interpreter/stream_analyzer.h
+2
-1
未找到文件。
paddle/fluid/framework/new_executor/interpreter/stream_analyzer.cc
浏览文件 @
f0f4dd1e
...
...
@@ -258,13 +258,15 @@ void StreamAnalyzer::AnalyseAllEventInfo(
const
std
::
vector
<
size_t
>&
next_instr_ids
=
run_type_info
[
cur_instr_id
][
DownstreamRunType
::
kEventRun
];
std
::
set
<
size_t
>
waiter_instr_ids
;
std
::
set
<
size_t
>
visited_next_instr_id
;
for
(
size_t
next_instr_id
:
next_instr_ids
)
{
AnalyseEventInfoForTwoInstructions
(
instructions
,
run_type_info
,
cur_instr_id
,
next_instr_id
,
&
waiter_instr_ids
);
&
waiter_instr_ids
,
&
visited_next_instr_id
);
}
for
(
size_t
waiter_instr_id
:
waiter_instr_ids
)
{
...
...
@@ -302,7 +304,14 @@ void StreamAnalyzer::AnalyseEventInfoForTwoInstructions(
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
size_t
>>>&
run_type_info
,
const
size_t
cur_instr_id
,
const
size_t
next_instr_id
,
std
::
set
<
size_t
>*
waiter_instr_ids
)
const
{
std
::
set
<
size_t
>*
waiter_instr_ids
,
std
::
set
<
size_t
>*
visited_next_instr_id
)
const
{
if
(
visited_next_instr_id
->
find
(
next_instr_id
)
!=
visited_next_instr_id
->
end
())
{
return
;
}
visited_next_instr_id
->
insert
(
next_instr_id
);
// NOTE(Ruibiao): Though depend_op as next_instr is no_need_buffer, we should
// also wait event for it. Because depend_op is used to build dependencies for
// fused vars in some scenarios. In those cases, we do not know which vars may
...
...
@@ -338,21 +347,26 @@ void StreamAnalyzer::AnalyseEventInfoForTwoInstructions(
// between cur_instr and next_instr.
for
(
size_t
instr_id
:
run_type_info
[
next_instr_id
][
DownstreamRunType
::
kDirectRun
])
{
AnalyseEventInfoForTwoInstructions
(
instructions
,
run_type_info
,
cur_instr_id
,
instr_id
,
waiter_instr_ids
);
AnalyseEventInfoForTwoInstructions
(
instructions
,
run_type_info
,
cur_instr_id
,
instr_id
,
waiter_instr_ids
,
visited_next_instr_id
);
}
}
// waiter instr should only wait events for the last recorder instrs in each
// stream
void
StreamAnalyzer
::
ShrinkEventInfo
(
const
DependencyBuilder
&
dependency_builder
,
std
::
map
<
const
DeviceContext
*
,
std
::
map
<
size_t
,
std
::
set
<
size_t
>>>*
event_info
)
const
{
for
(
auto
&
context_item
:
*
event_info
)
{
for
(
auto
&
waiter_item
:
context_item
.
second
)
{
size_t
waiter_instr_id
=
waiter_item
.
first
;
std
::
set
<
size_t
>&
recorder_instr_ids
=
waiter_item
.
second
;
for
(
auto
&
item
:
*
event_info
)
{
// shrink redundant recorders, waiter instrs should only wait for the last
// recorder instrs in each stream
std
::
map
<
size_t
,
std
::
set
<
size_t
>>&
waiter_recorder_map
=
item
.
second
;
for
(
auto
&
waiter_recorder
:
waiter_recorder_map
)
{
size_t
waiter_instr_id
=
waiter_recorder
.
first
;
std
::
set
<
size_t
>&
recorder_instr_ids
=
waiter_recorder
.
second
;
std
::
set
<
size_t
>
unnecessary_recorder_instr_ids
;
for
(
size_t
cur_instr_id
:
recorder_instr_ids
)
{
for
(
size_t
next_instr_id
:
recorder_instr_ids
)
{
...
...
@@ -370,6 +384,38 @@ void StreamAnalyzer::ShrinkEventInfo(
recorder_instr_ids
.
erase
(
unnecessary_recorder_instr_id
);
}
}
// shrink redundant waiters, recorder instrs should only wait by the first
// waiter instrs in each stream
std
::
map
<
size_t
,
std
::
set
<
size_t
>>
recorder_waiter_map
;
for
(
auto
&
waiter_recorder
:
waiter_recorder_map
)
{
size_t
waiter_instr_id
=
waiter_recorder
.
first
;
std
::
set
<
size_t
>&
recorder_instr_ids
=
waiter_recorder
.
second
;
for
(
size_t
record_instr_id
:
recorder_instr_ids
)
{
recorder_waiter_map
[
record_instr_id
].
insert
(
waiter_instr_id
);
}
}
for
(
auto
&
recorder_waiter
:
recorder_waiter_map
)
{
size_t
recorder_instr_id
=
recorder_waiter
.
first
;
std
::
set
<
size_t
>&
waiter_instr_ids
=
recorder_waiter
.
second
;
std
::
set
<
size_t
>
unnecessary_waiter_instr_ids
;
for
(
size_t
cur_instr_id
:
waiter_instr_ids
)
{
for
(
size_t
next_instr_id
:
waiter_instr_ids
)
{
if
(
dependency_builder
.
OpHappensBefore
(
cur_instr_id
,
next_instr_id
))
{
unnecessary_waiter_instr_ids
.
insert
(
next_instr_id
);
break
;
}
}
}
for
(
size_t
unnecessary_wiater_instr_id
:
unnecessary_waiter_instr_ids
)
{
VLOG
(
8
)
<<
"Shrink event : "
<<
recorder_instr_id
<<
" -> "
<<
unnecessary_wiater_instr_id
;
waiter_recorder_map
[
unnecessary_wiater_instr_id
].
erase
(
recorder_instr_id
);
}
}
}
}
...
...
paddle/fluid/framework/new_executor/interpreter/stream_analyzer.h
浏览文件 @
f0f4dd1e
...
...
@@ -64,7 +64,8 @@ class StreamAnalyzer {
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
size_t
>>>&
run_type_info
,
const
size_t
cur_instr_id
,
const
size_t
next_instr_id
,
std
::
set
<
size_t
>*
waiter_instr_ids
)
const
;
std
::
set
<
size_t
>*
waiter_instr_ids
,
std
::
set
<
size_t
>*
visited_next_instr_id
)
const
;
void
ShrinkEventInfo
(
const
DependencyBuilder
&
dependency_builder
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录