39 #include <cuda_runtime.h>
42 #include <cusparse_v2.h>
45 #include <cublas_v2.h>
62 unsigned int s =
static_cast<unsigned int>(status );
67 #define CUDA_CHECK_STATUS(status ) CudaCheckStatus(status, __FILE__, __LINE__)
69 #define CUDA_CHECK_SUCCESS(err, desc) \
70 if(err != cudaSuccess)\
72 UG_THROW("Error in " << __FUNCTION__ << ": CUDA ERROR " << err <<":\n" <<\
73 ug::CUDAError(err) << "\n----------------------------\n" << desc << "\n");\
80 UG_DLOG(
DID_CUDA, 2,
"CUDA: Allocating " <<
sizeof(T)*N <<
" bytes.\n");
83 cudaError_t err = cudaMalloc ((
void**) &
p,
sizeof(T)*N);
84 if(err != cudaSuccess)
86 UG_THROW(
"Error in " << __FUNCTION__ <<
"when allocating " <<
sizeof(T)*N <<
" bytes. CUDA ERROR " << err <<
": " <<
114 size_t N = n*
sizeof(T);
117 UG_DLOG(
DID_CUDA, 2,
"CUDA: Allocating Temp Buffer " << N <<
" bytes.\n");
149 "cudaMemcpy vec size " << vec.size());
158 "cudaMemcpy dest size " << dest.size())
165 UG_DLOG(
DID_CUDA, 2,
"Create and Copying " << vec.size() <<
" to host\n");
169 "Error at cudaMalloc of " << N <<
" bytes");
179 cudaMemcpy(&t,
p+i,
sizeof(T), cudaMemcpyDeviceToHost);
Definition: cuda_manager.h:94
static cublasHandle_t get_cublasHandle()
Definition: cuda_manager.h:108
cublasHandle_t cublasHandle
Definition: cuda_manager.h:136
T * get_temp_return_buffer()
Definition: cuda_manager.h:127
void init()
Definition: cuda_manager.cpp:83
static int get_max_multiprocessor_cuda_device()
Definition: cuda_manager.cpp:54
static cusparseHandle_t get_cusparseHandle()
Definition: cuda_manager.h:102
cusparseHandle_t cusparseHandle
Definition: cuda_manager.h:104
size_t m_maxThreadsPerBlock
Definition: cuda_manager.h:109
void * m_tempRetBuffer
Definition: cuda_manager.h:138
void * m_tempBuffer
Definition: cuda_manager.h:137
static CUDAManager & get_instance()
Definition: cuda_manager.cpp:153
size_t m_tempSize
Definition: cuda_manager.h:139
virtual ~CUDAManager()
Definition: cuda_manager.cpp:68
T * get_temp_buffer(size_t n)
Definition: cuda_manager.h:112
static void get_cuda_devices(std::vector< cudaDeviceProp > &devices)
Definition: cuda_manager.cpp:45
Definition: debug_id.h:94
#define CUDA_CHECK_SUCCESS(err, desc)
Definition: cuda_manager.h:69
#define UG_THROW(msg)
Definition: error.h:57
#define UG_DLOG(__debugID__, level, msg)
Definition: log.h:298
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
T * MyCudaAlloc(size_t N)
Definition: cuda_manager.h:78
DebugID DID_CUDA("CUDA")
Definition: cuda_manager.h:55
void CudaCpyToHost(T &dest, typename T::value_type *src)
Definition: cuda_manager.h:153
void CudaCpyToDevice(typename T::value_type *dest, T &vec)
Definition: cuda_manager.h:144
T CUDA_GetElementFromDevice(T *p, size_t i=0)
Definition: cuda_manager.h:176
T::value_type * CudaCreateAndCopyToDevice(T &vec)
Definition: cuda_manager.h:163
const char * CUDAError(int err)
Definition: cuda_error.cpp:35
void CudaCheckStatus(T status, const char *file, int line)
Definition: cuda_manager.h:60
T value_type
Definition: sparsematrix_interface.h:2