25 cusparsecsr2dense(cusparseHandle_t cusparse_handle,
27 float * dense_matrix_dev)
29 auto cusparse_matrix =
matrix.get_cusparse_matrix();
31 const cusparseStatus_t cusparse_error_code =
32 cusparseScsr2dense(cusparse_handle,
35 std::get<3>(cusparse_matrix),
36 std::get<0>(cusparse_matrix),
37 std::get<2>(cusparse_matrix),
38 std::get<1>(cusparse_matrix),
47 cusparsecsr2dense(cusparseHandle_t cusparse_handle,
49 double * dense_matrix_dev)
51 auto cusparse_matrix =
matrix.get_cusparse_matrix();
53 const cusparseStatus_t cusparse_error_code =
54 cusparseDcsr2dense(cusparse_handle,
57 std::get<3>(cusparse_matrix),
58 std::get<0>(cusparse_matrix),
59 std::get<2>(cusparse_matrix),
60 std::get<1>(cusparse_matrix),
69 cusolverDngetrf_buffer_size(cusolverDnHandle_t cusolver_dn_handle,
72 float * dense_matrix_dev,
75 const cusolverStatus_t cusolver_error_code = cusolverDnSgetrf_bufferSize(
76 cusolver_dn_handle, m, n, dense_matrix_dev, m, &workspace_size);
83 cusolverDngetrf_buffer_size(cusolverDnHandle_t cusolver_dn_handle,
86 double * dense_matrix_dev,
89 const cusolverStatus_t cusolver_error_code = cusolverDnDgetrf_bufferSize(
90 cusolver_dn_handle, m, n, dense_matrix_dev, m, &workspace_size);
97 cusolverDngetrf(cusolverDnHandle_t cusolver_dn_handle,
100 float * dense_matrix_dev,
101 float * workspace_dev,
105 const cusolverStatus_t cusolver_error_code =
106 cusolverDnSgetrf(cusolver_dn_handle,
120 cusolverDngetrf(cusolverDnHandle_t cusolver_dn_handle,
123 double * dense_matrix_dev,
124 double * workspace_dev,
128 const cusolverStatus_t cusolver_error_code =
129 cusolverDnDgetrf(cusolver_dn_handle,
143 cusolverDngetrs(cusolverDnHandle_t cusolver_dn_handle,
145 float * dense_matrix_dev,
151 const cusolverStatus_t cusolver_error_code =
152 cusolverDnSgetrs(cusolver_dn_handle,
168 cusolverDngetrs(cusolverDnHandle_t cusolver_dn_handle,
170 double * dense_matrix_dev,
176 const cusolverStatus_t cusolver_error_code =
177 cusolverDnDgetrs(cusolver_dn_handle,
193 cusolverSpcsrlsvluHost(cusolverSpHandle_t cusolver_sp_handle,
194 const unsigned int n_rows,
195 const unsigned int nnz,
196 cusparseMatDescr_t descr,
197 const float * val_host,
198 const int * row_ptr_host,
199 const int * column_index_host,
200 const float * b_host,
204 const cusolverStatus_t cusolver_error_code =
205 cusolverSpScsrlsvluHost(cusolver_sp_handle,
224 cusolverSpcsrlsvluHost(cusolverSpHandle_t cusolver_sp_handle,
225 const unsigned int n_rows,
227 cusparseMatDescr_t descr,
228 const double * val_host,
229 const int * row_ptr_host,
230 const int * column_index_host,
231 const double * b_host,
235 const cusolverStatus_t cusolver_error_code =
236 cusolverSpDcsrlsvluHost(cusolver_sp_handle,
255 cholesky_factorization(cusolverSpHandle_t cusolver_sp_handle,
260 auto cusparse_matrix =
matrix.get_cusparse_matrix();
263 const cusolverStatus_t cusolver_error_code =
264 cusolverSpScsrlsvchol(cusolver_sp_handle,
266 matrix.n_nonzero_elements(),
267 std::get<3>(cusparse_matrix),
268 std::get<0>(cusparse_matrix),
269 std::get<2>(cusparse_matrix),
270 std::get<1>(cusparse_matrix),
283 cholesky_factorization(cusolverSpHandle_t cusolver_sp_handle,
288 auto cusparse_matrix =
matrix.get_cusparse_matrix();
291 const cusolverStatus_t cusolver_error_code =
292 cusolverSpDcsrlsvchol(cusolver_sp_handle,
294 matrix.n_nonzero_elements(),
295 std::get<3>(cusparse_matrix),
296 std::get<0>(cusparse_matrix),
297 std::get<2>(cusparse_matrix),
298 std::get<1>(cusparse_matrix),
310 template <
typename Number>
312 lu_factorization(cusparseHandle_t cusparse_handle,
313 cusolverDnHandle_t cusolver_dn_handle,
315 const Number * b_dev,
319 unsigned int const m =
matrix.m();
320 unsigned int const n =
matrix.n();
322 Number *dense_matrix_dev;
326 cusparsecsr2dense(cusparse_handle, matrix, dense_matrix_dev);
329 int workspace_size = 0;
330 cusolverDngetrf_buffer_size(
331 cusolver_dn_handle, m, n, dense_matrix_dev, workspace_size);
333 Number *workspace_dev;
342 cusolverDngetrf(cusolver_dn_handle,
352 cudaError_t cuda_error_code_debug =
353 cudaMemcpy(&info, info_dev,
sizeof(
int), cudaMemcpyDeviceToHost);
356 ExcMessage(
"There was a problem during the LU factorization"));
360 cudaError_t cuda_error_code =
361 cudaMemcpy(x_dev, b_dev, m *
sizeof(Number), cudaMemcpyDeviceToDevice);
364 cusolver_dn_handle, m, dense_matrix_dev, pivot_dev, x_dev, info_dev);
367 cudaMemcpy(&info, info_dev,
sizeof(
int), cudaMemcpyDeviceToHost);
381 template <
typename Number>
383 lu_factorization(cusolverSpHandle_t cusolver_sp_handle,
385 const Number * b_dev,
391 const unsigned int nnz =
matrix.n_nonzero_elements();
392 const unsigned int n_rows =
matrix.m();
393 std::vector<Number> val_host(nnz);
394 std::vector<int> column_index_host(nnz);
395 std::vector<int> row_ptr_host(n_rows + 1);
396 auto cusparse_matrix =
matrix.get_cusparse_matrix();
401 std::vector<Number> b_host(n_rows);
403 std::vector<Number> x_host(n_rows);
406 cusolverSpcsrlsvluHost(cusolver_sp_handle,
409 std::get<3>(cusparse_matrix),
412 column_index_host.data(),
423 template <
typename Number>
425 const std::string &solver_type)
426 : solver_type(solver_type)
431 template <
typename Number>
442 template <
typename Number>
446 return solver_control;
451 template <
typename Number>
458 if (additional_data.solver_type ==
"Cholesky")
459 cholesky_factorization(cuda_handle.cusolver_sp_handle,
463 else if (additional_data.solver_type ==
"LU_dense")
464 lu_factorization(cuda_handle.cusparse_handle,
465 cuda_handle.cusolver_dn_handle,
469 else if (additional_data.solver_type ==
"LU_host")
470 lu_factorization(cuda_handle.cusolver_sp_handle,
477 additional_data.solver_type +
" is invalid."));
480 solver_control.check(0, 0);
SolverControl & solver_control
const Utilities::CUDA::Handle & cuda_handle
SolverDirect(const Utilities::CUDA::Handle &handle, SolverControl &cn, const AdditionalData &data=AdditionalData())
const AdditionalData additional_data
void solve(const SparseMatrix< Number > &A, LinearAlgebra::CUDAWrappers::Vector< Number > &x, const LinearAlgebra::CUDAWrappers::Vector< Number > &b)
SolverControl & control() const
Number * get_values() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define AssertCusparse(error_code)
#define Assert(cond, exc)
#define AssertCusolver(error_code)
#define AssertCuda(error_code)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
@ matrix
Contents is actually a matrix.
void malloc(T *&pointer, const unsigned int n_elements)
void copy_to_host(const ArrayView< const T, MemorySpace::CUDA > &in, ArrayView< T, MemorySpace::Host > &out)
void copy_to_dev(const ArrayView< const T, MemorySpace::Host > &in, ArrayView< T, MemorySpace::CUDA > &out)
AdditionalData(const std::string &solver_type="LU_dense")