Dragon - C++ API
A Computation Graph Virtual Machine Based Deep Learning Framework
Public Member Functions | Static Public Member Functions | List of all members
dragon::CUDAContext Class Reference

#include <context_cuda.h>

Public Member Functions

 CUDAContext (const DeviceOption &option)
 Default Constructor. More...
 
 CUDAContext (const int device_id=0)
 Constructor with the specified device id. More...
 
void SwitchToDevice (const int stream_id)
 Switch to the device with the given stream. More...
 
void SwitchToDevice ()
 Switch to the device of this context. More...
 
void FinishDeviceCompution ()
 Synchronize the dispatched operations. More...
 
void MemsetAsync (size_t nbytes, void *ptr)
 Zero-Reset the memory asynchronously. More...
 
template<class DstContext , class SrcContext >
void MemcpyAsync (size_t nbytes, void *dst, const void *src)
 Copy the memory asynchronously. More...
 
template<typename T , class DstContext , class SrcContext >
void Copy (int n, T *dst, const T *src)
 Copy the memory with given type asynchronously. More...
 
int device_id () const
 Return the device id of this context. More...
 
int stream_id () const
 Return the stream id. More...
 
void set_stream_id (int stream_id)
 Set the stream id. More...
 
cudaStream_t cuda_stream ()
 Return the internal cuda stream. More...
 
cudaStream_t cuda_stream (int device_id, int stream_id)
 Return the specified cuda stream. More...
 
cublasHandle_t cublas_handle ()
 Return the internal cublas handle. More...
 
std::mt19937 * rand_generator ()
 Return the internal random generator. More...
 
curandGenerator_t & curand_generator ()
 Return the internal cuda random generator. More...
 
cudnnHandle_t cudnn_handle ()
 Return the internal cudnn handle. More...
 

Static Public Member Functions

static void * New (size_t nbytes)
 Malloc the memory. More...
 
static void Memset (size_t nbytes, void *ptr)
 Zero-Reset the memory. More...
 
template<class DstContext , class SrcContext >
static void Memcpy (size_t nbytes, void *dst, const void *src)
 Copy the memory. More...
 
template<class DstContext , class SrcContext >
static void MemcpyEx (size_t nbytes, void *dst, const void *src, int device_id)
 Copy the memory [Extended]. More...
 
static void Delete (void *data)
 Free the memory. More...
 
static void SyncStream (cudaStream_t stream)
 Synchronize the specified cuda stream. More...
 
static int active_device_id ()
 Return the active device id of current thread. More...
 
static std::mutex & mutex ()
 Return the global context locker. More...
 
static CUDAObjectobj ()
 Return the thread local cuda object. More...
 

Constructor & Destructor Documentation

◆ CUDAContext() [1/2]

dragon::CUDAContext::CUDAContext ( const DeviceOption &  option)
inline

Default Constructor.

◆ CUDAContext() [2/2]

dragon::CUDAContext::CUDAContext ( const int  device_id = 0)
inline

Constructor with the specified device id.

Member Function Documentation

◆ active_device_id()

static int dragon::CUDAContext::active_device_id ( )
inlinestatic

Return the active device id of current thread.

◆ Copy()

template<typename T , class DstContext , class SrcContext >
void dragon::CUDAContext::Copy ( int  n,
T *  dst,
const T *  src 
)
inline

Copy the memory with given type asynchronously.

◆ cublas_handle()

cublasHandle_t dragon::CUDAContext::cublas_handle ( )
inline

Return the internal cublas handle.

◆ cuda_stream() [1/2]

cudaStream_t dragon::CUDAContext::cuda_stream ( )
inline

Return the internal cuda stream.

◆ cuda_stream() [2/2]

cudaStream_t dragon::CUDAContext::cuda_stream ( int  device_id,
int  stream_id 
)
inline

Return the specified cuda stream.

◆ cudnn_handle()

cudnnHandle_t dragon::CUDAContext::cudnn_handle ( )
inline

Return the internal cudnn handle.

◆ curand_generator()

curandGenerator_t& dragon::CUDAContext::curand_generator ( )
inline

Return the internal cuda random generator.

◆ Delete()

static void dragon::CUDAContext::Delete ( void *  data)
inlinestatic

Free the memory.

◆ device_id()

int dragon::CUDAContext::device_id ( ) const
inline

Return the device id of this context.

◆ FinishDeviceCompution()

void dragon::CUDAContext::FinishDeviceCompution ( )
inline

Synchronize the dispatched operations.

◆ Memcpy()

template<class DstContext , class SrcContext >
static void dragon::CUDAContext::Memcpy ( size_t  nbytes,
void *  dst,
const void *  src 
)
inlinestatic

Copy the memory.

◆ MemcpyAsync()

template<class DstContext , class SrcContext >
void dragon::CUDAContext::MemcpyAsync ( size_t  nbytes,
void *  dst,
const void *  src 
)
inline

Copy the memory asynchronously.

◆ MemcpyEx()

template<class DstContext , class SrcContext >
static void dragon::CUDAContext::MemcpyEx ( size_t  nbytes,
void *  dst,
const void *  src,
int  device_id 
)
inlinestatic

Copy the memory [Extended].

◆ Memset()

static void dragon::CUDAContext::Memset ( size_t  nbytes,
void *  ptr 
)
inlinestatic

Zero-Reset the memory.

◆ MemsetAsync()

void dragon::CUDAContext::MemsetAsync ( size_t  nbytes,
void *  ptr 
)
inline

Zero-Reset the memory asynchronously.

◆ mutex()

static std::mutex& dragon::CUDAContext::mutex ( )
inlinestatic

Return the global context locker.

◆ New()

static void* dragon::CUDAContext::New ( size_t  nbytes)
inlinestatic

Malloc the memory.

◆ obj()

static CUDAObject* dragon::CUDAContext::obj ( )
inlinestatic

Return the thread local cuda object.

◆ rand_generator()

std::mt19937* dragon::CUDAContext::rand_generator ( )
inline

Return the internal random generator.

◆ set_stream_id()

void dragon::CUDAContext::set_stream_id ( int  stream_id)
inline

Set the stream id.

◆ stream_id()

int dragon::CUDAContext::stream_id ( ) const
inline

Return the stream id.

◆ SwitchToDevice() [1/2]

void dragon::CUDAContext::SwitchToDevice ( const int  stream_id)
inline

Switch to the device with the given stream.

◆ SwitchToDevice() [2/2]

void dragon::CUDAContext::SwitchToDevice ( )
inline

Switch to the device of this context.

◆ SyncStream()

static void dragon::CUDAContext::SyncStream ( cudaStream_t  stream)
inlinestatic

Synchronize the specified cuda stream.


The documentation for this class was generated from the following file: