From 5398e1a3a68bae3ffe6fa5144ac4d70eb9cd0dc7 Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Sun, 2 Sep 2018 17:44:05 +0800 Subject: [PATCH] fix bugs --- paddle/fluid/platform/device_context.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/paddle/fluid/platform/device_context.cc b/paddle/fluid/platform/device_context.cc index 3d416bb528a..5fb3b054ee2 100644 --- a/paddle/fluid/platform/device_context.cc +++ b/paddle/fluid/platform/device_context.cc @@ -157,19 +157,19 @@ class CudnnHolder { void RunFunc(const std::function& cudnn_func, size_t required_workspace_len) { - framework::RWLockGuard lock_guard(&rw_lock_, - framework::RWLockGuard::Status::kRDLock); + std::lock_guard lock(mtx_); if (required_workspace_len > workspace_len_) { - lock_guard.UnLock(); - lock_guard.WRLock(); ReallocateWorkspace(required_workspace_len); - lock_guard.UnLock(); - lock_guard.RDLock(); } cudnn_func(workspace_); } - ~CudnnHolder() { PADDLE_ENFORCE(dynload::cudnnDestroy(cudnn_handle_)); } + ~CudnnHolder() { + PADDLE_ENFORCE(dynload::cudnnDestroy(cudnn_handle_)); + if (workspace_ != nullptr) { + paddle::memory::Free(place_, workspace_); + } + } private: void ReallocateWorkspace(size_t required_workspace_len) { @@ -194,7 +194,7 @@ class CudnnHolder { const cudaStream_t* stream_; // not owned; const CUDAPlace place_; - framework::RWLock rw_lock_; + std::mutex mtx_; }; CUDADeviceContext::CUDADeviceContext(CUDAPlace place) -- GitLab