Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
ab5fe1e9
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ab5fe1e9
编写于
7月 14, 2017
作者:
L
liaogang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ENH: memory test: check alignment and memory size
上级
00572aa4
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
67 addition
and
13 deletion
+67
-13
paddle/memory/memory_test.cc
paddle/memory/memory_test.cc
+67
-13
未找到文件。
paddle/memory/memory_test.cc
浏览文件 @
ab5fe1e9
...
...
@@ -13,14 +13,36 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/memory/memory.h"
#include "gtest/gtest.h"
#include "paddle/memory/detail/memory_block.h"
#include "paddle/memory/detail/meta_data.h"
#include "paddle/platform/cpu_info.h"
#include "paddle/platform/gpu_info.h"
#include "paddle/platform/place.h"
template
<
typename
T
>
inline
bool
is_aligned
(
T
*
p
,
size_t
n
=
alignof
(
T
))
{
#include <gtest/gtest.h>
#include <unordered_map>
inline
bool
is_aligned
(
void
const
*
p
,
const
size_t
n
)
{
return
0
==
(
reinterpret_cast
<
uintptr_t
>
(
p
)
%
n
);
}
size_t
align
(
size_t
size
,
paddle
::
platform
::
CPUPlace
place
)
{
size
+=
sizeof
(
paddle
::
memory
::
detail
::
Metadata
);
size_t
alignment
=
paddle
::
platform
::
CpuMinChunkSize
();
size_t
remaining
=
size
%
alignment
;
return
remaining
==
0
?
size
:
size
+
(
alignment
-
remaining
);
}
size_t
align
(
size_t
size
,
paddle
::
platform
::
GPUPlace
place
)
{
size
+=
sizeof
(
paddle
::
memory
::
detail
::
Metadata
);
size_t
alignment
=
paddle
::
platform
::
GpuMinChunkSize
();
size_t
remaining
=
size
%
alignment
;
return
remaining
==
0
?
size
:
size
+
(
alignment
-
remaining
);
}
void
update_size
(
size_t
&
total_size
,
const
size_t
size
)
{}
TEST
(
BuddyAllocator
,
CPUAllocation
)
{
void
*
p
=
nullptr
;
...
...
@@ -37,17 +59,33 @@ TEST(BuddyAllocator, CPUAllocation) {
TEST
(
BuddyAllocator
,
CPUMultAlloc
)
{
paddle
::
platform
::
CPUPlace
cpu
;
std
::
vector
<
void
*>
ps
;
ps
.
reserve
(
8
);
std
::
unordered_map
<
void
*
,
size_t
>
ps
;
size_t
total_size
=
paddle
::
memory
::
Used
(
cpu
);
EXPECT_EQ
(
total_size
,
0UL
);
for
(
auto
size
:
{
128
,
256
,
1024
,
4096
,
16384
,
65536
,
262144
,
1048576
,
4194304
})
{
ps
.
emplace_back
(
paddle
::
memory
::
Alloc
(
cpu
,
size
));
ps
[
paddle
::
memory
::
Alloc
(
cpu
,
size
)]
=
size
;
// Buddy Allocator doesn't manage too large memory chunk
if
(
paddle
::
memory
::
Used
(
cpu
)
==
total_size
)
continue
;
size_t
aligned_size
=
align
(
size
,
cpu
);
total_size
+=
aligned_size
;
EXPECT_EQ
(
total_size
,
paddle
::
memory
::
Used
(
cpu
));
}
for
(
auto
p
:
ps
)
{
EXPECT_EQ
(
is_aligned
(
p
,
32
),
true
);
paddle
::
memory
::
Free
(
cpu
,
p
);
EXPECT_EQ
(
is_aligned
(
p
.
first
,
32
),
true
);
paddle
::
memory
::
Free
(
cpu
,
p
.
first
);
// Buddy Allocator doesn't manage too large memory chunk
if
(
paddle
::
memory
::
Used
(
cpu
)
==
total_size
)
continue
;
size_t
aligned_size
=
align
(
p
.
second
,
cpu
);
total_size
-=
aligned_size
;
EXPECT_EQ
(
total_size
,
paddle
::
memory
::
Used
(
cpu
));
}
}
...
...
@@ -69,17 +107,33 @@ TEST(BuddyAllocator, GPUAllocation) {
TEST
(
BuddyAllocator
,
GPUMultAlloc
)
{
paddle
::
platform
::
GPUPlace
gpu
;
std
::
vector
<
void
*>
ps
;
ps
.
reserve
(
8
);
std
::
unordered_map
<
void
*
,
size_t
>
ps
;
size_t
total_size
=
paddle
::
memory
::
Used
(
gpu
);
EXPECT_EQ
(
total_size
,
0UL
);
for
(
auto
size
:
{
128
,
256
,
1024
,
4096
,
16384
,
65536
,
262144
,
1048576
,
4194304
})
{
ps
.
emplace_back
(
paddle
::
memory
::
Alloc
(
gpu
,
size
));
ps
[
paddle
::
memory
::
Alloc
(
gpu
,
size
)]
=
size
;
// Buddy Allocator doesn't manage too large memory chunk
if
(
paddle
::
memory
::
Used
(
gpu
)
==
total_size
)
continue
;
size_t
aligned_size
=
align
(
size
,
gpu
);
total_size
+=
aligned_size
;
EXPECT_EQ
(
total_size
,
paddle
::
memory
::
Used
(
gpu
));
}
for
(
auto
p
:
ps
)
{
EXPECT_EQ
(
is_aligned
(
p
,
32
),
true
);
paddle
::
memory
::
Free
(
gpu
,
p
);
EXPECT_EQ
(
is_aligned
(
p
.
first
,
32
),
true
);
paddle
::
memory
::
Free
(
gpu
,
p
.
first
);
// Buddy Allocator doesn't manage too large memory chunk
if
(
paddle
::
memory
::
Used
(
gpu
)
==
total_size
)
continue
;
size_t
aligned_size
=
align
(
p
.
second
,
gpu
);
total_size
-=
aligned_size
;
EXPECT_EQ
(
total_size
,
paddle
::
memory
::
Used
(
gpu
));
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录