Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
e0ef91a6
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e0ef91a6
编写于
7月 06, 2020
作者:
J
Jesse Lee
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix Queue::Reset
上级
8b78bbc3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
76 addition
and
1 deletion
+76
-1
mindspore/ccsrc/dataset/util/circular_pool.cc
mindspore/ccsrc/dataset/util/circular_pool.cc
+3
-0
mindspore/ccsrc/dataset/util/queue.h
mindspore/ccsrc/dataset/util/queue.h
+3
-0
tests/ut/cpp/dataset/queue_test.cc
tests/ut/cpp/dataset/queue_test.cc
+70
-1
未找到文件。
mindspore/ccsrc/dataset/util/circular_pool.cc
浏览文件 @
e0ef91a6
...
@@ -88,6 +88,9 @@ Status CircularPool::Allocate(size_t n, void **p) {
...
@@ -88,6 +88,9 @@ Status CircularPool::Allocate(size_t n, void **p) {
while
(
cirIt
.
has_next
())
{
while
(
cirIt
.
has_next
())
{
auto
it
=
cirIt
.
Next
();
auto
it
=
cirIt
.
Next
();
Arena
*
ba
=
it
->
get
();
Arena
*
ba
=
it
->
get
();
if
(
ba
->
get_max_size
()
<
n
)
{
return
Status
(
StatusCode
::
kOutOfMemory
);
}
// If we are asked to move forward the tail
// If we are asked to move forward the tail
if
(
move_tail
)
{
if
(
move_tail
)
{
Arena
*
expected
=
cirIt
.
cur_tail_
;
Arena
*
expected
=
cirIt
.
cur_tail_
;
...
...
mindspore/ccsrc/dataset/util/queue.h
浏览文件 @
e0ef91a6
...
@@ -182,6 +182,9 @@ class Queue {
...
@@ -182,6 +182,9 @@ class Queue {
arr_
[
k
].
~
T
();
arr_
[
k
].
~
T
();
}
}
}
}
for
(
uint64_t
i
=
0
;
i
<
sz_
;
i
++
)
{
std
::
allocator_traits
<
Allocator
<
T
>>::
construct
(
alloc_
,
&
(
arr_
[
i
]));
}
empty_cv_
.
ResetIntrpState
();
empty_cv_
.
ResetIntrpState
();
full_cv_
.
ResetIntrpState
();
full_cv_
.
ResetIntrpState
();
head_
=
0
;
head_
=
0
;
...
...
tests/ut/cpp/dataset/queue_test.cc
浏览文件 @
e0ef91a6
...
@@ -19,6 +19,8 @@
...
@@ -19,6 +19,8 @@
#include "dataset/util/task_manager.h"
#include "dataset/util/task_manager.h"
#include "dataset/util/queue.h"
#include "dataset/util/queue.h"
#include <atomic>
#include <atomic>
#include <chrono>
#include <random>
#include "utils/log_adapter.h"
#include "utils/log_adapter.h"
using
namespace
mindspore
::
dataset
;
using
namespace
mindspore
::
dataset
;
...
@@ -39,7 +41,7 @@ class RefCount {
...
@@ -39,7 +41,7 @@ class RefCount {
public:
public:
RefCount
()
:
v_
(
nullptr
)
{}
RefCount
()
:
v_
(
nullptr
)
{}
explicit
RefCount
(
int
x
)
:
v_
(
std
::
make_shared
<
int
>
(
x
))
{}
explicit
RefCount
(
int
x
)
:
v_
(
std
::
make_shared
<
int
>
(
x
))
{}
explicit
RefCount
(
const
RefCount
&
o
)
:
v_
(
o
.
v_
)
{}
RefCount
(
const
RefCount
&
o
)
:
v_
(
o
.
v_
)
{}
~
RefCount
()
{
~
RefCount
()
{
MS_LOG
(
DEBUG
)
<<
"Destructor of RefCount called"
<<
std
::
endl
;
MS_LOG
(
DEBUG
)
<<
"Destructor of RefCount called"
<<
std
::
endl
;
gRefCountDestructorCalled
++
;
gRefCountDestructorCalled
++
;
...
@@ -167,3 +169,70 @@ TEST_F(MindDataTestQueue, Test6) {
...
@@ -167,3 +169,70 @@ TEST_F(MindDataTestQueue, Test6) {
MS_LOG
(
INFO
)
<<
"Popped value "
<<
*
pepped_value
<<
" from queue index "
<<
chosen_queue_index
;
MS_LOG
(
INFO
)
<<
"Popped value "
<<
*
pepped_value
<<
" from queue index "
<<
chosen_queue_index
;
ASSERT_EQ
(
*
pepped_value
,
99
);
ASSERT_EQ
(
*
pepped_value
,
99
);
}
}
using
namespace
std
::
chrono
;
template
<
typename
QueueType
,
typename
PayloadType
>
void
Perf
(
int
n
,
int
p
,
std
::
string
name
)
{
auto
payload
=
std
::
vector
<
PayloadType
>
(
n
,
PayloadType
(
p
));
auto
queue
=
QueueType
(
n
);
auto
t0
=
high_resolution_clock
::
now
();
auto
check
=
0
;
for
(
int
i
=
0
;
i
<
queue
.
capacity
();
i
++
)
{
queue
.
Add
(
PayloadType
(
p
));
}
check
=
queue
.
size
();
for
(
int
i
=
0
;
i
<
queue
.
capacity
();
i
++
)
{
queue
.
PopFront
(
&
payload
[
i
]);
}
auto
t1
=
high_resolution_clock
::
now
();
std
::
cout
<<
name
<<
" queue filled size: "
<<
queue
.
size
()
<<
" "
<<
check
<<
std
::
endl
;
auto
t2
=
high_resolution_clock
::
now
();
for
(
int
i
=
0
;
i
<
queue
.
capacity
();
i
++
)
{
queue
.
Add
(
PayloadType
(
p
));
}
check
=
queue
.
size
();
for
(
int
i
=
0
;
i
<
queue
.
capacity
();
i
++
)
{
queue
.
PopFront
(
&
payload
[
i
]);
}
auto
t3
=
high_resolution_clock
::
now
();
auto
d
=
duration_cast
<
milliseconds
>
(
t3
-
t2
+
t1
-
t0
).
count
();
std
::
cout
<<
name
<<
" queue emptied size: "
<<
queue
.
size
()
<<
" "
<<
check
<<
std
::
endl
;
std
::
cout
<<
name
<<
" "
<<
" ran in "
<<
d
<<
"ms"
<<
std
::
endl
;
}
template
<
typename
QueueType
,
typename
PayloadType
>
void
Fuzz
(
int
n
,
int
p
,
std
::
string
name
)
{
std
::
mt19937
gen
(
1
);
auto
payload
=
std
::
vector
<
PayloadType
>
(
n
,
PayloadType
(
p
));
auto
queue
=
QueueType
(
n
);
auto
dist
=
std
::
uniform_int_distribution
<
int
>
(
0
,
2
);
std
::
cout
<<
"###"
<<
std
::
endl
;
for
(
auto
i
=
0
;
i
<
n
;
i
++
)
{
auto
v
=
dist
(
gen
);
if
(
v
==
0
&&
queue
.
size
()
<
n
-
1
)
{
queue
.
Add
(
std
::
move
(
payload
[
i
]));
}
if
(
v
==
1
&&
queue
.
size
()
>
0
)
{
queue
.
PopFront
(
&
payload
[
i
]);
}
else
{
queue
.
Reset
();
}
}
std
::
cout
<<
name
<<
" fuzz ran "
<<
queue
.
size
()
<<
std
::
endl
;
}
TEST_F
(
MindDataTestQueue
,
TestPerf
)
{
try
{
int
kSz
=
1000000
;
// std::cout << "enter size" << std::endl;
// std::cin >> kSz;
Perf
<
Queue
<
std
::
vector
<
int
>>
,
std
::
vector
<
int
>>
(
kSz
,
1
,
"old queue, vector of size 1"
);
}
catch
(
const
std
::
exception
&
e
)
{
std
::
cout
<<
e
.
what
()
<<
std
::
endl
;
}
std
::
cout
<<
"Test Reset"
<<
std
::
endl
;
std
::
cout
<<
"Enter fuzz size"
<<
std
::
endl
;
int
fs
=
1000
;
// std::cin >> fs;
Fuzz
<
Queue
<
std
::
vector
<
int
>>
,
std
::
vector
<
int
>>
(
fs
,
1
,
"New queue"
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录