26 if (result != cudaSuccess) {
27 throw std::runtime_error(std::string(
"CUDA Runtime Error: ") +
28 cudaGetErrorString(result));
33 if (result != CUBLAS_STATUS_SUCCESS) {
34 throw std::runtime_error(std::string(
"CUBLAS Runtime Error: ") +
41 case CUBLAS_STATUS_SUCCESS:
42 return "CUBLAS_STATUS_SUCCESS";
43 case CUBLAS_STATUS_NOT_INITIALIZED:
44 return "CUBLAS_STATUS_NOT_INITIALIZED";
45 case CUBLAS_STATUS_ALLOC_FAILED:
46 return "CUBLAS_STATUS_ALLOC_FAILED";
47 case CUBLAS_STATUS_INVALID_VALUE:
48 return "CUBLAS_STATUS_INVALID_VALUE";
49 case CUBLAS_STATUS_ARCH_MISMATCH:
50 return "CUBLAS_STATUS_ARCH_MISMATCH";
51 case CUBLAS_STATUS_MAPPING_ERROR:
52 return "CUBLAS_STATUS_MAPPING_ERROR";
53 case CUBLAS_STATUS_EXECUTION_FAILED:
54 return "CUBLAS_STATUS_EXECUTION_FAILED";
55 case CUBLAS_STATUS_INTERNAL_ERROR:
56 return "CUBLAS_STATUS_INTERNAL_ERROR";
57 case CUBLAS_STATUS_NOT_SUPPORTED:
58 return "CUBLAS_STATUS_NOT_SUPPORTED";
59 case CUBLAS_STATUS_LICENSE_ERROR:
60 return "CUBLAS_STATUS_LICENSE_ERROR";
67 cudaError_t err = cudaGetDeviceCount(&count);
68 return (err != cudaSuccess) ? 0 :
Index(count);
72 : ld_(nrows), cols_(ncols) {
77CudaMatrix::operator Eigen::MatrixXd()
const {
78 Eigen::MatrixXd result = Eigen::MatrixXd::Zero(this->rows(), this->cols());
79 checkCuda(cudaMemcpyAsync(result.data(), this->data(), this->size_matrix(),
80 cudaMemcpyDeviceToHost, this->stream_));
81 checkCuda(cudaStreamSynchronize(this->stream_));
88 size_t size_arr)
const {
91 checkCuda(cudaMalloc(&dmatrix, size_arr));
93 [](
double* x) {
checkCuda(cudaFree(x)); });
98 size_t requested_memory)
const {
100 checkCuda(cudaMemGetInfo(&free, &total));
102 std::ostringstream oss;
103 oss <<
"There were requested : " << requested_memory
104 <<
"bytes Index the device\n";
105 oss <<
"Device Free memory (bytes): " << free
106 <<
"\nDevice total Memory (bytes): " << total <<
"\n";
109 if (requested_memory > free) {
110 oss <<
"There is not enough memory in the Device!\n";
111 throw std::runtime_error(oss.str());
116 Eigen::MatrixXd temp = m;
std::unique_ptr< double, void(*)(double *)> Unique_ptr_to_GPU_data
size_t size_matrix() const
Unique_ptr_to_GPU_data data_
void throw_if_not_enough_memory_in_gpu(size_t requested_memory) const
CudaMatrix(const T &matrix, const cudaStream_t &stream)
Unique_ptr_to_GPU_data alloc_matrix_in_gpu(size_t size_arr) const
void checkCublas(cublasStatus_t result)
std::string cudaGetErrorEnum(cublasStatus_t error)
Index count_available_gpus()
void checkCuda(cudaError_t result)
base class for all analysis tools