22 #include "../_cuda_utilities/cuda_interface.h"
29 template <
typename DataType>
34 copied_host_to_device(false),
59 template <
typename DataType>
65 copied_host_to_device(false),
73 if (num_gpu_devices_ == 0)
77 else if (num_gpu_devices_ > device_count)
79 std::cerr <<
"ERROR: Number of requested gpu devices exceeds the " \
80 <<
"number of available gpu devices. Nummber of detected " \
81 <<
"devices are " << device_count <<
" while the " \
82 <<
"requested number of devices are " << num_gpu_devices_ \
102 template <
typename DataType>
106 if (this->cublas_handle != NULL)
109 omp_set_num_threads(this->num_gpu_devices);
114 unsigned int thread_id = omp_get_thread_num();
117 cublasStatus_t status = cublasDestroy(
118 this->cublas_handle[thread_id]);
119 assert(status == CUBLAS_STATUS_SUCCESS);
123 delete[] this->cublas_handle;
124 this->cublas_handle = NULL;
128 if (this->cusparse_handle != NULL)
131 omp_set_num_threads(this->num_gpu_devices);
136 unsigned int thread_id = omp_get_thread_num();
140 this->cusparse_handle[thread_id]);
141 assert(status == CUSPARSE_STATUS_SUCCESS);
145 delete[] this->cusparse_handle;
146 this->cusparse_handle = NULL;
167 template <
typename DataType>
173 return this->cublas_handle[device_id];
184 template <
typename DataType>
187 if (this->cublas_handle == NULL)
190 this->cublas_handle =
new cublasHandle_t[this->num_gpu_devices];
193 omp_set_num_threads(this->num_gpu_devices);
198 unsigned int thread_id = omp_get_thread_num();
201 cublasStatus_t status = cublasCreate(
202 &this->cublas_handle[thread_id]);
203 assert(status == CUBLAS_STATUS_SUCCESS);
216 template <
typename DataType>
219 if (this->cusparse_handle == NULL)
222 this->cusparse_handle =
new cusparseHandle_t[this->num_gpu_devices];
225 omp_set_num_threads(this->num_gpu_devices);
230 unsigned int thread_id = omp_get_thread_num();
234 &this->cusparse_handle[thread_id]);
235 assert(status == CUSPARSE_STATUS_SUCCESS);
251 template <
typename DataType>
254 int device_count = 0;
258 if ((error != cudaSuccess) || (device_count < 1))
260 std::cerr <<
"ERROR: No cuda-capable GPU device was detected on " \
261 <<
"this machine. If a cuda-capable GPU device exists, " \
262 <<
"install its cuda driver. Alternatively, set " \
263 <<
"'gpu=False' to use cpu instead." \
static int get_device()
Gets the current device in multi-gpu applications.
static void set_device(int device_id)
Sets the current device in multi-gpu applications.
Base class for linear operators. This class serves as interface for all derived classes.
void initialize_cusparse_handle()
Creates a cusparseHandle_t object, if not created already.
int query_gpu_devices() const
Before any numerical computation, this method chechs if any gpu device is available on the machine,...
cublasHandle_t get_cublas_handle() const
This function returns a reference to the cublasHandle_t object. The object will be created,...
virtual ~cuLinearOperator()
void initialize_cublas_handle()
Creates a cublasHandle_t object, if not created already.
cudaError_t cudaGetDeviceCount(int *count)
Definition of CUDA's cudaGetDeviceCount function using dynamically loaded cudart library.
cusparseStatus_t cusparseDestroy(cusparseHandle_t handle)
Definition of CUDA's cusparseDestroy function using dynamically loaded cublas library.
cusparseStatus_t cusparseCreate(cusparseHandle_t *handle)
Definition of CUDA's cusparseCreate function using dynamically loaded cublas library.