tf::cublasScopedPerThreadHandle class

class to provide RAII-styled guard of cublas handle acquisition

Sample usage:

{
  tf::cublasScopedPerThreadHandle handle(1);  // acquires a cublas handle on device 1

  // use handle as a normal cublas handle (cublasHandle_t)
  cublasSetStream(handle, stream);

}  // leaving the scope to release the handle back to the pool on device 1

By default, the cublas handle has a pointer mode set to device (i.e., CUBLAS_POINTER_MODE_DEVICE), that is required for capturing cublas kernels. The scoped per-thread cublas handle is primarily used by tf::cublasFlowCapturer.

cublasScopedPerThreadHandle is non-copyable.

Constructors, destructors, conversion operators

cublasScopedPerThreadHandle(int d) explicit
constructs a scoped handle under the given device context
cublasScopedPerThreadHandle()
constructs a scoped handle under caller's device context
~cublasScopedPerThreadHandle()
destructs the scoped handle guard
operator cublasHandle_t() const
implicit conversion to the native cublas handle (cublasHandle_t)
cublasScopedPerThreadHandle(const cublasScopedPerThreadHandle&) deleted
disabled copy constructor
cublasScopedPerThreadHandle(cublasScopedPerThreadHandle&&) defaulted
default move constructor

Public functions

auto use_count() const -> long
returns the number of shared owners
auto operator=(const cublasScopedPerThreadHandle&) -> cublasScopedPerThreadHandle& deleted
disabled copy assignment
auto operator=(cublasScopedPerThreadHandle&&) -> cublasScopedPerThreadHandle& deleted
default move assignment

Function documentation

tf::cublasScopedPerThreadHandle::cublasScopedPerThreadHandle(int d) explicit

constructs a scoped handle under the given device context

The constructor acquires a handle from a per-thread handle pool.

tf::cublasScopedPerThreadHandle::cublasScopedPerThreadHandle()

constructs a scoped handle under caller's device context

The constructor acquires a handle from a per-thread handle pool.

tf::cublasScopedPerThreadHandle::~cublasScopedPerThreadHandle()

destructs the scoped handle guard

The destructor releases the handle to the per-thread handle pool.