Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
1238706d
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
1238706d
编写于
11月 30, 2017
作者:
Q
QI JUN
提交者:
GitHub
11月 30, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine unittest with setting gflags (#5476)
* add gflags for C++ unittest
上级
605b3e44
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
66 addition
and
20 deletion
+66
-20
cmake/generic.cmake
cmake/generic.cmake
+4
-4
paddle/memory/memory.cc
paddle/memory/memory.cc
+21
-6
paddle/optimizer/parameter_optimizer_test.cc
paddle/optimizer/parameter_optimizer_test.cc
+0
-5
paddle/optimizer/serialization_test.cc
paddle/optimizer/serialization_test.cc
+0
-5
paddle/testing/CMakeLists.txt
paddle/testing/CMakeLists.txt
+2
-0
paddle/testing/paddle_gtest_main.cc
paddle/testing/paddle_gtest_main.cc
+39
-0
未找到文件。
cmake/generic.cmake
浏览文件 @
1238706d
...
...
@@ -227,8 +227,8 @@ function(cc_test TARGET_NAME)
set
(
multiValueArgs SRCS DEPS
)
cmake_parse_arguments
(
cc_test
"
${
options
}
"
"
${
oneValueArgs
}
"
"
${
multiValueArgs
}
"
${
ARGN
}
)
add_executable
(
${
TARGET_NAME
}
${
cc_test_SRCS
}
)
target_link_libraries
(
${
TARGET_NAME
}
${
cc_test_DEPS
}
gtest gtest_main
)
add_dependencies
(
${
TARGET_NAME
}
${
cc_test_DEPS
}
gtest gtest_main
)
target_link_libraries
(
${
TARGET_NAME
}
${
cc_test_DEPS
}
paddle_gtest_main paddle_memory gtest gflags
)
add_dependencies
(
${
TARGET_NAME
}
${
cc_test_DEPS
}
paddle_gtest_main paddle_memory gtest gflags
)
add_test
(
NAME
${
TARGET_NAME
}
COMMAND
${
TARGET_NAME
}
WORKING_DIRECTORY
${
CMAKE_CURRENT_SOURCE_DIR
}
)
endif
()
endfunction
(
cc_test
)
...
...
@@ -288,8 +288,8 @@ function(nv_test TARGET_NAME)
set
(
multiValueArgs SRCS DEPS
)
cmake_parse_arguments
(
nv_test
"
${
options
}
"
"
${
oneValueArgs
}
"
"
${
multiValueArgs
}
"
${
ARGN
}
)
cuda_add_executable
(
${
TARGET_NAME
}
${
nv_test_SRCS
}
)
target_link_libraries
(
${
TARGET_NAME
}
${
nv_test_DEPS
}
gtest gtest_main
)
add_dependencies
(
${
TARGET_NAME
}
${
nv_test_DEPS
}
gtest gtest_main
)
target_link_libraries
(
${
TARGET_NAME
}
${
nv_test_DEPS
}
paddle_gtest_main paddle_memory gtest gflags
)
add_dependencies
(
${
TARGET_NAME
}
${
nv_test_DEPS
}
paddle_gtest_main paddle_memory gtest gflags
)
add_test
(
${
TARGET_NAME
}
${
TARGET_NAME
}
)
endif
()
endfunction
(
nv_test
)
...
...
paddle/memory/memory.cc
浏览文件 @
1238706d
...
...
@@ -81,18 +81,33 @@ BuddyAllocator* GetGPUBuddyAllocator(int gpu_id) {
}
template
<
>
void
*
Alloc
<
platform
::
GPUPlace
>
(
platform
::
GPUPlace
place
,
size_t
siz
e
)
{
return
GetGPUBuddyAllocator
(
place
.
device
)
->
Alloc
(
size
);
size_t
Used
<
platform
::
GPUPlace
>
(
platform
::
GPUPlace
plac
e
)
{
return
GetGPUBuddyAllocator
(
place
.
device
)
->
Used
(
);
}
template
<
>
void
Free
<
platform
::
GPUPlace
>
(
platform
::
GPUPlace
place
,
void
*
p
)
{
GetGPUBuddyAllocator
(
place
.
device
)
->
Free
(
p
);
void
*
Alloc
<
platform
::
GPUPlace
>
(
platform
::
GPUPlace
place
,
size_t
size
)
{
auto
*
buddy_allocator
=
GetGPUBuddyAllocator
(
place
.
device
);
auto
*
ptr
=
buddy_allocator
->
Alloc
(
size
);
if
(
ptr
==
nullptr
)
{
int
cur_dev
=
platform
::
GetCurrentDeviceId
();
platform
::
SetDeviceId
(
place
.
device
);
size_t
avail
,
total
;
platform
::
GpuMemoryUsage
(
avail
,
total
);
LOG
(
WARNING
)
<<
"Cannot allocate "
<<
size
<<
" bytes in GPU "
<<
place
.
device
<<
", available "
<<
avail
<<
" bytes"
;
LOG
(
WARNING
)
<<
"total "
<<
total
;
LOG
(
WARNING
)
<<
"GpuMinChunkSize "
<<
platform
::
GpuMinChunkSize
();
LOG
(
WARNING
)
<<
"GpuMaxChunkSize "
<<
platform
::
GpuMaxChunkSize
();
LOG
(
WARNING
)
<<
"GPU memory used: "
<<
Used
<
platform
::
GPUPlace
>
(
place
);
platform
::
SetDeviceId
(
cur_dev
);
}
return
ptr
;
}
template
<
>
size_t
Used
<
platform
::
GPUPlace
>
(
platform
::
GPUPlace
place
)
{
return
GetGPUBuddyAllocator
(
place
.
device
)
->
Used
(
);
void
Free
<
platform
::
GPUPlace
>
(
platform
::
GPUPlace
place
,
void
*
p
)
{
GetGPUBuddyAllocator
(
place
.
device
)
->
Free
(
p
);
}
#endif
...
...
paddle/optimizer/parameter_optimizer_test.cc
浏览文件 @
1238706d
...
...
@@ -127,8 +127,3 @@ TEST_F(OptimizerTest, TestGetWeight) { TestGetWeight(); }
TEST_F
(
OptimizerTest
,
TestUpdate
)
{
TestUpdate
();
}
TEST_F
(
OptimizerTest
,
TestCheckPoint
)
{
TestCheckPoint
();
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
paddle/optimizer/serialization_test.cc
浏览文件 @
1238706d
...
...
@@ -46,8 +46,3 @@ TEST(TensorToProto, Case2) {
EXPECT_EQ
(
t1
[
i
],
t
[
i
]);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
paddle/testing/CMakeLists.txt
浏览文件 @
1238706d
...
...
@@ -5,4 +5,6 @@ if(WITH_TESTING)
add_dependencies
(
paddle_test_main paddle_proto
${
external_project_dependencies
}
)
add_library
(
paddle_test_util STATIC TestUtil.cpp
)
add_dependencies
(
paddle_test_util paddle_proto
${
external_project_dependencies
}
)
add_library
(
paddle_gtest_main STATIC paddle_gtest_main.cc
)
add_dependencies
(
paddle_gtest_main paddle_memory gtest gflags
)
endif
()
paddle/testing/paddle_gtest_main.cc
0 → 100644
浏览文件 @
1238706d
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <cstring>
#include "gflags/gflags.h"
#include "gtest/gtest.h"
#include "paddle/memory/memory.h"
int
main
(
int
argc
,
char
**
argv
)
{
std
::
vector
<
char
*>
new_argv
;
std
::
string
gflags_env
;
new_argv
.
push_back
(
argv
[
0
]);
#ifdef PADDLE_WITH_CUDA
new_argv
.
push_back
(
strdup
(
"--tryfromenv=fraction_of_gpu_memory_to_use,use_pinned_memory"
));
#else
new_argv
.
push_back
(
strdup
(
"--tryfromenv=use_pinned_memory"
));
#endif
int
new_argc
=
static_cast
<
int
>
(
new_argv
.
size
());
char
**
new_argv_address
=
new_argv
.
data
();
google
::
ParseCommandLineFlags
(
&
new_argc
,
&
new_argv_address
,
false
);
testing
::
InitGoogleTest
(
&
argc
,
argv
);
paddle
::
memory
::
Used
(
paddle
::
platform
::
CPUPlace
());
#ifdef PADDLE_WITH_CUDA
paddle
::
memory
::
Used
(
paddle
::
platform
::
GPUPlace
(
0
));
#endif
return
RUN_ALL_TESTS
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录