Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
c8a9094b
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,发现更多精彩内容 >>
提交
c8a9094b
编写于
6月 29, 2020
作者:
M
Megvii Engine Team
提交者:
Xu Xinran
7月 06, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mge/data/dataloader): add refcount in _PlasmaStoreManager
GitOrigin-RevId: 9a95cb1a5d82dcb20a43493bfc59dd0100ca85f4
上级
05682707
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
55 addition
and
1 deletion
+55
-1
python_module/megengine/data/_queue.py
python_module/megengine/data/_queue.py
+6
-1
python_module/test/unit/data/test_dataloader.py
python_module/test/unit/data/test_dataloader.py
+49
-0
未找到文件。
python_module/megengine/data/_queue.py
浏览文件 @
c8a9094b
...
@@ -26,7 +26,7 @@ def _clear_plasma_store():
...
@@ -26,7 +26,7 @@ def _clear_plasma_store():
# `_PlasmaStoreManager.__del__` will not be called automaticly in subprocess,
# `_PlasmaStoreManager.__del__` will not be called automaticly in subprocess,
# so this function should be called explicitly
# so this function should be called explicitly
global
MGE_PLASMA_STORE_MANAGER
global
MGE_PLASMA_STORE_MANAGER
if
MGE_PLASMA_STORE_MANAGER
is
not
None
:
if
MGE_PLASMA_STORE_MANAGER
is
not
None
and
MGE_PLASMA_STORE_MANAGER
.
refcount
==
0
:
del
MGE_PLASMA_STORE_MANAGER
del
MGE_PLASMA_STORE_MANAGER
MGE_PLASMA_STORE_MANAGER
=
None
MGE_PLASMA_STORE_MANAGER
=
None
...
@@ -50,6 +50,7 @@ class _PlasmaStoreManager:
...
@@ -50,6 +50,7 @@ class _PlasmaStoreManager:
stderr
=
None
if
debug_flag
else
subprocess
.
DEVNULL
,
stderr
=
None
if
debug_flag
else
subprocess
.
DEVNULL
,
)
)
self
.
__initialized
=
True
self
.
__initialized
=
True
self
.
refcount
=
1
def
__del__
(
self
):
def
__del__
(
self
):
if
self
.
__initialized
and
self
.
plasma_store
.
returncode
is
None
:
if
self
.
__initialized
and
self
.
plasma_store
.
returncode
is
None
:
...
@@ -83,6 +84,8 @@ class PlasmaShmQueue:
...
@@ -83,6 +84,8 @@ class PlasmaShmQueue:
"Exception happened in starting plasma_store: {}
\n
"
"Exception happened in starting plasma_store: {}
\n
"
"Tips: {}"
.
format
(
str
(
e
),
err_info
)
"Tips: {}"
.
format
(
str
(
e
),
err_info
)
)
)
else
:
MGE_PLASMA_STORE_MANAGER
.
refcount
+=
1
self
.
socket_name
=
MGE_PLASMA_STORE_MANAGER
.
socket_name
self
.
socket_name
=
MGE_PLASMA_STORE_MANAGER
.
socket_name
...
@@ -133,6 +136,8 @@ class PlasmaShmQueue:
...
@@ -133,6 +136,8 @@ class PlasmaShmQueue:
def
close
(
self
):
def
close
(
self
):
self
.
queue
.
close
()
self
.
queue
.
close
()
self
.
disconnect_client
()
self
.
disconnect_client
()
global
MGE_PLASMA_STORE_MANAGER
MGE_PLASMA_STORE_MANAGER
.
refcount
-=
1
_clear_plasma_store
()
_clear_plasma_store
()
def
cancel_join_thread
(
self
):
def
cancel_join_thread
(
self
):
...
...
python_module/test/unit/data/test_dataloader.py
浏览文件 @
c8a9094b
...
@@ -132,3 +132,52 @@ def test_dataloader_parallel_worker_exception():
...
@@ -132,3 +132,52 @@ def test_dataloader_parallel_worker_exception():
with
pytest
.
raises
(
RuntimeError
,
match
=
r
"worker.*died"
):
with
pytest
.
raises
(
RuntimeError
,
match
=
r
"worker.*died"
):
data_iter
=
iter
(
dataloader
)
data_iter
=
iter
(
dataloader
)
batch_data
=
next
(
data_iter
)
batch_data
=
next
(
data_iter
)
def
_multi_instances_parallel_dataloader_worker
():
dataset
=
init_dataset
()
for
divide_flag
in
[
True
,
False
]:
train_dataloader
=
DataLoader
(
dataset
,
sampler
=
RandomSampler
(
dataset
,
batch_size
=
4
,
drop_last
=
False
),
num_workers
=
2
,
divide
=
divide_flag
,
)
val_dataloader
=
DataLoader
(
dataset
,
sampler
=
RandomSampler
(
dataset
,
batch_size
=
10
,
drop_last
=
False
),
num_workers
=
2
,
divide
=
divide_flag
,
)
for
idx
,
(
data
,
label
)
in
enumerate
(
train_dataloader
):
assert
data
.
shape
==
(
4
,
1
,
32
,
32
)
assert
label
.
shape
==
(
4
,)
if
idx
%
5
==
0
:
for
val_data
,
val_label
in
val_dataloader
:
assert
val_data
.
shape
==
(
10
,
1
,
32
,
32
)
assert
val_label
.
shape
==
(
10
,)
def
test_dataloader_parallel_multi_instances
():
# set max shared memory to 100M
os
.
environ
[
"MGE_PLASMA_MEMORY"
]
=
"100000000"
_multi_instances_parallel_dataloader_worker
()
def
test_dataloader_parallel_multi_instances_multiprocessing
():
# set max shared memory to 100M
os
.
environ
[
"MGE_PLASMA_MEMORY"
]
=
"100000000"
import
multiprocessing
as
mp
# mp.set_start_method("spawn")
processes
=
[]
for
i
in
range
(
4
):
p
=
mp
.
Process
(
target
=
_multi_instances_parallel_dataloader_worker
)
p
.
start
()
processes
.
append
(
p
)
for
p
in
processes
:
p
.
join
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录