Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0574915e
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看板
提交
0574915e
编写于
10月 17, 2017
作者:
W
wangmeng28
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'upstream/develop' into factorization_machine_layer
上级
86053e77
064c3695
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
20 addition
and
45 deletion
+20
-45
paddle/framework/scope.cc
paddle/framework/scope.cc
+5
-9
paddle/memory/memory.cc
paddle/memory/memory.cc
+15
-36
未找到文件。
paddle/framework/scope.cc
浏览文件 @
0574915e
...
@@ -65,16 +65,12 @@ void Scope::DropKids() {
...
@@ -65,16 +65,12 @@ void Scope::DropKids() {
kids_
.
clear
();
kids_
.
clear
();
}
}
std
::
once_flag
feed_variable_flag
;
framework
::
Scope
&
GetGlobalScope
()
{
framework
::
Scope
&
GetGlobalScope
()
{
static
std
::
unique_ptr
<
framework
::
Scope
>
g_scope
{
nullptr
};
static
framework
::
Scope
*
g_scope
=
nullptr
;
std
::
call_once
(
feed_variable_flag
,
[
&
]()
{
if
(
g_scope
==
nullptr
)
{
g_scope
.
reset
(
new
framework
::
Scope
());
g_scope
=
new
framework
::
Scope
();
g_scope
->
Var
(
"feed_value"
);
}
g_scope
->
Var
(
"fetch_value"
);
return
*
g_scope
;
});
return
*
(
g_scope
.
get
());
}
}
}
// namespace framework
}
// namespace framework
...
...
paddle/memory/memory.cc
浏览文件 @
0574915e
...
@@ -14,11 +14,6 @@ limitations under the License. */
...
@@ -14,11 +14,6 @@ limitations under the License. */
#include "paddle/memory/memory.h"
#include "paddle/memory/memory.h"
#include <algorithm> // for transform
#include <cstring> // for memcpy
#include <memory> // for unique_ptr
#include <mutex> // for call_once
#include "glog/logging.h"
#include "glog/logging.h"
#include "paddle/memory/detail/buddy_allocator.h"
#include "paddle/memory/detail/buddy_allocator.h"
...
@@ -32,19 +27,14 @@ namespace memory {
...
@@ -32,19 +27,14 @@ namespace memory {
using
BuddyAllocator
=
detail
::
BuddyAllocator
;
using
BuddyAllocator
=
detail
::
BuddyAllocator
;
std
::
once_flag
cpu_allocator_flag
;
std
::
once_flag
gpu_allocator_flag
;
BuddyAllocator
*
GetCPUBuddyAllocator
()
{
BuddyAllocator
*
GetCPUBuddyAllocator
()
{
static
std
::
unique_ptr
<
BuddyAllocator
>
a
{
nullptr
};
static
detail
::
BuddyAllocator
*
a
=
nullptr
;
if
(
a
==
nullptr
)
{
std
::
call_once
(
cpu_allocator_flag
,
[
&
]()
{
a
=
new
detail
::
BuddyAllocator
(
new
detail
::
CPUAllocator
,
a
.
reset
(
new
BuddyAllocator
(
new
detail
::
CPUAllocator
,
platform
::
CpuMinChunkSize
(),
platform
::
CpuMinChunkSize
(),
platform
::
CpuMaxChunkSize
());
platform
::
CpuMaxChunkSize
()));
}
});
return
a
;
return
a
.
get
();
}
}
template
<
>
template
<
>
...
@@ -65,35 +55,24 @@ size_t Used<platform::CPUPlace>(platform::CPUPlace place) {
...
@@ -65,35 +55,24 @@ 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
)
{
using
BuddyAllocVec
=
std
::
vector
<
BuddyAllocator
*>
;
static
BuddyAllocator
**
as
=
NULL
;
static
std
::
unique_ptr
<
BuddyAllocVec
,
void
(
*
)(
BuddyAllocVec
*
p
)
>
as
{
if
(
as
==
NULL
)
{
new
BuddyAllocVec
,
[](
BuddyAllocVec
*
p
)
{
std
::
for_each
(
p
->
begin
(),
p
->
end
(),
[](
BuddyAllocator
*
p
)
{
delete
p
;
});
}};
// GPU buddy allocators
auto
&
allocators
=
*
as
.
get
();
// GPU buddy allocator initialization
std
::
call_once
(
gpu_allocator_flag
,
[
&
]()
{
int
gpu_num
=
platform
::
GetCUDADeviceCount
();
int
gpu_num
=
platform
::
GetCUDADeviceCount
();
a
llocators
.
reserve
(
gpu_num
)
;
a
s
=
new
BuddyAllocator
*
[
gpu_num
]
;
for
(
int
gpu
=
0
;
gpu
<
gpu_num
;
gpu
++
)
{
for
(
int
gpu
=
0
;
gpu
<
gpu_num
;
gpu
++
)
{
platform
::
SetDeviceId
(
gpu
);
platform
::
SetDeviceId
(
gpu
);
a
llocators
.
emplace_back
(
new
BuddyAllocator
(
new
detail
::
GPUAllocator
,
a
s
[
gpu
]
=
new
BuddyAllocator
(
new
detail
::
GPUAllocator
,
platform
::
GpuMinChunkSize
(),
platform
::
GpuMinChunkSize
(),
platform
::
GpuMaxChunkSize
()
));
platform
::
GpuMaxChunkSize
(
));
}
}
VLOG
(
3
)
<<
"
\n\n
NOTE: each GPU device use "
VLOG
(
3
)
<<
"
\n\n
NOTE: each GPU device use "
<<
FLAGS_fraction_of_gpu_memory_to_use
*
100
<<
"% of GPU memory.
\n
"
<<
FLAGS_fraction_of_gpu_memory_to_use
*
100
<<
"% of GPU memory.
\n
"
<<
"You can set environment variable '"
<<
"You can set environment variable '"
<<
platform
::
kEnvFractionGpuMemoryToUse
<<
platform
::
kEnvFractionGpuMemoryToUse
<<
"' to change the fraction of GPU usage.
\n\n
"
;
<<
"' to change the fraction of GPU usage.
\n\n
"
;
});
}
platform
::
SetDeviceId
(
gpu_id
);
platform
::
SetDeviceId
(
gpu_id
);
return
a
llocator
s
[
gpu_id
];
return
as
[
gpu_id
];
}
}
template
<
>
template
<
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录