Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
c501826f
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
1 年多 前同步成功
通知
696
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c501826f
编写于
8月 31, 2018
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use framework::RWLock
上级
1f36a4c2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
76 addition
and
9 deletion
+76
-9
paddle/fluid/framework/rw_lock.h
paddle/fluid/framework/rw_lock.h
+65
-0
paddle/fluid/platform/device_context.cc
paddle/fluid/platform/device_context.cc
+11
-9
未找到文件。
paddle/fluid/framework/rw_lock.h
浏览文件 @
c501826f
...
...
@@ -56,5 +56,70 @@ struct RWLock {
};
#endif
class
RWLockGuard
{
public:
enum
Status
{
kUnLock
,
kWRLock
,
kRDLock
};
RWLockGuard
(
RWLock
*
rw_lock
,
Status
init_status
)
:
lock_
(
rw_lock
),
status_
(
Status
::
kUnLock
)
{
switch
(
init_status
)
{
case
Status
::
kRDLock
:
{
RDLock
();
break
;
}
case
Status
::
kWRLock
:
{
WRLock
();
break
;
}
}
}
void
WRLock
()
{
switch
(
status_
)
{
case
Status
::
kUnLock
:
{
lock_
->
WRLock
();
break
;
}
case
Status
::
kWRLock
:
{
break
;
}
case
Status
::
kRDLock
:
{
PADDLE_THROW
(
"Please unlock read lock first before invoking write lock."
);
break
;
}
}
}
void
RDLock
()
{
switch
(
status_
)
{
case
Status
::
kUnLock
:
{
lock_
->
RDLock
();
break
;
}
case
Status
::
kRDLock
:
{
break
;
}
case
Status
::
kWRLock
:
{
PADDLE_THROW
(
"Please unlock write lock first before invoking read lock."
);
break
;
}
}
}
void
UnLock
()
{
if
(
status_
!=
Status
::
kUnLock
)
{
lock_
->
UNLock
();
}
}
~
RWLockGuard
()
{
UnLock
();
}
private:
RWLock
*
lock_
;
Status
status_
;
};
}
// namespace framework
}
// namespace paddle
paddle/fluid/platform/device_context.cc
浏览文件 @
c501826f
...
...
@@ -15,12 +15,11 @@ limitations under the License. */
#include <unordered_set>
#include <vector>
#include "paddle/fluid/memory/memory.h"
#ifdef PADDLE_WITH_CUDA
#include
<boost\thread\thread.hpp>
#include
"paddle/fluid/framework/rw_lock.h"
#endif
#include "paddle/fluid/memory/memory.h"
namespace
paddle
{
namespace
platform
{
...
...
@@ -158,9 +157,14 @@ class CudnnHolder {
void
RunFunc
(
const
std
::
function
<
void
(
void
*
)
>&
cudnn_func
,
size_t
required_workspace_len
)
{
boost
::
upgrade_lock
<
boost
::
shared_mutex
>
shared_lock
(
mtx_
);
framework
::
RWLockGuard
lock_guard
(
&
rw_lock_
,
framework
::
RWLockGuard
::
Status
::
kRDLock
);
if
(
required_workspace_len
>
workspace_len_
)
{
ReallocateWorkspace
(
required_workspace_len
,
&
shared_lock
);
lock_guard
.
UnLock
();
lock_guard
.
WRLock
();
ReallocateWorkspace
(
required_workspace_len
);
lock_guard
.
UnLock
();
lock_guard
.
RDLock
();
}
cudnn_func
(
workspace_
);
}
...
...
@@ -168,9 +172,7 @@ class CudnnHolder {
~
CudnnHolder
()
{
PADDLE_ENFORCE
(
dynload
::
cudnnDestroy
(
cudnn_handle_
));
}
private:
void
ReallocateWorkspace
(
size_t
required_workspace_len
,
boost
::
upgrade_lock
<
boost
::
shared_mutex
>*
lock
)
{
boost
::
upgrade_to_unique_lock
<
boost
::
shared_mutex
>
unique_lock
(
*
lock
);
void
ReallocateWorkspace
(
size_t
required_workspace_len
)
{
if
(
required_workspace_len
<=
workspace_len_
)
{
return
;
}
...
...
@@ -192,7 +194,7 @@ class CudnnHolder {
const
cudaStream_t
*
stream_
;
// not owned;
const
CUDAPlace
place_
;
boost
::
shared_mutex
mtx
_
;
framework
::
RWLock
rw_lock
_
;
};
CUDADeviceContext
::
CUDADeviceContext
(
CUDAPlace
place
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录