Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
0574915e
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看板
提交
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() {
kids_
.
clear
();
}
std
::
once_flag
feed_variable_flag
;
framework
::
Scope
&
GetGlobalScope
()
{
static
std
::
unique_ptr
<
framework
::
Scope
>
g_scope
{
nullptr
};
std
::
call_once
(
feed_variable_flag
,
[
&
]()
{
g_scope
.
reset
(
new
framework
::
Scope
());
g_scope
->
Var
(
"feed_value"
);
g_scope
->
Var
(
"fetch_value"
);
});
return
*
(
g_scope
.
get
());
static
framework
::
Scope
*
g_scope
=
nullptr
;
if
(
g_scope
==
nullptr
)
{
g_scope
=
new
framework
::
Scope
();
}
return
*
g_scope
;
}
}
// namespace framework
...
...
paddle/memory/memory.cc
浏览文件 @
0574915e
...
...
@@ -14,11 +14,6 @@ limitations under the License. */
#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 "paddle/memory/detail/buddy_allocator.h"
...
...
@@ -32,19 +27,14 @@ namespace memory {
using
BuddyAllocator
=
detail
::
BuddyAllocator
;
std
::
once_flag
cpu_allocator_flag
;
std
::
once_flag
gpu_allocator_flag
;
BuddyAllocator
*
GetCPUBuddyAllocator
()
{
static
std
::
unique_ptr
<
BuddyAllocator
>
a
{
nullptr
};
std
::
call_once
(
cpu_allocator_flag
,
[
&
]()
{
a
.
reset
(
new
BuddyAllocator
(
new
detail
::
CPUAllocator
,
platform
::
CpuMinChunkSize
(),
platform
::
CpuMaxChunkSize
()));
});
return
a
.
get
();
static
detail
::
BuddyAllocator
*
a
=
nullptr
;
if
(
a
==
nullptr
)
{
a
=
new
detail
::
BuddyAllocator
(
new
detail
::
CPUAllocator
,
platform
::
CpuMinChunkSize
(),
platform
::
CpuMaxChunkSize
());
}
return
a
;
}
template
<
>
...
...
@@ -65,35 +55,24 @@ size_t Used<platform::CPUPlace>(platform::CPUPlace place) {
#ifdef PADDLE_WITH_CUDA
BuddyAllocator
*
GetGPUBuddyAllocator
(
int
gpu_id
)
{
using
BuddyAllocVec
=
std
::
vector
<
BuddyAllocator
*>
;
static
std
::
unique_ptr
<
BuddyAllocVec
,
void
(
*
)(
BuddyAllocVec
*
p
)
>
as
{
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
,
[
&
]()
{
static
BuddyAllocator
**
as
=
NULL
;
if
(
as
==
NULL
)
{
int
gpu_num
=
platform
::
GetCUDADeviceCount
();
a
llocators
.
reserve
(
gpu_num
)
;
a
s
=
new
BuddyAllocator
*
[
gpu_num
]
;
for
(
int
gpu
=
0
;
gpu
<
gpu_num
;
gpu
++
)
{
platform
::
SetDeviceId
(
gpu
);
a
llocators
.
emplace_back
(
new
BuddyAllocator
(
new
detail
::
GPUAllocator
,
platform
::
GpuMinChunkSize
(),
platform
::
GpuMaxChunkSize
()
));
a
s
[
gpu
]
=
new
BuddyAllocator
(
new
detail
::
GPUAllocator
,
platform
::
GpuMinChunkSize
(),
platform
::
GpuMaxChunkSize
(
));
}
VLOG
(
3
)
<<
"
\n\n
NOTE: each GPU device use "
<<
FLAGS_fraction_of_gpu_memory_to_use
*
100
<<
"% of GPU memory.
\n
"
<<
"You can set environment variable '"
<<
platform
::
kEnvFractionGpuMemoryToUse
<<
"' to change the fraction of GPU usage.
\n\n
"
;
});
}
platform
::
SetDeviceId
(
gpu_id
);
return
a
llocator
s
[
gpu_id
];
return
as
[
gpu_id
];
}
template
<
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录