Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
db128c45
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
db128c45
编写于
6月 25, 2017
作者:
Y
Yi Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass cpu_allocator_test
上级
67481ca8
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
55 addition
and
16 deletion
+55
-16
CMakeLists.txt
CMakeLists.txt
+1
-1
cmake/generic.cmake
cmake/generic.cmake
+4
-0
paddle/memory/detail/CMakeLists.txt
paddle/memory/detail/CMakeLists.txt
+5
-1
paddle/memory/detail/cpu_allocator.h
paddle/memory/detail/cpu_allocator.h
+9
-4
paddle/memory/detail/cpu_allocator_test.cc
paddle/memory/detail/cpu_allocator_test.cc
+11
-5
paddle/memory/memory.cc
paddle/memory/memory.cc
+12
-2
paddle/memory/memory.h
paddle/memory/memory.h
+13
-3
未找到文件。
CMakeLists.txt
浏览文件 @
db128c45
...
@@ -71,7 +71,7 @@ if(ANDROID)
...
@@ -71,7 +71,7 @@ if(ANDROID)
"Disable RDMA when cross-compiling for Android"
FORCE
)
"Disable RDMA when cross-compiling for Android"
FORCE
)
endif
(
ANDROID
)
endif
(
ANDROID
)
set
(
THIRD_PARTY_PATH
"
${
PROJ_ROOT
}
/third_party"
CACHE STRING
set
(
THIRD_PARTY_PATH
"
${
CMAKE_BINARY_DIR
}
/third_party"
CACHE STRING
"A path setting third party libraries download & build directories."
)
"A path setting third party libraries download & build directories."
)
if
(
WITH_C_API AND WITH_PYTHON
)
if
(
WITH_C_API AND WITH_PYTHON
)
...
...
cmake/generic.cmake
浏览文件 @
db128c45
...
@@ -78,6 +78,10 @@
...
@@ -78,6 +78,10 @@
#
#
# cc_test(example_test SRCS example_test.cc DEPS example glog gflags)
# cc_test(example_test SRCS example_test.cc DEPS example glog gflags)
if
(
WITH_GPU
)
add_definitions
(
-DPADDLE_WITH_GPU
)
endif
()
if
(
NOT APPLE
)
if
(
NOT APPLE
)
find_package
(
Threads REQUIRED
)
find_package
(
Threads REQUIRED
)
link_libraries
(
${
CMAKE_THREAD_LIBS_INIT
}
)
link_libraries
(
${
CMAKE_THREAD_LIBS_INIT
}
)
...
...
paddle/memory/detail/CMakeLists.txt
浏览文件 @
db128c45
cc_test
(
cpu_allocator_test SRCS cpu_allocator_test.cc
)
if
(
${
WITH_GPU
}
)
nv_test
(
cpu_allocator_test SRCS cpu_allocator_test.cc
)
# nv_test links CUDA, but
else
(
${
WITH_GPU
}
)
cc_test
(
cpu_allocator_test SRCS cpu_allocator_test.cc
)
# cc_test doesn't.
endif
(
${
WITH_GPU
}
)
paddle/memory/detail/cpu_allocator.h
浏览文件 @
db128c45
...
@@ -17,6 +17,11 @@ limitations under the License. */
...
@@ -17,6 +17,11 @@ limitations under the License. */
#include <malloc.h> // for malloc and free
#include <malloc.h> // for malloc and free
#include <stddef.h> // for size_t
#include <stddef.h> // for size_t
#ifdef PADDLE_WITH_GPU
#include <cuda.h>
#include <cuda_runtime_api.h>
#endif // PADDLE_WITH_GPU
namespace
paddle
{
namespace
paddle
{
namespace
memory
{
namespace
memory
{
namespace
detail
{
namespace
detail
{
...
@@ -40,9 +45,9 @@ public:
...
@@ -40,9 +45,9 @@ public:
void
Free
(
void
*
p
)
{
free
(
p
);
}
void
Free
(
void
*
p
)
{
free
(
p
);
}
};
};
// If CMake macro WITH_GPU is OFF, C++ compiler won't generate the
// If CMake macro
PADDLE_
WITH_GPU is OFF, C++ compiler won't generate the
// following specialization that depends on the CUDA library.
// following specialization that depends on the CUDA library.
#ifdef WITH_GPU
#ifdef
PADDLE_
WITH_GPU
template
<
>
template
<
>
class
CPUAllocator
<
true
>
{
class
CPUAllocator
<
true
>
{
public:
public:
...
@@ -51,12 +56,12 @@ public:
...
@@ -51,12 +56,12 @@ public:
if
(
cudaMallocHost
(
&
p
,
size
)
!=
cudaSuccess
)
{
if
(
cudaMallocHost
(
&
p
,
size
)
!=
cudaSuccess
)
{
return
NULL
;
return
NULL
;
}
}
return
*
p
;
return
p
;
}
}
void
Free
(
void
*
p
)
{
cudaFreeHost
(
p
);
}
void
Free
(
void
*
p
)
{
cudaFreeHost
(
p
);
}
};
};
#endif // WITH_GPU
#endif //
PADDLE_
WITH_GPU
}
// namespace detail
}
// namespace detail
}
// namespace memory
}
// namespace memory
...
...
paddle/memory/detail/cpu_allocator_test.cc
浏览文件 @
db128c45
...
@@ -22,11 +22,17 @@ TEST(CPUAllocator, NonStaging) {
...
@@ -22,11 +22,17 @@ TEST(CPUAllocator, NonStaging) {
a
.
Free
(
p
);
a
.
Free
(
p
);
}
}
#ifdef WITH_GPU
#ifdef
PADDLE_
WITH_GPU
TEST
(
CPUAllocator
,
Staging
)
{
TEST
(
CPUAllocator
,
Staging
)
{
paddle
::
memory
::
detail
::
CPUAllocator
<
true
>
a
;
paddle
::
memory
::
detail
::
CPUAllocator
<
true
>
a
;
void
*
p
=
a
.
Alloc
(
4096
);
EXPECT_NE
(
p
,
nullptr
);
int
devices
;
a
.
Free
(
p
);
if
(
cudaGetDeviceCount
(
&
devices
)
==
cudaSuccess
&&
devices
>
0
)
{
void
*
p
=
a
.
Alloc
(
4096
);
EXPECT_NE
(
p
,
nullptr
);
a
.
Free
(
p
);
}
else
{
EXPECT_EQ
(
a
.
Alloc
(
4096
),
nullptr
);
}
}
}
#endif // WITH_GPU
#endif //
PADDLE_
WITH_GPU
paddle/memory/memory.cc
浏览文件 @
db128c45
...
@@ -19,7 +19,11 @@ namespace memory {
...
@@ -19,7 +19,11 @@ namespace memory {
template
<
>
template
<
>
void
*
Alloc
<
CPUPlace
>
(
CPUPlace
,
size_t
size
)
{
void
*
Alloc
<
CPUPlace
>
(
CPUPlace
,
size_t
size
)
{
return
GetCPUBuddyAllocator
()
->
Alloc
(
size
);
return
GetCPUBuddyAllocator
(
false
/*non-staging*/
)
->
Alloc
(
size
);
}
void
*
AllocStaging
(
CPUPlace
,
size_t
size
)
{
return
GetCPUBuddyAllocator
(
true
/*staging*/
)
->
Alloc
(
size
);
}
}
template
<
>
template
<
>
...
@@ -29,9 +33,14 @@ void* Alloc<GPUPlace>(GPUPlace pl, size_t size) {
...
@@ -29,9 +33,14 @@ void* Alloc<GPUPlace>(GPUPlace pl, size_t size) {
template
<
>
template
<
>
void
Free
<
CPUPlace
>
(
CPUPlace
,
void
*
p
)
{
void
Free
<
CPUPlace
>
(
CPUPlace
,
void
*
p
)
{
return
GetCPUBuddyAllocator
()
->
Free
(
p
);
return
GetCPUBuddyAllocator
(
false
/*non-staging*/
)
->
Free
(
p
);
}
void
FreeStaging
(
CPUPlace
,
void
*
p
)
{
return
GetCPUBuddyAllocator
(
false
/*non-staging*/
)
->
Free
(
p
);
}
}
#ifdef PADDLE_WITH_GPU
template
<
>
template
<
>
void
*
Alloc
<
GPUPlace
>
(
GPUPlace
pl
,
void
*
p
)
{
void
*
Alloc
<
GPUPlace
>
(
GPUPlace
pl
,
void
*
p
)
{
return
GetGPUBuddyAllocator
(
pl
.
device
)
->
Free
(
p
);
return
GetGPUBuddyAllocator
(
pl
.
device
)
->
Free
(
p
);
...
@@ -46,6 +55,7 @@ template <>
...
@@ -46,6 +55,7 @@ template <>
size_t
Alloc
<
GPUPlace
>
(
GPUPlace
pl
)
{
size_t
Alloc
<
GPUPlace
>
(
GPUPlace
pl
)
{
return
GetGPUBuddyAllocator
(
pl
.
device
)
->
Used
();
return
GetGPUBuddyAllocator
(
pl
.
device
)
->
Used
();
}
}
#endif // PADDLE_WITH_GPU
}
// namespace memory
}
// namespace memory
}
// namespace paddle
}
// namespace paddle
paddle/memory/memory.h
浏览文件 @
db128c45
...
@@ -19,9 +19,19 @@ limitations under the License. */
...
@@ -19,9 +19,19 @@ limitations under the License. */
namespace
paddle
{
namespace
paddle
{
namespace
memory
{
namespace
memory
{
typename
<
typename
paddle
::
framework
::
Place
>
void
*
Alloc
(
Place
,
size_t
);
template
<
typename
paddle
::
framework
::
Place
>
typename
<
typename
paddle
::
framework
::
Place
>
void
Free
(
Place
,
void
*
);
void
*
Alloc
(
Place
,
size_t
);
typename
<
typename
paddle
::
framework
::
Place
>
size_t
Used
(
Place
);
template
<
typename
paddle
::
framework
::
Place
>
void
Free
(
Place
,
void
*
);
template
<
typename
paddle
::
framework
::
Place
>
size_t
Used
(
Place
);
// Staging memory means "pinned" host memory that can be mapped into
// the CUDA memory space and accessed by the device rapidly. Don't
// allocate too much staging memory; otherwise system performance will
// degrade because the OS cannot find enough swap memory space.
void
*
AllocStaging
(
CPUPlace
,
size_t
);
void
*
FreeStaging
(
CPUPlace
,
size_t
);
}
// namespace memory
}
// namespace memory
}
// namespace paddle
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录