Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
091ab633
P
Paddle
项目概览
Crayon鑫
/
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看板
未验证
提交
091ab633
编写于
7月 09, 2018
作者:
G
gongweibao
提交者:
GitHub
7月 09, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix singleton. (#11835)
上级
436bb450
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
51 addition
and
34 deletion
+51
-34
paddle/fluid/framework/op_info.cc
paddle/fluid/framework/op_info.cc
+2
-2
paddle/fluid/memory/detail/buddy_allocator.cc
paddle/fluid/memory/detail/buddy_allocator.cc
+3
-2
paddle/fluid/memory/detail/buddy_allocator.h
paddle/fluid/memory/detail/buddy_allocator.h
+4
-3
paddle/fluid/memory/malloc.cc
paddle/fluid/memory/malloc.cc
+42
-27
未找到文件。
paddle/fluid/framework/op_info.cc
浏览文件 @
091ab633
...
@@ -21,8 +21,8 @@ namespace framework {
...
@@ -21,8 +21,8 @@ namespace framework {
// a static local variable is already being initialized.
// a static local variable is already being initialized.
// https://stackoverflow.com/questions/11711920/how-to-implement-multithread-safe-singleton-in-c11-without-using-mutex
// https://stackoverflow.com/questions/11711920/how-to-implement-multithread-safe-singleton-in-c11-without-using-mutex
OpInfoMap
&
OpInfoMap
::
Instance
()
{
OpInfoMap
&
OpInfoMap
::
Instance
()
{
static
OpInfoMap
*
g_op_info_map
=
new
OpInfoMap
()
;
static
OpInfoMap
g_op_info_map
;
return
*
g_op_info_map
;
return
g_op_info_map
;
}
}
}
// namespace framework
}
// namespace framework
}
// namespace paddle
}
// namespace paddle
paddle/fluid/memory/detail/buddy_allocator.cc
浏览文件 @
091ab633
...
@@ -19,8 +19,9 @@ namespace paddle {
...
@@ -19,8 +19,9 @@ namespace paddle {
namespace
memory
{
namespace
memory
{
namespace
detail
{
namespace
detail
{
BuddyAllocator
::
BuddyAllocator
(
SystemAllocator
*
system_allocator
,
BuddyAllocator
::
BuddyAllocator
(
size_t
min_chunk_size
,
size_t
max_chunk_size
)
std
::
unique_ptr
<
SystemAllocator
>
system_allocator
,
size_t
min_chunk_size
,
size_t
max_chunk_size
)
:
min_chunk_size_
(
min_chunk_size
),
:
min_chunk_size_
(
min_chunk_size
),
max_chunk_size_
(
max_chunk_size
),
max_chunk_size_
(
max_chunk_size
),
cache_
(
system_allocator
->
UseGpu
()),
cache_
(
system_allocator
->
UseGpu
()),
...
...
paddle/fluid/memory/detail/buddy_allocator.h
浏览文件 @
091ab633
...
@@ -14,6 +14,7 @@ limitations under the License. */
...
@@ -14,6 +14,7 @@ limitations under the License. */
#pragma once
#pragma once
#include <memory>
#include <mutex> // NOLINT
#include <mutex> // NOLINT
#include <set>
#include <set>
#include <tuple>
#include <tuple>
...
@@ -32,8 +33,8 @@ namespace detail {
...
@@ -32,8 +33,8 @@ namespace detail {
class
BuddyAllocator
{
class
BuddyAllocator
{
public:
public:
BuddyAllocator
(
SystemAllocator
*
system_allocator
,
size_t
min_chunk_size
,
BuddyAllocator
(
std
::
unique_ptr
<
SystemAllocator
>
system_allocator
,
size_t
max_chunk_size
);
size_t
m
in_chunk_size
,
size_t
m
ax_chunk_size
);
~
BuddyAllocator
();
~
BuddyAllocator
();
...
@@ -103,7 +104,7 @@ class BuddyAllocator {
...
@@ -103,7 +104,7 @@ class BuddyAllocator {
private:
private:
/*! Allocate CPU/GPU memory from system */
/*! Allocate CPU/GPU memory from system */
SystemAllocator
*
system_allocator_
;
std
::
unique_ptr
<
SystemAllocator
>
system_allocator_
;
std
::
mutex
mutex_
;
std
::
mutex
mutex_
;
};
};
...
...
paddle/fluid/memory/malloc.cc
浏览文件 @
091ab633
...
@@ -12,6 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -12,6 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include <vector>
#include "paddle/fluid/memory/malloc.h"
#include "paddle/fluid/memory/malloc.h"
#include "glog/logging.h"
#include "glog/logging.h"
...
@@ -34,12 +36,15 @@ namespace memory {
...
@@ -34,12 +36,15 @@ namespace memory {
using
BuddyAllocator
=
detail
::
BuddyAllocator
;
using
BuddyAllocator
=
detail
::
BuddyAllocator
;
BuddyAllocator
*
GetCPUBuddyAllocator
()
{
BuddyAllocator
*
GetCPUBuddyAllocator
()
{
static
std
::
once_flag
init_flag
;
static
detail
::
BuddyAllocator
*
a
=
nullptr
;
static
detail
::
BuddyAllocator
*
a
=
nullptr
;
if
(
a
==
nullptr
)
{
a
=
new
detail
::
BuddyAllocator
(
new
detail
::
CPUAllocator
,
std
::
call_once
(
init_flag
,
[]()
{
platform
::
CpuMinChunkSize
(),
a
=
new
detail
::
BuddyAllocator
(
platform
::
CpuMaxChunkSize
());
std
::
unique_ptr
<
detail
::
SystemAllocator
>
(
new
detail
::
CPUAllocator
),
}
platform
::
CpuMinChunkSize
(),
platform
::
CpuMaxChunkSize
());
});
return
a
;
return
a
;
}
}
...
@@ -68,19 +73,22 @@ size_t Used<platform::CPUPlace>(platform::CPUPlace place) {
...
@@ -68,19 +73,22 @@ size_t Used<platform::CPUPlace>(platform::CPUPlace place) {
#ifdef PADDLE_WITH_CUDA
#ifdef PADDLE_WITH_CUDA
BuddyAllocator
*
GetGPUBuddyAllocator
(
int
gpu_id
)
{
BuddyAllocator
*
GetGPUBuddyAllocator
(
int
gpu_id
)
{
static
BuddyAllocator
**
as
=
NULL
;
static
std
::
once_flag
init_flag
;
if
(
as
==
NULL
)
{
static
detail
::
BuddyAllocator
**
a_arr
=
nullptr
;
std
::
call_once
(
init_flag
,
[
gpu_id
]()
{
int
gpu_num
=
platform
::
GetCUDADeviceCount
();
int
gpu_num
=
platform
::
GetCUDADeviceCount
();
as
=
new
BuddyAllocator
*
[
gpu_num
];
PADDLE_ENFORCE
(
gpu_id
<
gpu_num
,
"gpu_id:%d should < gpu_num:%d"
,
gpu_id
,
for
(
int
gpu
=
0
;
gpu
<
gpu_num
;
gpu
++
)
{
gpu_num
);
as
[
gpu
]
=
nullptr
;
}
a_arr
=
new
BuddyAllocator
*
[
gpu_num
];
}
for
(
int
i
=
0
;
i
<
gpu_num
;
i
++
)
{
platform
::
SetDeviceId
(
gpu_id
);
a_arr
[
i
]
=
nullptr
;
if
(
!
as
[
gpu_id
])
{
platform
::
SetDeviceId
(
i
);
as
[
gpu_id
]
=
new
BuddyAllocator
(
new
detail
::
GPUAllocator
(
gpu_id
),
a_arr
[
i
]
=
new
BuddyAllocator
(
platform
::
GpuMinChunkSize
(),
std
::
unique_ptr
<
detail
::
SystemAllocator
>
(
new
detail
::
GPUAllocator
(
i
)),
platform
::
GpuMaxChunkSize
());
platform
::
GpuMinChunkSize
(),
platform
::
GpuMaxChunkSize
());
VLOG
(
10
)
<<
"
\n\n
NOTE: each GPU device use "
VLOG
(
10
)
<<
"
\n\n
NOTE: each GPU device use "
<<
FLAGS_fraction_of_gpu_memory_to_use
*
100
<<
FLAGS_fraction_of_gpu_memory_to_use
*
100
<<
"% of GPU memory.
\n
"
<<
"% of GPU memory.
\n
"
...
@@ -88,7 +96,10 @@ BuddyAllocator* GetGPUBuddyAllocator(int gpu_id) {
...
@@ -88,7 +96,10 @@ BuddyAllocator* GetGPUBuddyAllocator(int gpu_id) {
<<
"FLAGS_fraction_of_gpu_memory_to_use"
<<
"FLAGS_fraction_of_gpu_memory_to_use"
<<
"' to change the fraction of GPU usage.
\n\n
"
;
<<
"' to change the fraction of GPU usage.
\n\n
"
;
}
}
return
as
[
gpu_id
];
});
platform
::
SetDeviceId
(
gpu_id
);
return
a_arr
[
gpu_id
];
}
}
template
<
>
template
<
>
...
@@ -125,12 +136,16 @@ void Free<platform::CUDAPlace>(platform::CUDAPlace place, void* p) {
...
@@ -125,12 +136,16 @@ void Free<platform::CUDAPlace>(platform::CUDAPlace place, void* p) {
}
}
BuddyAllocator
*
GetCUDAPinnedBuddyAllocator
()
{
BuddyAllocator
*
GetCUDAPinnedBuddyAllocator
()
{
static
BuddyAllocator
*
ba
=
NULL
;
static
std
::
once_flag
init_flag
;
if
(
ba
==
NULL
)
{
static
BuddyAllocator
*
ba
=
nullptr
;
ba
=
new
BuddyAllocator
(
new
detail
::
CUDAPinnedAllocator
,
std
::
call_once
(
init_flag
,
[]()
{
ba
=
new
BuddyAllocator
(
std
::
unique_ptr
<
detail
::
SystemAllocator
>
(
new
detail
::
CUDAPinnedAllocator
),
platform
::
CUDAPinnedMinChunkSize
(),
platform
::
CUDAPinnedMinChunkSize
(),
platform
::
CUDAPinnedMaxChunkSize
());
platform
::
CUDAPinnedMaxChunkSize
());
}
});
return
ba
;
return
ba
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录