Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
cuda_precondition.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_cuda_precondition_h
17 #define dealii_cuda_precondition_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <deal.II/base/cuda.h>
22 #include <deal.II/base/smartpointer.h>
23 
24 #include <memory>
25 
26 #ifdef DEAL_II_COMPILER_CUDA_AWARE
27 
28 DEAL_II_NAMESPACE_OPEN
29 
30 // forward-definition
31 namespace LinearAlgebra
32 {
33  namespace CUDAWrappers
34  {
35  template <typename Number>
36  class Vector;
37  }
38 } // namespace LinearAlgebra
39 
40 namespace CUDAWrappers
41 {
42  // forward definition
43  template <typename Number>
44  class SparseMatrix;
45 
61  template <typename Number>
63  {
64  public:
68  using size_type = int;
69 
75  {
82 
91  };
92 
97 
101  PreconditionIC(const PreconditionIC<Number> &) = delete;
102 
107  operator=(const PreconditionIC<Number> &) = delete;
108 
112  ~PreconditionIC();
113 
123  void
124  initialize(const SparseMatrix<Number> &matrix,
125  const AdditionalData & additional_data = AdditionalData());
126 
130  void
133 
138  void
141 
149  size_type
150  m() const;
151 
159  size_type
160  n() const;
161 
162  private:
166  cusparseHandle_t cusparse_handle;
167 
171  cusparseMatDescr_t descr_M;
172 
176  cusparseMatDescr_t descr_L;
177 
181  csric02Info_t info_M;
182 
186  csrsv2Info_t info_L;
187 
191  csrsv2Info_t info_Lt;
192 
197 
202  std::unique_ptr<Number[], void (*)(Number *)> P_val_dev;
203 
208  const int *P_row_ptr_dev;
209 
214  const int *P_column_index_dev;
215 
220  std::unique_ptr<Number[], void (*)(Number *)> tmp_dev;
221 
226  std::unique_ptr<void, void (*)(void *)> buffer_dev;
227 
233  cusparseSolvePolicy_t policy_L;
234 
240  cusparseSolvePolicy_t policy_Lt;
241 
246  cusparseSolvePolicy_t policy_M;
247 
252  int n_rows;
253 
259  };
260 
276  template <typename Number>
278  {
279  public:
283  using size_type = int;
284 
290  {
296  AdditionalData(bool use_level_analysis = true);
297 
306  };
307 
312 
316  PreconditionILU(const PreconditionILU<Number> &) = delete;
317 
322  operator=(const PreconditionILU<Number> &) = delete;
323 
328 
338  void
339  initialize(const SparseMatrix<Number> &matrix,
340  const AdditionalData & additional_data = AdditionalData());
341 
345  void
348 
352  void
355 
363  size_type
364  m() const;
365 
373  size_type
374  n() const;
375 
376  private:
380  cusparseHandle_t cusparse_handle;
381 
385  cusparseMatDescr_t descr_M;
386 
390  cusparseMatDescr_t descr_L;
391 
395  cusparseMatDescr_t descr_U;
396 
400  csrilu02Info_t info_M;
401 
405  csrsv2Info_t info_L;
406 
410  csrsv2Info_t info_U;
411 
416 
421  std::unique_ptr<Number[], void (*)(Number *)> P_val_dev;
422 
427  const int *P_row_ptr_dev;
428 
433  const int *P_column_index_dev;
434 
439  std::unique_ptr<Number[], void (*)(Number *)> tmp_dev;
440 
445  std::unique_ptr<void, void (*)(void *)> buffer_dev;
446 
452  cusparseSolvePolicy_t policy_L;
453 
459  cusparseSolvePolicy_t policy_U;
460 
465  cusparseSolvePolicy_t policy_M;
466 
471  int n_rows;
472 
478  };
479 
480  /*--------------------------- inline functions ----------------------------*/
481 
482 # ifndef DOXYGEN
483  template <typename Number>
484  inline typename PreconditionIC<Number>::size_type
486  {
487  return n_rows;
488  }
489 
490 
491 
492  template <typename Number>
493  inline typename PreconditionIC<Number>::size_type
495  {
496  return n_rows;
497  }
498 
499 
500 
501  template <typename Number>
502  inline typename PreconditionILU<Number>::size_type
504  {
505  return n_rows;
506  }
507 
508 
509 
510  template <typename Number>
511  inline typename PreconditionILU<Number>::size_type
513  {
514  return n_rows;
515  }
516 # endif // DOXYGEN
517 
518 } // namespace CUDAWrappers
519 
520 DEAL_II_NAMESPACE_CLOSE
521 
522 #endif // DEAL_II_WITH_CUDA
523 
524 #endif // dealii_cuda_precondition_h
std::unique_ptr< void, void(*)(void *)> buffer_dev
cusparseSolvePolicy_t policy_L
void vmult(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &src) const
void initialize(const SparseMatrix< Number > &matrix, const AdditionalData &additional_data=AdditionalData())
cusparseSolvePolicy_t policy_L
PreconditionIC & operator=(const PreconditionIC< Number > &)=delete
PreconditionILU & operator=(const PreconditionILU< Number > &)=delete
AdditionalData(bool use_level_analysis=true)
SmartPointer< const SparseMatrix< Number > > matrix_pointer
cusparseSolvePolicy_t policy_M
cusparseSolvePolicy_t policy_Lt
SmartPointer< const SparseMatrix< Number > > matrix_pointer
AdditionalData(bool use_level_analysis=true)
cusparseSolvePolicy_t policy_M
void Tvmult(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &src) const
std::unique_ptr< Number[], void(*)(Number *)> P_val_dev
std::unique_ptr< Number[], void(*)(Number *)> tmp_dev
void vmult(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &src) const
void Tvmult(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &src) const
PreconditionILU(const Utilities::CUDA::Handle &handle)
PreconditionIC(const Utilities::CUDA::Handle &handle)
void initialize(const SparseMatrix< Number > &matrix, const AdditionalData &additional_data=AdditionalData())
std::unique_ptr< Number[], void(*)(Number *)> P_val_dev
cusparseSolvePolicy_t policy_U
std::unique_ptr< void, void(*)(void *)> buffer_dev
std::unique_ptr< Number[], void(*)(Number *)> tmp_dev