Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
95a30eb6
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
403
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看板
提交
95a30eb6
编写于
3月 24, 2022
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
perf(imperative): speed up stackmanager guard
GitOrigin-RevId: 12d23b6f7ea00f852d3a7d0641bb723ada50cb3a
上级
f7a5fe17
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
13 deletion
+26
-13
imperative/src/impl/interpreter/interpreter_impl.cpp
imperative/src/impl/interpreter/interpreter_impl.cpp
+24
-12
imperative/src/impl/interpreter/stack_manager.h
imperative/src/impl/interpreter/stack_manager.h
+1
-0
imperative/src/include/megbrain/imperative/utils/stats.h
imperative/src/include/megbrain/imperative/utils/stats.h
+1
-1
未找到文件。
imperative/src/impl/interpreter/interpreter_impl.cpp
浏览文件 @
95a30eb6
...
...
@@ -138,8 +138,11 @@ Interpreter& Interpreter::inst() {
Handle
ChannelImpl
::
put
(
const
HostTensorND
&
value
,
bool
no_cache
)
{
MGB_LOCK_GUARD
(
m_spin
);
mgb_assert
(
check_available
(),
"Channel already closed"
);
auto
&
state
=
get_channel_state
();
auto
_
=
StackManager
::
Guard
{
"Put"
,
&
state
.
stack_manager
};
std
::
optional
<
StackManager
::
Guard
>
guard
;
if
(
Profiler
::
is_profiling
())
{
auto
&
state
=
get_channel_state
();
guard
.
emplace
(
"Put"
,
&
state
.
stack_manager
);
}
auto
info
=
put_impl
(
value
,
no_cache
);
return
reinterpret_cast
<
Handle
>
(
info
);
}
...
...
@@ -183,8 +186,11 @@ Handle ChannelImpl::put(const DeviceTensorND& data, const HostTensorND& hvalue)
}
TensorInfo
*
ChannelImpl
::
put_impl
(
const
DeviceTensorND
&
data
,
const
HostTensorND
&
hvalue
)
{
auto
&
state
=
get_channel_state
();
auto
_
=
StackManager
::
Guard
{
"Put"
,
&
state
.
stack_manager
};
std
::
optional
<
StackManager
::
Guard
>
guard
;
if
(
Profiler
::
is_profiling
())
{
auto
&
state
=
get_channel_state
();
guard
.
emplace
(
"Put"
,
&
state
.
stack_manager
);
}
auto
info
=
alloc
();
MGB_RECORD_EVENT
(
TensorCommandEvent
,
info
->
id
,
TensorCommandKind
::
Put
);
constexpr
int
size_threshold
=
TensorShape
::
MAX_NDIM
;
...
...
@@ -253,8 +259,10 @@ void ChannelImpl::dispatch_default_cpu(
SmallVector
<
Handle
>*
outputs
)
{
auto
&
state
=
get_channel_state
();
auto
name
=
op
->
trait
()
->
make_name
(
*
op
);
auto
_
=
StackManager
::
Guard
(
name
,
&
state
.
stack_manager
);
std
::
optional
<
StackManager
::
Guard
>
guard
;
if
(
Profiler
::
is_profiling
())
{
guard
.
emplace
(
op
->
trait
()
->
make_name
(
*
op
),
&
state
.
stack_manager
);
}
auto
[
output_descs
,
validated
]
=
OpDef
::
infer_output_attrs_fallible
(
*
op
,
input_descs
);
...
...
@@ -329,8 +337,9 @@ void ChannelImpl::dispatch_default_cpu(
return
op_info
;
};
MGB_RECORD_EVENT
(
OpDispatchEvent
,
op_id
,
name
,
op_info_getter
,
tinfo_to_tid
(
input_infos
),
tinfo_to_tid
(
output_infos
),
state
.
stack_manager
.
dump
());
OpDispatchEvent
,
op_id
,
guard
.
value
().
name
(),
op_info_getter
,
tinfo_to_tid
(
input_infos
),
tinfo_to_tid
(
output_infos
),
state
.
stack_manager
.
dump
());
}
void
ChannelImpl
::
dispatch_kernel
(
...
...
@@ -340,8 +349,10 @@ void ChannelImpl::dispatch_kernel(
auto
&
state
=
get_channel_state
();
auto
&
options
=
state
.
options
;
auto
name
=
op
->
trait
()
->
make_name
(
*
op
);
auto
_
=
StackManager
::
Guard
{
name
,
&
state
.
stack_manager
};
std
::
optional
<
StackManager
::
Guard
>
guard
;
if
(
Profiler
::
is_profiling
())
{
guard
.
emplace
(
op
->
trait
()
->
make_name
(
*
op
),
&
state
.
stack_manager
);
}
auto
[
output_descs
,
validated
]
=
OpDef
::
infer_output_attrs_fallible
(
*
op
,
input_descs
);
...
...
@@ -376,8 +387,9 @@ void ChannelImpl::dispatch_kernel(
return
op_info
;
};
MGB_RECORD_EVENT
(
OpDispatchEvent
,
cmd
.
id
,
name
,
op_info_getter
,
tinfo_to_tid
(
cmd
.
inputs
),
tinfo_to_tid
(
cmd
.
outputs
),
state
.
stack_manager
.
dump
());
OpDispatchEvent
,
cmd
.
id
,
guard
.
value
().
name
(),
op_info_getter
,
tinfo_to_tid
(
cmd
.
inputs
),
tinfo_to_tid
(
cmd
.
outputs
),
state
.
stack_manager
.
dump
());
m_worker
.
add_task
(
{
Profiler
::
next_id
(),
std
::
move
(
cmd
),
get_channel_state
().
stack_manager
.
dump
()});
...
...
imperative/src/impl/interpreter/stack_manager.h
浏览文件 @
95a30eb6
...
...
@@ -98,6 +98,7 @@ public:
m_manager
->
enter
(
name
);
}
}
std
::
string
name
()
const
{
return
m_name
;
}
~
Guard
()
{
release
();
}
void
release
()
{
if
(
m_manager
)
{
...
...
imperative/src/include/megbrain/imperative/utils/stats.h
浏览文件 @
95a30eb6
...
...
@@ -186,7 +186,7 @@ inline stats::Timer::Timer(std::string name, bool default_enabled)
}
#if MGE_ENABLE_STATS
#define MGE_TIMER_SCOPE(name) auto name = Stats::name.time_scope()
#define MGE_TIMER_SCOPE(name) auto name = Stats::name.time_scope
_recursive
()
#define MGE_TIMER_SCOPE_RELEASE(name) name.release()
#define MGE_TIMER_SCOPE_ENABLE(name) auto name = Stats::name.enable_scope()
#else
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录