Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
3c6ab799
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看板
未验证
提交
3c6ab799
编写于
5月 05, 2019
作者:
C
chengduo
提交者:
GitHub
5月 05, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unnecessary set_devices (#17158)
* remove unnecessary set_devices
上级
f938ccec
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
11 addition
and
16 deletion
+11
-16
paddle/fluid/memory/allocation/legacy_allocator.cc
paddle/fluid/memory/allocation/legacy_allocator.cc
+5
-5
paddle/fluid/memory/detail/system_allocator.cc
paddle/fluid/memory/detail/system_allocator.cc
+6
-11
未找到文件。
paddle/fluid/memory/allocation/legacy_allocator.cc
浏览文件 @
3c6ab799
...
@@ -29,6 +29,9 @@
...
@@ -29,6 +29,9 @@
#include "paddle/fluid/platform/profiler.h"
#include "paddle/fluid/platform/profiler.h"
#include "paddle/fluid/string/printf.h"
#include "paddle/fluid/string/printf.h"
#include "paddle/fluid/string/split.h"
#include "paddle/fluid/string/split.h"
#ifdef PADDLE_WITH_CUDA
#include "paddle/fluid/platform/cuda_device_guard.h"
#endif
DEFINE_bool
(
init_allocated_mem
,
false
,
DEFINE_bool
(
init_allocated_mem
,
false
,
"It is a mistake that the values of the memory allocated by "
"It is a mistake that the values of the memory allocated by "
...
@@ -142,7 +145,6 @@ BuddyAllocator *GetGPUBuddyAllocator(int gpu_id) {
...
@@ -142,7 +145,6 @@ BuddyAllocator *GetGPUBuddyAllocator(int gpu_id) {
std
::
call_once
(
init_flag
,
[
gpu_id
]()
{
std
::
call_once
(
init_flag
,
[
gpu_id
]()
{
devices
=
platform
::
GetSelectedDevices
();
devices
=
platform
::
GetSelectedDevices
();
int
gpu_num
=
devices
.
size
();
int
gpu_num
=
devices
.
size
();
allocation
::
GPUMemMonitor
.
Initialize
(
devices
.
size
());
allocation
::
GPUMemMonitor
.
Initialize
(
devices
.
size
());
a_arr
=
new
BuddyAllocator
*
[
gpu_num
];
a_arr
=
new
BuddyAllocator
*
[
gpu_num
];
...
@@ -168,9 +170,9 @@ BuddyAllocator *GetGPUBuddyAllocator(int gpu_id) {
...
@@ -168,9 +170,9 @@ BuddyAllocator *GetGPUBuddyAllocator(int gpu_id) {
<<
". Current 'FLAGS_reallocate_gpu_memory_in_mb' value is "
<<
". Current 'FLAGS_reallocate_gpu_memory_in_mb' value is "
<<
FLAGS_reallocate_gpu_memory_in_mb
<<
"
\n\n
"
;
<<
FLAGS_reallocate_gpu_memory_in_mb
<<
"
\n\n
"
;
}
}
platform
::
SetDeviceId
(
gpu_id
);
});
});
platform
::
SetDeviceId
(
gpu_id
);
auto
pos
=
std
::
distance
(
devices
.
begin
(),
auto
pos
=
std
::
distance
(
devices
.
begin
(),
std
::
find
(
devices
.
begin
(),
devices
.
end
(),
gpu_id
));
std
::
find
(
devices
.
begin
(),
devices
.
end
(),
gpu_id
));
return
a_arr
[
pos
];
return
a_arr
[
pos
];
...
@@ -193,8 +195,7 @@ void *Alloc<platform::CUDAPlace>(const platform::CUDAPlace &place,
...
@@ -193,8 +195,7 @@ void *Alloc<platform::CUDAPlace>(const platform::CUDAPlace &place,
auto
*
buddy_allocator
=
GetGPUBuddyAllocator
(
place
.
device
);
auto
*
buddy_allocator
=
GetGPUBuddyAllocator
(
place
.
device
);
auto
*
ptr
=
buddy_allocator
->
Alloc
(
size
);
auto
*
ptr
=
buddy_allocator
->
Alloc
(
size
);
if
(
ptr
==
nullptr
)
{
if
(
ptr
==
nullptr
)
{
int
cur_dev
=
platform
::
GetCurrentDeviceId
();
platform
::
CUDADeviceGuard
(
place
.
device
);
platform
::
SetDeviceId
(
place
.
device
);
size_t
avail
,
total
;
size_t
avail
,
total
;
platform
::
GpuMemoryUsage
(
&
avail
,
&
total
);
platform
::
GpuMemoryUsage
(
&
avail
,
&
total
);
LOG
(
FATAL
)
<<
"Cannot allocate "
<<
string
::
HumanReadableSize
(
size
)
LOG
(
FATAL
)
<<
"Cannot allocate "
<<
string
::
HumanReadableSize
(
size
)
...
@@ -206,7 +207,6 @@ void *Alloc<platform::CUDAPlace>(const platform::CUDAPlace &place,
...
@@ -206,7 +207,6 @@ void *Alloc<platform::CUDAPlace>(const platform::CUDAPlace &place,
<<
string
::
HumanReadableSize
(
buddy_allocator
->
GetMaxChunkSize
())
<<
string
::
HumanReadableSize
(
buddy_allocator
->
GetMaxChunkSize
())
<<
"GPU memory used: "
<<
"GPU memory used: "
<<
string
::
HumanReadableSize
(
Used
<
platform
::
CUDAPlace
>
(
place
));
<<
string
::
HumanReadableSize
(
Used
<
platform
::
CUDAPlace
>
(
place
));
platform
::
SetDeviceId
(
cur_dev
);
}
else
{
}
else
{
if
(
FLAGS_benchmark
)
{
if
(
FLAGS_benchmark
)
{
allocation
::
GPUMemMonitor
.
Add
(
place
.
device
,
size
);
allocation
::
GPUMemMonitor
.
Add
(
place
.
device
,
size
);
...
...
paddle/fluid/memory/detail/system_allocator.cc
浏览文件 @
3c6ab799
...
@@ -29,6 +29,9 @@ limitations under the License. */
...
@@ -29,6 +29,9 @@ limitations under the License. */
#include "paddle/fluid/platform/cpu_info.h"
#include "paddle/fluid/platform/cpu_info.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/gpu_info.h"
#include "paddle/fluid/platform/gpu_info.h"
#ifdef PADDLE_WITH_CUDA
#include "paddle/fluid/platform/cuda_device_guard.h"
#endif
DECLARE_bool
(
use_pinned_memory
);
DECLARE_bool
(
use_pinned_memory
);
DECLARE_double
(
fraction_of_gpu_memory_to_use
);
DECLARE_double
(
fraction_of_gpu_memory_to_use
);
...
@@ -104,18 +107,11 @@ void* GPUAllocator::Alloc(size_t* index, size_t size) {
...
@@ -104,18 +107,11 @@ void* GPUAllocator::Alloc(size_t* index, size_t size) {
// CUDA documentation doesn't explain if cudaMalloc returns nullptr
// CUDA documentation doesn't explain if cudaMalloc returns nullptr
// if size is 0. We just make sure it does.
// if size is 0. We just make sure it does.
if
(
size
<=
0
)
return
nullptr
;
if
(
size
<=
0
)
return
nullptr
;
void
*
p
;
int
prev_id
;
cudaGetDevice
(
&
prev_id
);
if
(
prev_id
!=
gpu_id_
)
{
cudaSetDevice
(
gpu_id_
);
}
cudaError_t
result
=
cudaMalloc
(
&
p
,
size
);
paddle
::
platform
::
CUDADeviceGuard
guard
(
gpu_id_
);
if
(
prev_id
!=
gpu_id_
)
{
void
*
p
;
cudaSetDevice
(
prev_id
);
cudaError_t
result
=
cudaMalloc
(
&
p
,
size
);
}
if
(
result
==
cudaSuccess
)
{
if
(
result
==
cudaSuccess
)
{
*
index
=
0
;
*
index
=
0
;
...
@@ -140,7 +136,6 @@ void* GPUAllocator::Alloc(size_t* index, size_t size) {
...
@@ -140,7 +136,6 @@ void* GPUAllocator::Alloc(size_t* index, size_t size) {
void
GPUAllocator
::
Free
(
void
*
p
,
size_t
size
,
size_t
index
)
{
void
GPUAllocator
::
Free
(
void
*
p
,
size_t
size
,
size_t
index
)
{
cudaError_t
err
;
cudaError_t
err
;
if
(
index
==
0
)
{
if
(
index
==
0
)
{
PADDLE_ASSERT
(
gpu_alloc_size_
>=
size
);
PADDLE_ASSERT
(
gpu_alloc_size_
>=
size
);
gpu_alloc_size_
-=
size
;
gpu_alloc_size_
-=
size
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录