24 cusparsecsr2dense(cusparseHandle_t cusparse_handle,
26 float *dense_matrix_dev)
28 auto cusparse_matrix =
matrix.get_cusparse_matrix();
30 const cusparseStatus_t cusparse_error_code =
31 cusparseScsr2dense(cusparse_handle,
34 std::get<3>(cusparse_matrix),
35 std::get<0>(cusparse_matrix),
36 std::get<2>(cusparse_matrix),
37 std::get<1>(cusparse_matrix),
46 cusparsecsr2dense(cusparseHandle_t cusparse_handle,
48 double *dense_matrix_dev)
50 auto cusparse_matrix =
matrix.get_cusparse_matrix();
52 const cusparseStatus_t cusparse_error_code =
53 cusparseDcsr2dense(cusparse_handle,
56 std::get<3>(cusparse_matrix),
57 std::get<0>(cusparse_matrix),
58 std::get<2>(cusparse_matrix),
59 std::get<1>(cusparse_matrix),
68 cusolverDngetrf_buffer_size(cusolverDnHandle_t cusolver_dn_handle,
71 float *dense_matrix_dev,
74 const cusolverStatus_t cusolver_error_code = cusolverDnSgetrf_bufferSize(
75 cusolver_dn_handle, m, n, dense_matrix_dev, m, &workspace_size);
82 cusolverDngetrf_buffer_size(cusolverDnHandle_t cusolver_dn_handle,
85 double *dense_matrix_dev,
88 const cusolverStatus_t cusolver_error_code = cusolverDnDgetrf_bufferSize(
89 cusolver_dn_handle, m, n, dense_matrix_dev, m, &workspace_size);
96 cusolverDngetrf(cusolverDnHandle_t cusolver_dn_handle,
99 float *dense_matrix_dev,
100 float *workspace_dev,
104 const cusolverStatus_t cusolver_error_code =
105 cusolverDnSgetrf(cusolver_dn_handle,
119 cusolverDngetrf(cusolverDnHandle_t cusolver_dn_handle,
122 double *dense_matrix_dev,
123 double *workspace_dev,
127 const cusolverStatus_t cusolver_error_code =
128 cusolverDnDgetrf(cusolver_dn_handle,
142 cusolverDngetrs(cusolverDnHandle_t cusolver_dn_handle,
144 float *dense_matrix_dev,
150 const cusolverStatus_t cusolver_error_code =
151 cusolverDnSgetrs(cusolver_dn_handle,
167 cusolverDngetrs(cusolverDnHandle_t cusolver_dn_handle,
169 double *dense_matrix_dev,
175 const cusolverStatus_t cusolver_error_code =
176 cusolverDnDgetrs(cusolver_dn_handle,
192 cusolverSpcsrlsvluHost(cusolverSpHandle_t cusolver_sp_handle,
193 const unsigned int n_rows,
194 const unsigned int nnz,
195 cusparseMatDescr_t descr,
196 const float *val_host,
197 const int *row_ptr_host,
198 const int *column_index_host,
203 const cusolverStatus_t cusolver_error_code =
204 cusolverSpScsrlsvluHost(cusolver_sp_handle,
223 cusolverSpcsrlsvluHost(cusolverSpHandle_t cusolver_sp_handle,
224 const unsigned int n_rows,
226 cusparseMatDescr_t descr,
227 const double *val_host,
228 const int *row_ptr_host,
229 const int *column_index_host,
230 const double *b_host,
234 const cusolverStatus_t cusolver_error_code =
235 cusolverSpDcsrlsvluHost(cusolver_sp_handle,
254 cholesky_factorization(cusolverSpHandle_t cusolver_sp_handle,
259 auto cusparse_matrix =
matrix.get_cusparse_matrix();
262 const cusolverStatus_t cusolver_error_code =
263 cusolverSpScsrlsvchol(cusolver_sp_handle,
265 matrix.n_nonzero_elements(),
266 std::get<3>(cusparse_matrix),
267 std::get<0>(cusparse_matrix),
268 std::get<2>(cusparse_matrix),
269 std::get<1>(cusparse_matrix),
282 cholesky_factorization(cusolverSpHandle_t cusolver_sp_handle,
287 auto cusparse_matrix =
matrix.get_cusparse_matrix();
290 const cusolverStatus_t cusolver_error_code =
291 cusolverSpDcsrlsvchol(cusolver_sp_handle,
293 matrix.n_nonzero_elements(),
294 std::get<3>(cusparse_matrix),
295 std::get<0>(cusparse_matrix),
296 std::get<2>(cusparse_matrix),
297 std::get<1>(cusparse_matrix),
309 template <
typename Number>
311 lu_factorization(cusparseHandle_t cusparse_handle,
312 cusolverDnHandle_t cusolver_dn_handle,
318 const unsigned int m =
matrix.m();
319 const unsigned int n =
matrix.n();
321 Number *dense_matrix_dev;
325 cusparsecsr2dense(cusparse_handle, matrix, dense_matrix_dev);
328 int workspace_size = 0;
329 cusolverDngetrf_buffer_size(
330 cusolver_dn_handle, m, n, dense_matrix_dev, workspace_size);
332 Number *workspace_dev;
341 cusolverDngetrf(cusolver_dn_handle,
351 cudaError_t cuda_error_code_debug =
352 cudaMemcpy(&info, info_dev,
sizeof(
int), cudaMemcpyDeviceToHost);
355 ExcMessage(
"There was a problem during the LU factorization"));
359 cudaError_t cuda_error_code =
360 cudaMemcpy(x_dev, b_dev, m *
sizeof(Number), cudaMemcpyDeviceToDevice);
363 cusolver_dn_handle, m, dense_matrix_dev, pivot_dev, x_dev, info_dev);
366 cudaMemcpy(&info, info_dev,
sizeof(
int), cudaMemcpyDeviceToHost);
380 template <
typename Number>
382 lu_factorization(cusolverSpHandle_t cusolver_sp_handle,
390 const unsigned int nnz =
matrix.n_nonzero_elements();
391 const unsigned int n_rows =
matrix.m();
392 std::vector<Number> val_host(nnz);
393 std::vector<int> column_index_host(nnz);
394 std::vector<int> row_ptr_host(n_rows + 1);
395 auto cusparse_matrix =
matrix.get_cusparse_matrix();
400 std::vector<Number> b_host(n_rows);
402 std::vector<Number> x_host(n_rows);
405 cusolverSpcsrlsvluHost(cusolver_sp_handle,
408 std::get<3>(cusparse_matrix),
411 column_index_host.data(),
422 template <
typename Number>
424 const std::string &solver_type)
425 : solver_type(solver_type)
430 template <
typename Number>
441 template <
typename Number>
445 return solver_control;
450 template <
typename Number>
457 if (additional_data.solver_type ==
"Cholesky")
458 cholesky_factorization(cuda_handle.cusolver_sp_handle,
462 else if (additional_data.solver_type ==
"LU_dense")
463 lu_factorization(cuda_handle.cusparse_handle,
464 cuda_handle.cusolver_dn_handle,
468 else if (additional_data.solver_type ==
"LU_host")
469 lu_factorization(cuda_handle.cusolver_sp_handle,
476 additional_data.solver_type +
" is invalid."));
479 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")