monolish  0.14.2
MONOlithic LIner equation Solvers for Highly-parallel architecture
cholesky_cusolver_gpu.cpp
Go to the documentation of this file.
1 #include "../../../include/monolish_blas.hpp"
2 #include "../../../include/monolish_equation.hpp"
3 #include "../../internal/monolish_internal.hpp"
4 
5 #ifdef MONOLISH_USE_NVIDIA_GPU
6 #include "cusolverSp.h"
7 #endif
8 
9 namespace monolish {
10 
11 template <>
12 int equation::Cholesky<matrix::CRS<double>, double>::cusolver_Cholesky(
14  Logger &logger = Logger::get_instance();
15  logger.func_in(monolish_func);
16 
17 #ifdef MONOLISH_USE_NVIDIA_GPU
18  cusolverSpHandle_t sp_handle;
19  cusolverSpCreate(&sp_handle);
20 
21  cusparseMatDescr_t descrA;
22  internal::check_CUDA(cusparseCreateMatDescr(&descrA));
23  internal::check_CUDA(
24  cusparseSetMatType(descrA, CUSPARSE_MATRIX_TYPE_GENERAL));
25  internal::check_CUDA(
26  cusparseSetMatIndexBase(descrA, CUSPARSE_INDEX_BASE_ZERO));
27  internal::check_CUDA(
28  cusparseSetMatDiagType(descrA, CUSPARSE_DIAG_TYPE_NON_UNIT));
29 
30  int n = A.get_row();
31  int nnz = A.get_nnz();
32 
33  double *Dval = A.val.data();
34  int *Dptr = A.row_ptr.data();
35  int *Dind = A.col_ind.data();
36 
37  const double *Drhv = b.data();
38  double *Dsol = x.data();
39 
40 #pragma omp target data use_device_ptr(Dval, Dptr, Dind, Drhv, Dsol)
41  {
42  internal::check_CUDA(cusolverSpDcsrlsvchol(sp_handle, n, nnz, descrA, Dval,
43  Dptr, Dind, Drhv, tol, reorder,
44  Dsol, &singularity));
45  }
46 #else
47  (void)(&A);
48  (void)(&x);
49  (void)(&b);
50  throw std::runtime_error("error sparse Cholesky is only GPU");
51 #endif
52  logger.func_out();
53  return 0;
54 }
55 
56 template <>
57 int equation::Cholesky<matrix::CRS<float>, float>::cusolver_Cholesky(
59  Logger &logger = Logger::get_instance();
60  logger.func_in(monolish_func);
61 #ifdef MONOLISH_USE_NVIDIA_GPU
62 
63  cusolverSpHandle_t sp_handle;
64  cusolverSpCreate(&sp_handle);
65 
66  cusparseMatDescr_t descrA;
67  internal::check_CUDA(cusparseCreateMatDescr(&descrA));
68  internal::check_CUDA(
69  cusparseSetMatType(descrA, CUSPARSE_MATRIX_TYPE_GENERAL));
70  internal::check_CUDA(
71  cusparseSetMatIndexBase(descrA, CUSPARSE_INDEX_BASE_ZERO));
72  internal::check_CUDA(
73  cusparseSetMatDiagType(descrA, CUSPARSE_DIAG_TYPE_NON_UNIT));
74 
75  int n = A.get_row();
76  int nnz = A.get_nnz();
77 
78  float *Dval = A.val.data();
79  int *Dptr = A.row_ptr.data();
80  int *Dind = A.col_ind.data();
81 
82  const float *Drhv = b.data();
83  float *Dsol = x.data();
84 
85 #pragma omp target data use_device_ptr(Dval, Dptr, Dind, Drhv, Dsol)
86  {
87  internal::check_CUDA(cusolverSpScsrlsvchol(sp_handle, n, nnz, descrA, Dval,
88  Dptr, Dind, Drhv, tol, reorder,
89  Dsol, &singularity));
90  }
91 #else
92  (void)(&A);
93  (void)(&x);
94  (void)(&b);
95  // throw std::runtime_error("error sparse Cholesky is only GPU");
96 #endif
97  logger.func_out();
98  return 0;
99 }
100 } // namespace monolish
monolish::matrix::CRS::val
std::vector< Float > val
CRS format value, which stores values of the non-zero elements (size nnz)
Definition: monolish_crs.hpp:68
monolish_func
#define monolish_func
Definition: monolish_logger.hpp:9
monolish::Logger
logger class (singleton, for developper class)
Definition: monolish_logger.hpp:19
monolish::Logger::func_out
void func_out()
Definition: logger_utils.cpp:80
monolish::matrix::CRS::get_nnz
size_t get_nnz() const
get # of non-zeros
Definition: monolish_crs.hpp:261
monolish::equation::Cholesky
Cholesky solver class. It can use set_tol(), get_tol(), set_reorder(), get_singularity().
Definition: monolish_equation.hpp:307
monolish::matrix::CRS::col_ind
std::vector< int > col_ind
CRS format column index, which stores column numbers of the non-zero elements (size nnz)
Definition: monolish_crs.hpp:74
monolish::vector::data
const Float * data() const
returns a direct pointer to the vector
Definition: monolish_vector.hpp:236
monolish::matrix::CRS::get_row
size_t get_row() const
get # of row
Definition: monolish_crs.hpp:243
monolish
Definition: monolish_matrix_blas.hpp:10
monolish::vector
vector class
Definition: monolish_coo.hpp:32
monolish::matrix::CRS::row_ptr
std::vector< int > row_ptr
CRS format row pointer, which stores the starting points of the rows of the arrays value and col_ind ...
Definition: monolish_crs.hpp:80
monolish::Logger::get_instance
static Logger & get_instance()
Definition: monolish_logger.hpp:42
monolish::matrix::CRS
Compressed Row Storage (CRS) format Matrix.
Definition: monolish_coo.hpp:36
monolish::Logger::func_in
void func_in(const std::string func_name)
Definition: logger_utils.cpp:69