Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
c774bcbd
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看板
提交
c774bcbd
编写于
11月 07, 2018
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge device_context
test=develop
上级
057a682e
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
25 addition
and
13 deletion
+25
-13
paddle/fluid/platform/device_context.cc
paddle/fluid/platform/device_context.cc
+5
-8
paddle/fluid/platform/device_context.h
paddle/fluid/platform/device_context.h
+20
-5
未找到文件。
paddle/fluid/platform/device_context.cc
浏览文件 @
c774bcbd
...
@@ -160,29 +160,26 @@ class EigenCudaStreamDevice : public Eigen::StreamInterface {
...
@@ -160,29 +160,26 @@ class EigenCudaStreamDevice : public Eigen::StreamInterface {
};
};
CudnnHolder
::
CudnnHolder
(
const
cudaStream_t
*
stream
,
const
CUDAPlace
&
place
)
CudnnHolder
::
CudnnHolder
(
const
cudaStream_t
*
stream
,
const
CUDAPlace
&
place
)
:
workspace_
(
nullptr
),
workspace_len_
(
0
),
stream_
(
stream
),
place_
(
place
)
{
:
workspace_
(
nullptr
),
stream_
(
stream
),
place_
(
place
)
{
PADDLE_ENFORCE
(
dynload
::
cudnnCreate
(
&
cudnn_handle_
));
PADDLE_ENFORCE
(
dynload
::
cudnnCreate
(
&
cudnn_handle_
));
PADDLE_ENFORCE
(
dynload
::
cudnnSetStream
(
cudnn_handle_
,
*
stream_
));
PADDLE_ENFORCE
(
dynload
::
cudnnSetStream
(
cudnn_handle_
,
*
stream_
));
}
}
CudnnHolder
::~
CudnnHolder
()
{
CudnnHolder
::~
CudnnHolder
()
{
PADDLE_ENFORCE
(
dynload
::
cudnnDestroy
(
cudnn_handle_
));
PADDLE_ENFORCE
(
dynload
::
cudnnDestroy
(
cudnn_handle_
));
if
(
workspace_
!=
nullptr
)
{
paddle
::
memory
::
Free
(
place_
,
workspace_
);
}
}
}
void
CudnnHolder
::
ReallocateWorkspace
(
size_t
required_workspace_len
)
{
void
CudnnHolder
::
ReallocateWorkspace
(
size_t
required_workspace_len
)
{
if
(
required_workspace_len
<=
workspace_len_
)
{
if
(
required_workspace_len
<=
WorkspaceSize
()
)
{
return
;
return
;
}
}
if
(
workspace_
!=
nullptr
)
{
if
(
workspace_
!=
nullptr
)
{
// Maybe someone is using the current workspace
// Maybe someone is using the current workspace
PADDLE_ENFORCE
(
cudaStreamSynchronize
(
*
stream_
));
PADDLE_ENFORCE
(
cudaStreamSynchronize
(
*
stream_
));
paddle
::
memory
::
Free
(
place_
,
workspace_
);
workspace_
.
reset
(
);
}
}
workspace_
=
paddle
::
memory
::
Alloc
(
place_
,
required_workspace_len
);
workspace_
=
paddle
::
memory
::
Alloc
(
place_
,
required_workspace_len
,
workspace_len_
=
required_workspace_len
;
paddle
::
memory
::
Allocator
::
kScratchpad
)
;
}
}
CUDADeviceContext
::
CUDADeviceContext
(
CUDAPlace
place
)
CUDADeviceContext
::
CUDADeviceContext
(
CUDAPlace
place
)
...
...
paddle/fluid/platform/device_context.h
浏览文件 @
c774bcbd
...
@@ -16,7 +16,7 @@ limitations under the License. */
...
@@ -16,7 +16,7 @@ limitations under the License. */
#include <string>
#include <string>
#include <unordered_map>
#include <unordered_map>
#include <vector>
#include <vector>
#include "paddle/fluid/memory/malloc.h"
#ifdef PADDLE_WITH_CUDA
#ifdef PADDLE_WITH_CUDA
#include "paddle/fluid/platform/dynload/cublas.h"
#include "paddle/fluid/platform/dynload/cublas.h"
#include "paddle/fluid/platform/dynload/cudnn.h"
#include "paddle/fluid/platform/dynload/cudnn.h"
...
@@ -85,17 +85,32 @@ class CudnnHolder {
...
@@ -85,17 +85,32 @@ class CudnnHolder {
template
<
typename
Callback
>
template
<
typename
Callback
>
void
RunFuncImpl
(
Callback
&&
cudnn_func
,
size_t
required_workspace_len
)
{
void
RunFuncImpl
(
Callback
&&
cudnn_func
,
size_t
required_workspace_len
)
{
if
(
required_workspace_len
>
workspace_len_
)
{
if
(
required_workspace_len
>
WorkspaceSize
()
)
{
ReallocateWorkspace
(
required_workspace_len
);
ReallocateWorkspace
(
required_workspace_len
);
}
}
cudnn_func
(
workspace_
);
cudnn_func
(
WorkspacePtr
());
}
inline
void
*
WorkspacePtr
()
{
if
(
workspace_
)
{
return
workspace_
->
ptr
();
}
else
{
return
nullptr
;
}
}
inline
size_t
WorkspaceSize
()
{
if
(
workspace_
)
{
return
workspace_
->
size
();
}
else
{
return
0
;
}
}
}
std
::
mutex
&
Mutex
()
{
return
mtx_
;
}
std
::
mutex
&
Mutex
()
{
return
mtx_
;
}
cudnnHandle_t
cudnn_handle_
;
cudnnHandle_t
cudnn_handle_
;
void
*
workspace_
;
std
::
unique_ptr
<
memory
::
Allocation
>
workspace_
;
size_t
workspace_len_
;
const
cudaStream_t
*
stream_
;
// not owned;
const
cudaStream_t
*
stream_
;
// not owned;
const
CUDAPlace
place_
;
const
CUDAPlace
place_
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录