Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
0035efa6
MegEngine
项目概览
MegEngine 天元
/
MegEngine
9 个月 前同步成功
通知
392
Star
4702
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,体验更适合开发者的 AI 搜索 >>
提交
0035efa6
编写于
2月 24, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mge): limit task queue size
GitOrigin-RevId: 9481d389140608eaec347bafc7b9b8f180786142
上级
5a1f9134
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
15 deletion
+28
-15
imperative/src/impl/interpreter/interpreter_impl.h
imperative/src/impl/interpreter/interpreter_impl.h
+2
-1
src/core/include/megbrain/utils/thread_impl_0.h
src/core/include/megbrain/utils/thread_impl_0.h
+1
-3
src/core/include/megbrain/utils/thread_impl_1.h
src/core/include/megbrain/utils/thread_impl_1.h
+25
-11
未找到文件。
imperative/src/impl/interpreter/interpreter_impl.h
浏览文件 @
0035efa6
...
...
@@ -120,8 +120,9 @@ private:
// set max_spin=0 to prevent Queue fetch task in busy wait manner.
// this won't affect throughput when python interpreter is sending enough task,
// but will significantly save CPU time when waiting for task, e.g. wait for data input
// limit pending tasks to 1000000
WorkQueue
(
ChannelImpl
*
owner
)
:
AsyncQueueSC
<
IdentifiedCommand
,
WorkQueue
>
(
0
),
m_owner
(
owner
)
{
:
AsyncQueueSC
<
IdentifiedCommand
,
WorkQueue
>
(
0
,
1000000
),
m_owner
(
owner
)
{
sys
::
set_thread_name
(
"interpreter"
);
}
void
process_one_task
(
IdentifiedCommand
&
icmd
)
{
...
...
src/core/include/megbrain/utils/thread_impl_0.h
浏览文件 @
0035efa6
...
...
@@ -55,8 +55,7 @@ namespace mgb {
template
<
typename
Param
,
class
TaskImpl
>
class
AsyncQueueSC
:
public
NonCopyableObj
{
public:
AsyncQueueSC
()
{}
AsyncQueueSC
(
size_t
max_spin
)
{}
AsyncQueueSC
(
ptrdiff_t
max_spin
=
-
1
,
ptrdiff_t
max_items
=
-
1
)
{}
virtual
~
AsyncQueueSC
()
=
default
;
...
...
@@ -91,4 +90,3 @@ namespace mgb {
}
// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}
src/core/include/megbrain/utils/thread_impl_1.h
浏览文件 @
0035efa6
...
...
@@ -156,11 +156,16 @@ namespace mgb {
};
public:
AsyncQueueSC
()
:
m_synchronizer
(
SCQueueSynchronizer
::
get_default_max_spin
())
{}
//! specify max spin manually, caller must ensure the given value is optimal,
//! otherwise caller should leave the value adjustable by user.
AsyncQueueSC
(
size_t
max_spin
)
:
m_synchronizer
(
max_spin
)
{}
//! \param max_spin specify max spin manually, caller must ensure the given value
//! is optimal, otherwise caller should leave the value adjustable by user.
//! \param max_items limit memory usage by number of items
AsyncQueueSC
(
ptrdiff_t
max_spin
=
-
1
,
ptrdiff_t
max_items
=
-
1
)
:
m_synchronizer
(
max_spin
>=
0
?
max_spin
:
SCQueueSynchronizer
::
get_default_max_spin
())
{
if
(
max_items
>=
0
)
{
// -1 / 2 == 0
m_block_quota
=
(
max_items
-
1
)
/
BLOCK_SIZE
+
1
;
}
}
#ifdef WIN32
bool
check_is_into_atexit
()
{
if
(
SCQueueSynchronizer
::
is_into_atexit
)
{
...
...
@@ -290,8 +295,10 @@ namespace mgb {
TaskBlock
*
m_queue_tail
=
nullptr
;
std
::
atomic_size_t
m_queue_tail_tid
{
0
},
//!< id of next task
m_finished_task
{
0
};
size_t
m_block_quota
=
std
::
numeric_limits
<
size_t
>::
max
();
std
::
vector
<
std
::
unique_ptr
<
TaskBlock
>>
m_free_task_block
;
Spinlock
m_mutex
;
std
::
condition_variable_any
m_cv
;
SyncedParam
*
m_cur_task
=
nullptr
;
SCQueueSynchronizer
m_synchronizer
;
#if MGB_ENABLE_EXCEPTION
...
...
@@ -354,12 +361,18 @@ namespace mgb {
std
::
unique_ptr
<
TaskBlock
>
allocate_task_block_unsafe
(
TaskBlock
*
prev
)
{
std
::
unique_ptr
<
TaskBlock
>
ret
;
if
(
!
m_free_task_block
.
empty
())
{
ret
=
std
::
move
(
m_free_task_block
.
back
());
m_free_task_block
.
pop_back
();
}
else
{
ret
=
std
::
make_unique
<
TaskBlock
>
();
}
do
{
if
(
!
m_free_task_block
.
empty
())
{
ret
=
std
::
move
(
m_free_task_block
.
back
());
m_free_task_block
.
pop_back
();
}
else
if
(
m_block_quota
>
0
)
{
ret
=
std
::
make_unique
<
TaskBlock
>
();
m_block_quota
--
;
}
else
{
m_cv
.
wait
(
m_mutex
);
continue
;
}
}
while
(
false
);
ret
->
first_tid
=
m_new_block_first_tid
;
m_new_block_first_tid
+=
BLOCK_SIZE
;
ret
->
prev
=
prev
;
...
...
@@ -402,6 +415,7 @@ namespace mgb {
}
else
{
m_queue_tail
=
nullptr
;
}
m_cv
.
notify_one
();
}
SyncedParam
&
cur
=
m_queue_head
->
params
[
qh
++
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录