Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
5cb35c1b
MegEngine
项目概览
MegEngine 天元
/
MegEngine
大约 1 年 前同步成功
通知
399
Star
4705
Fork
582
代码
文件
提交
分支
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5cb35c1b
编写于
5月 15, 2021
作者:
M
Megvii Engine Team
提交者:
huangxinda
7月 19, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(profiler): add state structs to replay recorded events
GitOrigin-RevId: 16a1f5d7ba85c8be19d75d0314331134bd63bb8e
上级
84fc5c92
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
153 addition
and
0 deletion
+153
-0
imperative/src/impl/profiler/states.h
imperative/src/impl/profiler/states.h
+153
-0
未找到文件。
imperative/src/impl/profiler/states.h
0 → 100644
浏览文件 @
5cb35c1b
#pragma once
#include <set>
#include <any>
#include <typeindex>
#include "megbrain/tensor.h"
namespace
mgb
::
imperative
::
profiler
{
struct
ProfileDeviceState
{
int64_t
index
;
CompNode
device
;
std
::
shared_ptr
<
CompNode
::
Event
>
base_event
;
uint64_t
base_time
;
//in ns
};
struct
ProfileWorkerState
{
};
struct
ProfileTensorState
{
uint64_t
id
;
TensorLayout
layout
;
CompNode
device
;
std
::
string
name
;
uint64_t
produced
=
0
;
uint64_t
living_time
=
0
;
size_t
size_in_bytes
()
const
{
if
(
!
layout
.
dtype
.
valid
())
{
return
0
;
}
return
layout
.
dtype
.
size
(
layout
.
total_nr_elems
());
}
};
struct
ProfileStaticsState
{
size_t
op_enqueue_count
=
0
;
size_t
op_execute_count
=
0
;
size_t
wait_value_count
=
0
;
size_t
wait_shape_count
=
0
;
size_t
exception_count
=
0
;
size_t
infer_shape_valid_count
=
0
;
size_t
infer_shape_invalid_count
=
0
;
size_t
alive_tensor_count
=
0
;
size_t
produce_tensor_count
=
0
;
size_t
erase_tensor_count
=
0
;
size_t
wait_prop_count
=
0
;
size_t
redundant_tensor_count
=
0
;
};
struct
ProfileOperatorState
{
uint64_t
id
;
std
::
string
name
;
SmallVector
<
uint64_t
>
inputs
;
SmallVector
<
uint64_t
>
outputs
;
CompNode
device
;
uint64_t
host_begin
;
uint64_t
host_end
;
std
::
shared_ptr
<
CompNode
::
Event
>
device_begin
;
std
::
shared_ptr
<
CompNode
::
Event
>
device_end
;
};
struct
ProfileThreadState
{
std
::
thread
::
id
tid
;
int64_t
index
;
std
::
vector
<
std
::
string
>
scope_stack
;
};
template
<
typename
TProp
>
struct
ProfileTensorPropPair
{
uint64_t
id
;
TProp
value
;
bool
operator
<
(
const
ProfileTensorPropPair
&
lhs
)
const
{
return
value
==
lhs
.
value
?
id
<
lhs
.
id
:
value
<
lhs
.
value
;
}
bool
operator
==
(
const
ProfileTensorPropPair
&
lhs
)
const
{
return
id
==
lhs
.
id
&&
value
==
lhs
.
value
;
}
bool
operator
>
(
const
ProfileTensorPropPair
&
lhs
)
const
{
return
value
==
lhs
.
value
?
id
>
lhs
.
id
:
value
>
lhs
.
value
;
}
};
using
ProfileTensorSizePair
=
ProfileTensorPropPair
<
size_t
>
;
using
ProfileTensorProducedPair
=
ProfileTensorPropPair
<
uint64_t
>
;
struct
GeneralTensorEvent
{
uint64_t
tensor_id
;
std
::
type_index
type
;
};
struct
ProfileState
{
std
::
unordered_map
<
uint64_t
,
ProfileTensorState
>
tensors
;
std
::
unordered_map
<
uint64_t
,
ProfileOperatorState
>
operators
;
std
::
unordered_map
<
std
::
string
,
uint64_t
>
tensor_name_counter
;
std
::
set
<
ProfileTensorSizePair
>
tensors_by_size
;
std
::
set
<
ProfileTensorSizePair
>
tensors_by_produced
;
ProfileWorkerState
worker
;
ProfileStaticsState
statics
;
std
::
unordered_map
<
std
::
thread
::
id
,
ProfileThreadState
>
threads
;
CompNode
::
UnorderedMap
<
ProfileDeviceState
>
devices
;
ProfileThreadState
&
operator
[](
std
::
thread
::
id
tid
)
{
if
(
threads
.
count
(
tid
)
==
0
)
{
threads
[
tid
].
tid
=
tid
;
threads
[
tid
].
index
=
threads
.
size
();
}
return
threads
[
tid
];
}
ProfileDeviceState
&
operator
[](
CompNode
device
)
{
if
(
devices
.
count
(
device
)
==
0
)
{
devices
[
device
].
device
=
device
;
devices
[
device
].
index
=
devices
.
size
();
}
return
devices
[
device
];
}
std
::
vector
<
uint64_t
>
top_k_tensor_in_device
(
CompNode
device
,
size_t
k
)
{
std
::
vector
<
uint64_t
>
results
;
for
(
auto
iter
=
tensors_by_size
.
rbegin
();
iter
!=
tensors_by_size
.
rend
();
++
iter
)
{
if
(
!
k
)
{
break
;
}
if
(
tensors
[
iter
->
id
].
device
==
device
)
{
results
.
push_back
(
iter
->
id
);
--
k
;
}
}
return
results
;
}
std
::
string
concat_scope
(
std
::
thread
::
id
tid
)
{
auto
&
scope_stack
=
threads
[
tid
].
scope_stack
;
if
(
scope_stack
.
empty
())
{
return
{};
}
std
::
string
result
=
scope_stack
[
0
];
for
(
size_t
i
=
1
;
i
<
scope_stack
.
size
();
++
i
)
{
result
+=
"::"
;
result
+=
scope_stack
[
i
];
}
return
result
;
}
};
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录