Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
0d6718fc
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
694
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0d6718fc
编写于
11月 15, 2018
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass compile
上级
d93b2d03
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
65 addition
and
78 deletion
+65
-78
paddle/fluid/framework/mixed_vector.h
paddle/fluid/framework/mixed_vector.h
+1
-1
paddle/fluid/memory/allocation/best_fit_allocator_test.cc
paddle/fluid/memory/allocation/best_fit_allocator_test.cc
+21
-28
paddle/fluid/memory/allocation/best_fit_allocator_test.cu
paddle/fluid/memory/allocation/best_fit_allocator_test.cu
+6
-6
paddle/fluid/memory/allocation/buffered_allocator_test.cc
paddle/fluid/memory/allocation/buffered_allocator_test.cc
+31
-35
paddle/fluid/memory/allocation/retry_allocator_test.cc
paddle/fluid/memory/allocation/retry_allocator_test.cc
+5
-7
paddle/fluid/platform/device_context.h
paddle/fluid/platform/device_context.h
+1
-1
未找到文件。
paddle/fluid/framework/mixed_vector.h
浏览文件 @
0d6718fc
...
...
@@ -284,7 +284,7 @@ class Vector {
bool
IsInCPU
()
const
{
return
flag_
&
kDataInCPU
;
}
mutable
std
::
vector
<
T
>
cpu_
;
mutable
std
::
unique_ptr
<
memory
::
Allocation
>
gpu_
;
mutable
memory
::
AllocationPtr
gpu_
;
mutable
int
flag_
;
mutable
std
::
mutex
mtx_
;
...
...
paddle/fluid/memory/allocation/best_fit_allocator_test.cc
浏览文件 @
0d6718fc
...
...
@@ -32,13 +32,10 @@ class StubAllocation : public Allocation {
TEST
(
BestFitAllocator
,
test_allocation
)
{
StubAllocation
stub
(
4UL
*
1024
*
1024
*
1024
);
BestFitAllocator
allocator
(
&
stub
);
{
auto
allocation
=
allocator
.
Allocate
(
64
);
allocator
.
FreeUniquePtr
(
std
::
move
(
allocation
));
}
{
auto
allocation
=
allocator
.
Allocate
(
64
,
allocator
.
kDefault
);
}
{
auto
allocation
=
allocator
.
Allocate
(
80
);
auto
allocation
=
allocator
.
Allocate
(
80
,
allocator
.
kDefault
);
{
auto
best_fit_allocation
=
...
...
@@ -50,19 +47,18 @@ TEST(BestFitAllocator, test_allocation) {
ASSERT_EQ
(
allocation
->
ptr
(),
nullptr
);
}
auto
allocation2
=
allocator
.
Allocate
(
60
);
auto
allocation3
=
allocator
.
Allocate
(
90
);
allocat
or
.
FreeUniquePtr
(
std
::
move
(
allocation2
)
);
allocation2
=
allocator
.
Allocate
(
30
);
auto
allocation2
=
allocator
.
Allocate
(
60
,
allocator
.
kDefault
);
auto
allocation3
=
allocator
.
Allocate
(
90
,
allocator
.
kDefault
);
allocat
ion2
.
reset
(
);
allocation2
=
allocator
.
Allocate
(
30
,
allocator
.
kDefault
);
{
auto
best_fit_allocation
=
dynamic_cast
<
BestFitAllocation
*>
(
allocation2
.
get
());
ASSERT_EQ
(
best_fit_allocation
->
ChunkIterator
()
->
offset_
,
80
);
}
allocator
.
FreeUniquePtr
(
std
::
move
(
allocation2
));
allocation2
=
allocator
.
Allocate
(
60
);
allocation2
.
reset
();
allocation2
=
allocator
.
Allocate
(
60
,
allocator
.
kDefault
);
{
auto
best_fit_allocation
=
...
...
@@ -70,23 +66,23 @@ TEST(BestFitAllocator, test_allocation) {
ASSERT_EQ
(
best_fit_allocation
->
ChunkIterator
()
->
offset_
,
80
);
}
allocat
or
.
FreeUniquePtr
(
std
::
move
(
allocation
)
);
allocat
or
.
FreeUniquePtr
(
std
::
move
(
allocation2
)
);
allocat
ion
.
reset
(
);
allocat
ion2
.
reset
(
);
allocation
=
allocator
.
Allocate
(
80
+
60
);
allocation
=
allocator
.
Allocate
(
80
+
60
,
allocator
.
kDefault
);
{
auto
best_fit_allocation
=
dynamic_cast
<
BestFitAllocation
*>
(
allocation
.
get
());
ASSERT_EQ
(
best_fit_allocation
->
ChunkIterator
()
->
offset_
,
0
);
}
allocat
or
.
FreeUniquePtr
(
std
::
move
(
allocation
)
);
allocat
ion
.
reset
(
);
allocation
=
allocator
.
Allocate
(
80
);
allocation2
=
allocator
.
Allocate
(
60
);
allocat
or
.
FreeUniquePtr
(
std
::
move
(
allocation
))
;
allocat
or
.
FreeUniquePtr
(
std
::
move
(
allocation3
))
;
allocat
or
.
FreeUniquePtr
(
std
::
move
(
allocation2
))
;
allocation
=
allocator
.
Allocate
(
80
,
allocator
.
kDefault
);
allocation2
=
allocator
.
Allocate
(
60
,
allocator
.
kDefault
);
allocat
ion
=
nullptr
;
allocat
ion2
=
nullptr
;
allocat
ion3
=
nullptr
;
ASSERT_EQ
(
allocator
.
NumFreeChunks
(),
1U
);
}
...
...
@@ -94,7 +90,8 @@ TEST(BestFitAllocator, test_allocation) {
TEST
(
BestFitAllocator
,
test_concurrent_cpu_allocation
)
{
CPUAllocator
allocator
;
auto
global_allocation
=
allocator
.
Allocate
(
256UL
*
1024
*
1024
);
auto
global_allocation
=
allocator
.
Allocate
(
256UL
*
1024
*
1024
,
allocator
.
kDefault
);
std
::
unique_ptr
<
Allocator
>
best_fit_allocator
(
new
BestFitAllocator
(
global_allocation
.
get
()));
...
...
@@ -109,8 +106,8 @@ TEST(BestFitAllocator, test_concurrent_cpu_allocation) {
for
(
size_t
i
=
0
;
i
<
128
;
++
i
)
{
size_t
allocate_size
=
dist
(
engine
);
auto
allocation
=
locked_allocator
.
Allocate
(
sizeof
(
size_t
)
*
allocate_size
);
auto
allocation
=
locked_allocator
.
Allocate
(
sizeof
(
size_t
)
*
allocate_size
,
locked_allocator
.
kDefault
);
size_t
*
data
=
reinterpret_cast
<
size_t
*>
(
allocation
->
ptr
());
...
...
@@ -122,8 +119,6 @@ TEST(BestFitAllocator, test_concurrent_cpu_allocation) {
for
(
size_t
j
=
0
;
j
<
allocate_size
;
++
j
)
{
ASSERT_EQ
(
data
[
j
],
j
);
}
locked_allocator
.
FreeUniquePtr
(
std
::
move
(
allocation
));
}
};
{
...
...
@@ -135,8 +130,6 @@ TEST(BestFitAllocator, test_concurrent_cpu_allocation) {
th
.
join
();
}
}
allocator
.
FreeUniquePtr
(
std
::
move
(
global_allocation
));
}
}
// namespace allocation
...
...
paddle/fluid/memory/allocation/best_fit_allocator_test.cu
浏览文件 @
0d6718fc
...
...
@@ -35,7 +35,8 @@ struct ForEachFill {
TEST
(
BestFitAllocator
,
concurrent_cuda
)
{
CUDAAllocator
allocator
(
platform
::
CUDAPlace
(
0
));
// 256 MB
auto
cuda_allocation
=
allocator
.
Allocate
(
256U
*
1024
*
1024
);
auto
cuda_allocation
=
allocator
.
Allocate
(
256U
*
1024
*
1024
,
allocator
.
kDefault
);
LockedAllocator
concurrent_allocator
(
std
::
unique_ptr
<
Allocator
>
(
new
BestFitAllocator
(
cuda_allocation
.
get
())));
...
...
@@ -49,8 +50,8 @@ TEST(BestFitAllocator, concurrent_cuda) {
for
(
size_t
i
=
0
;
i
<
128
;
++
i
)
{
size_t
allocate_size
=
dist
(
engine
);
auto
allocation
=
concurrent_allocator
.
Allocate
(
sizeof
(
size_t
)
*
allocate_size
);
auto
allocation
=
concurrent_allocator
.
Allocate
(
sizeof
(
size_t
)
*
allocate_size
,
concurrent_allocator
.
kDefault
);
size_t
*
data
=
reinterpret_cast
<
size_t
*>
(
allocation
->
ptr
());
...
...
@@ -66,8 +67,7 @@ TEST(BestFitAllocator, concurrent_cuda) {
for
(
size_t
j
=
0
;
j
<
allocate_size
;
++
j
)
{
ASSERT_EQ
(
buf
[
j
],
j
);
}
concurrent_allocator
.
FreeUniquePtr
(
std
::
move
(
allocation
));
allocation
=
nullptr
;
}
};
...
...
@@ -80,7 +80,7 @@ TEST(BestFitAllocator, concurrent_cuda) {
th
.
join
();
}
}
allocator
.
FreeUniquePtr
(
std
::
move
(
cuda_allocation
));
//
allocator.FreeUniquePtr(std::move(cuda_allocation));
}
}
// namespace allocation
...
...
paddle/fluid/memory/allocation/buffered_allocator_test.cc
浏览文件 @
0d6718fc
...
...
@@ -35,7 +35,7 @@ inline std::unique_ptr<BufferedAllocator> GetBufferedAllocator(
TEST
(
buffered_allocator
,
thread_safety
)
{
std
::
unique_ptr
<
CPUAllocator
>
allocator
(
new
CPUAllocator
());
auto
chunk
=
allocator
->
Allocate
(
1
<<
20
);
auto
chunk
=
allocator
->
Allocate
(
1
<<
20
,
allocator
->
kDefault
);
{
auto
buf_allocator
=
GetBufferedAllocator
(
chunk
.
get
(),
true
);
ASSERT_EQ
(
buf_allocator
->
IsAllocThreadSafe
(),
true
);
...
...
@@ -45,8 +45,6 @@ TEST(buffered_allocator, thread_safety) {
auto
buf_allocator
=
GetBufferedAllocator
(
chunk
.
get
(),
false
);
ASSERT_EQ
(
buf_allocator
->
IsAllocThreadSafe
(),
false
);
}
allocator
->
FreeUniquePtr
(
std
::
move
(
chunk
));
}
class
StubAllocation
:
public
Allocation
{
...
...
@@ -54,27 +52,8 @@ class StubAllocation : public Allocation {
using
Allocation
::
Allocation
;
};
class
StubAllocator
:
public
Unmanaged
Allocator
{
class
StubAllocator
:
public
MannualFree
Allocator
{
public:
std
::
unique_ptr
<
Allocation
>
Allocate
(
size_t
size
,
Allocator
::
Attr
attr
)
override
{
++
construct_count_
;
if
(
size
==
0
)
{
return
std
::
unique_ptr
<
Allocation
>
(
new
StubAllocation
(
nullptr
,
0
,
platform
::
CPUPlace
()));
}
else
{
return
std
::
unique_ptr
<
Allocation
>
(
new
StubAllocation
(
new
uint8_t
[
size
],
size
,
platform
::
CPUPlace
()));
}
}
void
FreeUniquePtr
(
std
::
unique_ptr
<
Allocation
>
allocation
)
{
StubAllocation
*
alloc
=
dynamic_cast
<
StubAllocation
*>
(
allocation
.
get
());
PADDLE_ENFORCE_NOT_NULL
(
alloc
);
if
(
alloc
->
ptr
())
delete
[]
static_cast
<
uint8_t
*>
(
alloc
->
ptr
());
++
destruct_count_
;
}
void
ResetCounter
()
{
construct_count_
=
0
;
destruct_count_
=
0
;
...
...
@@ -84,6 +63,23 @@ class StubAllocator : public UnmanagedAllocator {
size_t
GetFreeCount
()
const
{
return
destruct_count_
;
}
protected:
void
Free
(
Allocation
*
allocation
)
override
{
auto
*
alloc
=
dynamic_cast
<
StubAllocation
*>
(
allocation
);
PADDLE_ENFORCE_NOT_NULL
(
alloc
);
if
(
alloc
->
ptr
())
delete
[]
static_cast
<
uint8_t
*>
(
alloc
->
ptr
());
++
destruct_count_
;
delete
allocation
;
}
Allocation
*
AllocateImpl
(
size_t
size
,
Allocator
::
Attr
attr
)
override
{
++
construct_count_
;
if
(
size
==
0
)
{
return
new
StubAllocation
(
nullptr
,
0
,
platform
::
CPUPlace
());
}
else
{
return
new
StubAllocation
(
new
uint8_t
[
size
],
size
,
platform
::
CPUPlace
());
}
}
private:
size_t
construct_count_
=
0
;
size_t
destruct_count_
=
0
;
...
...
@@ -101,24 +97,24 @@ TEST(buffered_allocator, lazy_free) {
{
underlying_allocator
->
ResetCounter
();
auto
x
=
allocator
->
Allocate
(
1025
);
auto
x
=
allocator
->
Allocate
(
1025
,
allocator
->
kDefault
);
ASSERT_EQ
(
underlying_allocator
->
GetAllocCount
(),
kOne
);
ASSERT_EQ
(
underlying_allocator
->
GetFreeCount
(),
kZero
);
allocator
->
FreeUniquePtr
(
std
::
move
(
x
))
;
x
=
nullptr
;
ASSERT_EQ
(
underlying_allocator
->
GetFreeCount
(),
kZero
);
}
{
underlying_allocator
->
ResetCounter
();
auto
x
=
allocator
->
Allocate
(
900
);
auto
x
=
allocator
->
Allocate
(
900
,
allocator
->
kDefault
);
ASSERT_EQ
(
underlying_allocator
->
GetAllocCount
(),
kZero
);
ASSERT_EQ
(
underlying_allocator
->
GetFreeCount
(),
kZero
);
auto
y
=
allocator
->
Allocate
(
2048
);
auto
y
=
allocator
->
Allocate
(
2048
,
allocator
->
kDefault
);
ASSERT_EQ
(
underlying_allocator
->
GetAllocCount
(),
kOne
);
ASSERT_EQ
(
underlying_allocator
->
GetFreeCount
(),
kZero
);
allocator
->
FreeUniquePtr
(
std
::
move
(
x
))
;
x
=
nullptr
;
ASSERT_EQ
(
underlying_allocator
->
GetFreeCount
(),
kZero
);
allocator
->
FreeUniquePtr
(
std
::
move
(
y
))
;
y
=
nullptr
;
ASSERT_EQ
(
underlying_allocator
->
GetFreeCount
(),
kZero
);
}
...
...
@@ -132,13 +128,13 @@ TEST(buffered_allocator, lazy_free) {
TEST
(
buffered_allocator
,
garbage_collection
)
{
std
::
unique_ptr
<
CPUAllocator
>
cpu_allocator
(
new
CPUAllocator
());
auto
chunk
=
cpu_allocator
->
Allocate
(
2048
);
auto
chunk
=
cpu_allocator
->
Allocate
(
2048
,
cpu_allocator
->
kDefault
);
auto
allocator
=
GetBufferedAllocator
(
chunk
.
get
(),
false
);
auto
x1
=
allocator
->
Allocate
(
1600
);
auto
x2
=
allocator
->
Allocate
(
400
);
allocator
->
FreeUniquePtr
(
std
::
move
(
x1
))
;
allocator
->
FreeUniquePtr
(
std
::
move
(
x2
))
;
auto
x3
=
allocator
->
Allocate
(
1600
);
auto
x1
=
allocator
->
Allocate
(
1600
,
allocator
->
kDefault
);
auto
x2
=
allocator
->
Allocate
(
400
,
allocator
->
kDefault
);
x1
=
nullptr
;
x2
=
nullptr
;
auto
x3
=
allocator
->
Allocate
(
1600
,
allocator
->
kDefault
);
ASSERT_NE
(
x3
,
nullptr
);
ASSERT_NE
(
x3
->
ptr
(),
nullptr
);
}
...
...
paddle/fluid/memory/allocation/retry_allocator_test.cc
浏览文件 @
0d6718fc
...
...
@@ -32,7 +32,7 @@ TEST(RetryAllocator, RetryAllocator) {
CPUAllocator
cpu_allocator
;
size_t
size
=
(
1
<<
20
);
auto
cpu_allocation
=
cpu_allocator
.
Allocate
(
size
);
auto
cpu_allocation
=
cpu_allocator
.
Allocate
(
size
,
cpu_allocator
.
kDefault
);
std
::
unique_ptr
<
BestFitAllocator
>
best_fit_allocator
(
new
BestFitAllocator
(
cpu_allocation
.
get
()));
...
...
@@ -44,15 +44,15 @@ TEST(RetryAllocator, RetryAllocator) {
size_t
extra_time
=
2
;
// Reserve to perform more tests in the future
std
::
vector
<
std
::
shared_ptr
<
Managed
Allocator
>>
allocators
;
std
::
vector
<
std
::
shared_ptr
<
Allocator
>>
allocators
;
{
std
::
unique_ptr
<
BestFitAllocator
>
best_fit_allocator
(
new
BestFitAllocator
(
cpu_allocation
.
get
()));
std
::
unique_ptr
<
LockedAllocator
>
locked_allocator
(
new
LockedAllocator
(
std
::
move
(
best_fit_allocator
)));
allocators
.
push_back
(
RetryAllocator
::
Create
(
std
::
move
(
locked_allocator
),
(
thread_num
-
1
)
*
(
sleep_time
+
extra_time
)));
allocators
.
push_back
(
std
::
make_shared
<
RetryAllocator
>
(
std
::
move
(
locked_allocator
),
(
thread_num
-
1
)
*
(
sleep_time
+
extra_time
)));
}
for
(
auto
&
allocator
:
allocators
)
{
...
...
@@ -91,8 +91,6 @@ TEST(RetryAllocator, RetryAllocator) {
[
val
](
void
*
p
)
{
return
p
==
val
;
});
ASSERT_TRUE
(
is_all_equal
);
}
cpu_allocator
.
FreeUniquePtr
(
std
::
move
(
cpu_allocation
));
}
}
// namespace allocation
...
...
paddle/fluid/platform/device_context.h
浏览文件 @
0d6718fc
...
...
@@ -110,7 +110,7 @@ class CudnnHolder {
std
::
mutex
&
Mutex
()
{
return
mtx_
;
}
cudnnHandle_t
cudnn_handle_
;
std
::
unique_ptr
<
memory
::
Allocation
>
workspace_
;
memory
::
AllocationPtr
workspace_
;
const
cudaStream_t
*
stream_
;
// not owned;
const
CUDAPlace
place_
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录