20 #include "../_cu_basic_algebra/cu_matrix_operations.h"
21 #include "../_cuda_utilities/cuda_interface.h"
28 template <
typename DataType>
39 template <
typename DataType>
45 const int num_gpu_devices_):
49 cDenseMatrix<DataType>(A_, num_rows_, num_columns_, A_is_row_major_),
50 cuMatrix<DataType>(num_gpu_devices_),
65 template <
typename DataType>
69 if (this->copied_host_to_device)
72 for (
int device_id = 0; device_id < this->num_gpu_devices; ++device_id)
81 delete[] this->device_A;
82 this->device_A = NULL;
94 template <
typename DataType>
97 if (!this->copied_host_to_device)
100 omp_set_num_threads(this->num_gpu_devices);
103 this->device_A =
new DataType*[this->num_gpu_devices];
111 unsigned int thread_id = omp_get_thread_num();
117 this->device_A[thread_id]);
121 this->copied_host_to_device =
true;
130 template <
typename DataType>
132 const DataType* device_vector,
133 DataType* device_product)
135 assert(this->copied_host_to_device);
141 this->cublas_handle[device_id],
142 this->device_A[device_id],
146 this->A_is_row_major,
155 template <
typename DataType>
157 const DataType* device_vector,
158 const DataType alpha,
159 DataType* device_product)
161 assert(this->copied_host_to_device);
167 this->cublas_handle[device_id],
168 this->device_A[device_id],
173 this->A_is_row_major,
182 template <
typename DataType>
184 const DataType* device_vector,
185 DataType* device_product)
187 assert(this->copied_host_to_device);
193 this->cublas_handle[device_id],
194 this->device_A[device_id],
198 this->A_is_row_major,
207 template <
typename DataType>
209 const DataType* device_vector,
210 const DataType alpha,
211 DataType* device_product)
213 assert(this->copied_host_to_device);
219 this->cublas_handle[device_id],
220 this->device_A[device_id],
225 this->A_is_row_major,
static int get_device()
Gets the current device in multi-gpu applications.
static void del(void *device_array)
Deletes memory on gpu device if its pointer is not NULL, then sets the pointer to NULL.
static ArrayType * alloc(const LongIndexType array_size)
Allocates memory on gpu device. This function creates a pointer and returns it.
static void copy_to_device(const ArrayType *host_array, const LongIndexType array_size, ArrayType *device_array)
Copies memory on host to device memory.
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.
virtual void transpose_dot_plus(const DataType *device_vector, const DataType alpha, DataType *device_product)
virtual void transpose_dot(const DataType *device_vector, DataType *device_product)
virtual void dot_plus(const DataType *device_vector, const DataType alpha, DataType *device_product)
virtual void copy_host_to_device()
Copies the member data from the host memory to the device memory.
virtual void dot(const DataType *device_vector, DataType *device_product)
void initialize_cublas_handle()
Creates a cublasHandle_t object, if not created already.
static void dense_matvec(cublasHandle_t cublas_handle, const DataType *A, const DataType *b, const LongIndexType num_rows, const LongIndexType num_columns, const FlagType A_is_row_major, DataType *c)
Computes the matrix vector multiplication where is a dense matrix.
static void dense_transposed_matvec_plus(cublasHandle_t cublas_handle, const DataType *A, const DataType *b, const DataType alpha, const LongIndexType num_rows, const LongIndexType num_columns, const FlagType A_is_row_major, DataType *c)
Computes where is dense, and is the transpose of the matrix .
static void dense_transposed_matvec(cublasHandle_t cublas_handle, const DataType *A, const DataType *b, const LongIndexType num_rows, const LongIndexType num_columns, const FlagType A_is_row_major, DataType *c)
Computes matrix vector multiplication where is dense, and is the transpose of the matrix .
static void dense_matvec_plus(cublasHandle_t cublas_handle, const DataType *A, const DataType *b, const DataType alpha, const LongIndexType num_rows, const LongIndexType num_columns, const FlagType A_is_row_major, DataType *c)
Computes the operation where is a dense matrix.
Base class for constant matrices.