monolish  0.14.2
MONOlithic LIner equation Solvers for Highly-parallel architecture
qr_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::QR<matrix::CRS<double>, double>::cusolver_QR(
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(cusolverSpDcsrlsvqr(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 <>
58  vector<float> &x,
59  vector<float> &b) {
60  Logger &logger = Logger::get_instance();
61  logger.func_in(monolish_func);
62 
63 #ifdef MONOLISH_USE_NVIDIA_GPU
64  cusolverSpHandle_t sp_handle;
65  cusolverSpCreate(&sp_handle);
66 
67  cusparseMatDescr_t descrA;
68  internal::check_CUDA(cusparseCreateMatDescr(&descrA));
69  internal::check_CUDA(
70  cusparseSetMatType(descrA, CUSPARSE_MATRIX_TYPE_GENERAL));
71  internal::check_CUDA(
72  cusparseSetMatIndexBase(descrA, CUSPARSE_INDEX_BASE_ZERO));
73  internal::check_CUDA(
74  cusparseSetMatDiagType(descrA, CUSPARSE_DIAG_TYPE_NON_UNIT));
75 
76  int n = A.get_row();
77  int nnz = A.get_nnz();
78 
79  float *Dval = A.val.data();
80  int *Dptr = A.row_ptr.data();
81  int *Dind = A.col_ind.data();
82 
83  const float *Drhv = b.data();
84  float *Dsol = x.data();
85 
86 #pragma omp target data use_device_ptr(Dval, Dptr, Dind, Drhv, Dsol)
87  {
88  internal::check_CUDA(cusolverSpScsrlsvqr(sp_handle, n, nnz, descrA, Dval,
89  Dptr, Dind, Drhv, tol, reorder,
90  Dsol, &singularity));
91  }
92 #else
93  (void)(&A);
94  (void)(&x);
95  (void)(&b);
96  throw std::runtime_error("error sparse Cholesky is only GPU");
97 #endif
98  logger.func_out();
99  return 0;
100 }
101 } // 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::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::equation::QR
QR solver class (Dense, GPU only now). can use set_tol(), get_tol(), set_reorder(),...
Definition: monolish_equation.hpp:248
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