Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
8fddd808
MegEngine
项目概览
MegEngine 天元
/
MegEngine
接近 2 年 前同步成功
通知
414
Star
4708
Fork
583
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
8fddd808
编写于
7月 01, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(profiler): respect record_device option
GitOrigin-RevId: 7c9a8cfba773061218fa3cda98fcc305333e7945
上级
59d59766
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
25 addition
and
20 deletion
+25
-20
imperative/src/impl/interpreter/interpreter_impl.cpp
imperative/src/impl/interpreter/interpreter_impl.cpp
+5
-5
imperative/src/impl/profiler/chrome_timeline.cpp
imperative/src/impl/profiler/chrome_timeline.cpp
+2
-0
imperative/src/impl/profiler_plugin.cpp
imperative/src/impl/profiler_plugin.cpp
+13
-15
imperative/src/include/megbrain/imperative/profiler.h
imperative/src/include/megbrain/imperative/profiler.h
+5
-0
未找到文件。
imperative/src/impl/interpreter/interpreter_impl.cpp
浏览文件 @
8fddd808
...
@@ -724,14 +724,14 @@ void ChannelImpl::do_apply_op(const ApplyOp& cmd) {
...
@@ -724,14 +724,14 @@ void ChannelImpl::do_apply_op(const ApplyOp& cmd) {
// Before execute
// Before execute
for
(
auto
&&
[
device
,
kernel_id
]
:
kernels
)
{
for
(
auto
&&
[
device
,
kernel_id
]
:
kernels
)
{
MGB_RECORD_EVENT
(
KernelLaunchEvent
,
apply_id
,
kernel_id
,
device
);
MGB_RECORD_EVENT
(
KernelLaunchEvent
,
apply_id
,
kernel_id
,
device
);
MGB_RECORD_EVENT
(
RecordDeviceEvent
,
Timer
::
record_device
(
device
));
MGB_RECORD_EVENT
_IF
((
Profiler
::
get_option
(
"profile_device"
,
0
)),
RecordDeviceEvent
,
Timer
::
record_device
(
device
));
}
}
// Apply op
// Apply op
// Here std::move is REQUIRED for removing duplicated references.
// Here std::move is REQUIRED for removing duplicated references.
auto
outputs
=
apply_on_physical_tensor
(
apply_on_physical_tensor
,
*
cmd
.
op
,
inputs
);
auto
outputs
=
apply_on_physical_tensor
(
apply_on_physical_tensor
,
*
cmd
.
op
,
inputs
);
// After execute
// After execute
for
(
auto
&&
[
device
,
kernel_id
]
:
kernels
)
{
for
(
auto
&&
[
device
,
kernel_id
]
:
kernels
)
{
MGB_RECORD_EVENT
(
RecordDeviceEvent
,
Timer
::
record_device
(
device
));
MGB_RECORD_EVENT
_IF
((
Profiler
::
get_option
(
"profile_device"
,
0
)),
RecordDeviceEvent
,
Timer
::
record_device
(
device
));
MGB_RECORD_EVENT
(
KernelLaunchFinishEvent
,
apply_id
,
kernel_id
,
device
);
MGB_RECORD_EVENT
(
KernelLaunchFinishEvent
,
apply_id
,
kernel_id
,
device
);
}
}
// End profiling operator
// End profiling operator
...
@@ -1009,9 +1009,9 @@ void ChannelImpl::process_one_task(Command& icmd) {
...
@@ -1009,9 +1009,9 @@ void ChannelImpl::process_one_task(Command& icmd) {
using
T
=
std
::
decay_t
<
decltype
(
cmd
)
>
;
using
T
=
std
::
decay_t
<
decltype
(
cmd
)
>
;
if
constexpr
(
std
::
is_same_v
<
T
,
Put
>
)
{
if
constexpr
(
std
::
is_same_v
<
T
,
Put
>
)
{
MGB_RECORD_EVENT
(
TensorCommandEvent
,
cmd
.
dest
->
id
,
TensorCommandKind
::
Put
);
MGB_RECORD_EVENT
(
TensorCommandEvent
,
cmd
.
dest
->
id
,
TensorCommandKind
::
Put
);
MGB_RECORD_EVENT
(
RecordDeviceEvent
,
Timer
::
record_device
(
cmd
.
value
.
comp_node
()));
MGB_RECORD_EVENT
_IF
((
Profiler
::
get_option
(
"profile_device"
,
0
)),
RecordDeviceEvent
,
Timer
::
record_device
(
cmd
.
value
.
comp_node
()));
auto
value
=
cmd
.
no_cache
?
std
::
make_shared
<
Tensor
>
(
cmd
.
value
)
:
Tensor
::
make
(
cmd
.
value
);
auto
value
=
cmd
.
no_cache
?
std
::
make_shared
<
Tensor
>
(
cmd
.
value
)
:
Tensor
::
make
(
cmd
.
value
);
MGB_RECORD_EVENT
(
RecordDeviceEvent
,
Timer
::
record_device
(
cmd
.
value
.
comp_node
()));
MGB_RECORD_EVENT
_IF
((
Profiler
::
get_option
(
"profile_device"
,
0
)),
RecordDeviceEvent
,
Timer
::
record_device
(
cmd
.
value
.
comp_node
()));
produce_tensor
(
cmd
.
dest
,
std
::
move
(
value
));
produce_tensor
(
cmd
.
dest
,
std
::
move
(
value
));
MGB_RECORD_EVENT
(
TensorCommandFinishEvent
,
cmd
.
dest
->
id
,
TensorCommandKind
::
Put
);
MGB_RECORD_EVENT
(
TensorCommandFinishEvent
,
cmd
.
dest
->
id
,
TensorCommandKind
::
Put
);
sample_on_device
(
cmd
.
dest
->
desc
.
comp_node
,
false
);
sample_on_device
(
cmd
.
dest
->
desc
.
comp_node
,
false
);
...
@@ -1136,7 +1136,7 @@ void ChannelImpl::process_one_task(Command& icmd) {
...
@@ -1136,7 +1136,7 @@ void ChannelImpl::process_one_task(Command& icmd) {
if
(
Profiler
::
get_option
(
"sample_rate"
,
0
))
{
if
(
Profiler
::
get_option
(
"sample_rate"
,
0
))
{
sample_on_device
(
device
,
true
);
sample_on_device
(
device
,
true
);
}
}
MGB_RECORD_EVENT
(
RecordDeviceEvent
,
Timer
::
record_device
(
device
));
MGB_RECORD_EVENT
_IF
((
Profiler
::
get_option
(
"profile_device"
,
0
)),
RecordDeviceEvent
,
Timer
::
record_device
(
device
));
});
});
MGB_RECORD_EVENT
(
StartProfileFinishEvent
);
MGB_RECORD_EVENT
(
StartProfileFinishEvent
);
}
else
if
constexpr
(
std
::
is_same_v
<
T
,
StopProfile
>
)
{
}
else
if
constexpr
(
std
::
is_same_v
<
T
,
StopProfile
>
)
{
...
...
imperative/src/impl/profiler/chrome_timeline.cpp
浏览文件 @
8fddd808
...
@@ -302,6 +302,8 @@ struct ChromeTimelineEventVisitor: EventVisitor<ChromeTimelineEventVisitor> {
...
@@ -302,6 +302,8 @@ struct ChromeTimelineEventVisitor: EventVisitor<ChromeTimelineEventVisitor> {
}
else
if
constexpr
(
std
::
is_same_v
<
TEvent
,
TensorGetPropEvent
>
)
{
}
else
if
constexpr
(
std
::
is_same_v
<
TEvent
,
TensorGetPropEvent
>
)
{
new_host_event
(
"TensorGetProp"
,
'X'
)
new_host_event
(
"TensorGetProp"
,
'X'
)
.
dur
(
0
).
args
(
current_tensor
->
detail
(
current
->
time
));
.
dur
(
0
).
args
(
current_tensor
->
detail
(
current
->
time
));
}
else
if
constexpr
(
std
::
is_same_v
<
TEvent
,
TensorWaitPropEvent
>
)
{
new_host_event
(
"TensorWaitProp"
,
'B'
);
}
else
if
constexpr
(
std
::
is_same_v
<
TEvent
,
TensorWaitPropFinishEvent
>
)
{
}
else
if
constexpr
(
std
::
is_same_v
<
TEvent
,
TensorWaitPropFinishEvent
>
)
{
new_host_event
(
pid_str
,
'f'
)
new_host_event
(
pid_str
,
'f'
)
.
id
(
event
.
tensor_id
)
.
id
(
event
.
tensor_id
)
...
...
imperative/src/impl/profiler_plugin.cpp
浏览文件 @
8fddd808
...
@@ -26,7 +26,7 @@ ProfilerPlugin::ProfilerPlugin(cg::ComputingGraph* graph): PluginBase(graph) {
...
@@ -26,7 +26,7 @@ ProfilerPlugin::ProfilerPlugin(cg::ComputingGraph* graph): PluginBase(graph) {
// reset
// reset
mgb_assert
(
!
event
.
graph
->
options
().
imperative_proxy_graph
);
mgb_assert
(
!
event
.
graph
->
options
().
imperative_proxy_graph
);
CompNode
::
foreach
([](
CompNode
device
){
CompNode
::
foreach
([](
CompNode
device
){
Profiler
::
record
<
RecordDeviceEvent
>
(
Timer
::
record_device
(
device
));
MGB_RECORD_EVENT_IF
((
Profiler
::
get_option
(
"profile_device"
,
0
)),
RecordDeviceEvent
,
Timer
::
record_device
(
device
));
});
});
if
(
m_opr_dict
.
empty
()
&&
m_var_dict
.
empty
())
{
if
(
m_opr_dict
.
empty
()
&&
m_var_dict
.
empty
())
{
init_seq
(
event
.
exec
);
init_seq
(
event
.
exec
);
...
@@ -47,22 +47,21 @@ ProfilerPlugin::ProfilerPlugin(cg::ComputingGraph* graph): PluginBase(graph) {
...
@@ -47,22 +47,21 @@ ProfilerPlugin::ProfilerPlugin(cg::ComputingGraph* graph): PluginBase(graph) {
Profiler
::
record
<
ScopeEvent
>
(
"DispatchOprs"
);
Profiler
::
record
<
ScopeEvent
>
(
"DispatchOprs"
);
event
.
exec
->
iter_opr_seq
([
this
](
OperatorNodeBase
*
opr
)
->
bool
{
event
.
exec
->
iter_opr_seq
([
this
](
OperatorNodeBase
*
opr
)
->
bool
{
auto
&
opr_info
=
get_opr_info
(
opr
);
auto
&
opr_info
=
get_opr_info
(
opr
);
SmallVector
<
uint64_t
>
inputs
;
for
(
auto
input
:
opr
->
input
())
{
inputs
.
push_back
(
get_var_info
(
input
).
id
);
}
SmallVector
<
uint64_t
>
outputs
;
for
(
auto
output
:
opr
->
output
())
{
for
(
auto
output
:
opr
->
output
())
{
outputs
.
push_back
(
get_var_info
(
output
).
id
);
auto
&
var_id
=
get_var_info
(
output
).
id
;
var_id
=
Profiler
::
next_id
();
Profiler
::
record
<
TensorDeclareEvent
>
(
var_id
,
output
->
name
());
}
}
auto
opr_name
=
opr
->
dyn_typeinfo
()
->
name
;
auto
opr_name
=
opr
->
dyn_typeinfo
()
->
name
;
auto
copy_params
=
[
params
=
opr_info
.
params
]
{
return
*
params
;
};
auto
copy_params
=
[
params
=
opr_info
.
params
]
{
return
*
params
;
};
SmallVector
<
uint64_t
>
inputs
,
outputs
;
for
(
auto
input
:
opr
->
input
())
{
inputs
.
push_back
(
get_var_info
(
input
).
id
);
}
for
(
auto
output
:
opr
->
output
())
{
for
(
auto
output
:
opr
->
output
())
{
auto
&
var_id
=
get_var_info
(
output
).
id
;
outputs
.
push_back
(
get_var_info
(
output
).
id
);
var_id
=
Profiler
::
next_id
();
Profiler
::
record
<
TensorDeclareEvent
>
(
var_id
,
output
->
name
());
}
}
Profiler
::
record
<
OpDispatchEvent
>
(
opr_info
.
id
,
opr_name
,
copy_params
,
inputs
,
outputs
);
Profiler
::
record
<
OpDispatchEvent
>
(
opr_info
.
id
=
Profiler
::
next_id
()
,
opr_name
,
copy_params
,
inputs
,
outputs
);
return
true
;
return
true
;
});
});
Profiler
::
record
<
ScopeFinishEvent
>
(
"DispatchOprs"
);
Profiler
::
record
<
ScopeFinishEvent
>
(
"DispatchOprs"
);
...
@@ -128,12 +127,12 @@ ProfilerPlugin::ProfilerPlugin(cg::ComputingGraph* graph): PluginBase(graph) {
...
@@ -128,12 +127,12 @@ ProfilerPlugin::ProfilerPlugin(cg::ComputingGraph* graph): PluginBase(graph) {
auto
on_before_kern
=
[
this
](
BeforeKernel
const
&
event
)
{
auto
on_before_kern
=
[
this
](
BeforeKernel
const
&
event
)
{
OperatorNodeBase
*
opr
=
event
.
opr
;
OperatorNodeBase
*
opr
=
event
.
opr
;
Profiler
::
record
<
KernelLaunchEvent
>
(
get_opr_info
(
opr
).
id
,
get_opr_info
(
opr
).
id
,
event
.
comp_node
);
Profiler
::
record
<
KernelLaunchEvent
>
(
get_opr_info
(
opr
).
id
,
get_opr_info
(
opr
).
id
,
event
.
comp_node
);
Profiler
::
record
<
RecordDeviceEvent
>
(
Timer
::
record_device
(
event
.
comp_node
));
MGB_RECORD_EVENT_IF
((
Profiler
::
get_option
(
"profile_device"
,
0
)),
RecordDeviceEvent
,
Timer
::
record_device
(
event
.
comp_node
));
};
};
auto
on_after_kern
=
[
this
](
AfterKernel
const
&
event
)
{
auto
on_after_kern
=
[
this
](
AfterKernel
const
&
event
)
{
OperatorNodeBase
*
opr
=
event
.
opr
;
OperatorNodeBase
*
opr
=
event
.
opr
;
Profiler
::
record
<
RecordDeviceEvent
>
(
Timer
::
record_device
(
event
.
comp_node
));
MGB_RECORD_EVENT_IF
((
Profiler
::
get_option
(
"profile_device"
,
0
)),
RecordDeviceEvent
,
Timer
::
record_device
(
event
.
comp_node
));
Profiler
::
record
<
KernelLaunchEvent
>
(
get_opr_info
(
opr
).
id
,
get_opr_info
(
opr
).
id
,
event
.
comp_node
);
Profiler
::
record
<
KernelLaunch
Finish
Event
>
(
get_opr_info
(
opr
).
id
,
get_opr_info
(
opr
).
id
,
event
.
comp_node
);
};
};
auto
on_graph_compile
=
[
this
](
const
CompSeqOrderDetermined
&
)
{
auto
on_graph_compile
=
[
this
](
const
CompSeqOrderDetermined
&
)
{
m_opr_dict
.
clear
();
m_opr_dict
.
clear
();
...
@@ -182,7 +181,6 @@ void ProfilerPlugin::init_seq(cg::AsyncExecutable *comp_seq) {
...
@@ -182,7 +181,6 @@ void ProfilerPlugin::init_seq(cg::AsyncExecutable *comp_seq) {
ProfilerPlugin
::
OprInfo
&
ProfilerPlugin
::
register_opr
(
cg
::
OperatorNodeBase
*
opr
)
{
ProfilerPlugin
::
OprInfo
&
ProfilerPlugin
::
register_opr
(
cg
::
OperatorNodeBase
*
opr
)
{
OprInfo
info
;
OprInfo
info
;
info
.
id
=
Profiler
::
next_id
();
auto
params
=
std
::
make_shared
<
std
::
unordered_map
<
std
::
string
,
std
::
string
>>
();
auto
params
=
std
::
make_shared
<
std
::
unordered_map
<
std
::
string
,
std
::
string
>>
();
auto
params_json
=
opr
->
to_json
();
auto
params_json
=
opr
->
to_json
();
for
(
auto
&&
[
k
,
v
]
:
params_json
->
cast_final
<
json
::
Object
>
().
get_impl
())
{
for
(
auto
&&
[
k
,
v
]
:
params_json
->
cast_final
<
json
::
Object
>
().
get_impl
())
{
...
...
imperative/src/include/megbrain/imperative/profiler.h
浏览文件 @
8fddd808
...
@@ -233,5 +233,10 @@ public:
...
@@ -233,5 +233,10 @@ public:
mgb::imperative::Profiler::record<type>(type{__VA_ARGS__}); \
mgb::imperative::Profiler::record<type>(type{__VA_ARGS__}); \
} \
} \
#define MGB_RECORD_EVENT_IF(expr, type, ...) \
if (mgb::imperative::Profiler::is_profiling() && (expr)) { \
mgb::imperative::Profiler::record<type>(type{__VA_ARGS__}); \
} \
}
// namespace imperative
}
// namespace imperative
}
// namespace mgb
}
// namespace mgb
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录