Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
urhero
Paddle
提交
c4eced98
P
Paddle
项目概览
urhero
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c4eced98
编写于
1月 11, 2019
作者:
C
chengduozh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix thread safe bug
test=develop
上级
358e657f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
13 addition
and
15 deletion
+13
-15
paddle/fluid/platform/device_context.cc
paddle/fluid/platform/device_context.cc
+13
-15
未找到文件。
paddle/fluid/platform/device_context.cc
浏览文件 @
c4eced98
...
@@ -92,26 +92,24 @@ platform::TemporaryAllocator& DeviceTemporaryAllocator::Get(
...
@@ -92,26 +92,24 @@ platform::TemporaryAllocator& DeviceTemporaryAllocator::Get(
const
platform
::
Place
&
place
,
const
cudaStream_t
&
stream
)
{
const
platform
::
Place
&
place
,
const
cudaStream_t
&
stream
)
{
PADDLE_ENFORCE
(
platform
::
is_gpu_place
(
place
));
PADDLE_ENFORCE
(
platform
::
is_gpu_place
(
place
));
auto
place_stream
=
std
::
make_pair
(
place
,
stream
);
auto
place_stream
=
std
::
make_pair
(
place
,
stream
);
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
mtx_
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
mtx_
);
auto
it
=
device_allocator_
.
find
(
place_stream
);
if
(
!
device_allocator_
.
count
(
place_stream
))
{
if
(
it
==
device_allocator_
.
end
())
{
device_allocator_
[
place_stream
].
reset
(
new
TemporaryAllocator
(
place
));
auto
tmp_allocator
=
new
TemporaryAllocator
(
place
);
device_allocator_
[
place_stream
]
->
SetCallback
([
stream
]()
{
tmp_allocator
->
SetCallback
([
stream
]()
{
PADDLE_ENFORCE
(
cudaStreamSynchronize
(
stream
));
PADDLE_ENFORCE
(
cudaStreamSynchronize
(
stream
));
PADDLE_ENFORCE
(
cudaGetLastError
());
PADDLE_ENFORCE
(
cudaGetLastError
());
});
});
}
device_allocator_
[
place_stream
].
reset
(
tmp_allocator
);
return
*
tmp_allocator
;
}
else
{
return
*
it
->
second
;
}
}
return
*
device_allocator_
.
at
(
place_stream
);
}
}
template
<
>
template
<
>
platform
::
TemporaryAllocator
&
DeviceTemporaryAllocator
::
Get
(
platform
::
TemporaryAllocator
&
DeviceTemporaryAllocator
::
Get
(
const
platform
::
CUDADeviceContext
&
dev_ctx
)
{
const
platform
::
CUDADeviceContext
&
dev_ctx
)
{
auto
place_stream
=
std
::
make_pair
(
dev_ctx
.
GetPlace
(),
dev_ctx
.
stream
());
if
(
device_allocator_
.
count
(
place_stream
))
{
return
*
device_allocator_
.
at
(
place_stream
);
}
return
Get
(
dev_ctx
.
GetPlace
(),
dev_ctx
.
stream
());
return
Get
(
dev_ctx
.
GetPlace
(),
dev_ctx
.
stream
());
}
}
#endif
#endif
...
@@ -325,7 +323,7 @@ Place CUDADeviceContext::GetPlace() const { return place_; }
...
@@ -325,7 +323,7 @@ Place CUDADeviceContext::GetPlace() const { return place_; }
void
CUDADeviceContext
::
Wait
()
const
{
void
CUDADeviceContext
::
Wait
()
const
{
auto
&
allocator
=
auto
&
allocator
=
DeviceTemporaryAllocator
::
Instance
().
Get
<
CUDADeviceContext
>
(
*
this
);
DeviceTemporaryAllocator
::
Instance
().
Get
<
CUDADeviceContext
>
(
*
this
);
allocator
.
Release
([
=
]()
{
allocator
.
Release
([
this
]()
{
PADDLE_ENFORCE
(
cudaStreamSynchronize
(
stream_
));
PADDLE_ENFORCE
(
cudaStreamSynchronize
(
stream_
));
PADDLE_ENFORCE
(
cudaGetLastError
());
PADDLE_ENFORCE
(
cudaGetLastError
());
});
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录