RAII wrapper for all calls to cuDNN with a cuDNN handle argument. See CudnnAccess::GetHandle() for details.
| 170 | // |
| 171 | // See CudnnAccess::GetHandle() for details. |
| 172 | class CudnnHandle { |
| 173 | public: |
| 174 | // Takes ownership of the executor context and the lock to access cuDNN |
| 175 | // using handle. |
| 176 | CudnnHandle(gpu::ScopedActivateExecutorContext context, |
| 177 | std::unique_ptr<absl::MutexLock> lock, cudnnHandle_t handle) |
| 178 | : context_(std::move(context)), lock_(std::move(lock)), handle_(handle) {} |
| 179 | |
| 180 | // Returns cuDNN handle. To be passed directly to cuDNN APIs, don't keep |
| 181 | // a copy. |
| 182 | cudnnHandle_t handle() const { return handle_; } |
| 183 | |
| 184 | private: |
| 185 | gpu::ScopedActivateExecutorContext context_; |
| 186 | std::unique_ptr<absl::MutexLock> lock_; |
| 187 | cudnnHandle_t handle_; // Not owned. |
| 188 | }; |
| 189 | |
| 190 | } // namespace |
| 191 |