VertexCFD  0.0-dev
VertexCFD_LinearSolvers_CusolverGLU.hpp
1 #ifndef VERTEXCFD_LINEARSOLVERS_CUSOLVERGLU_HPP
2 #define VERTEXCFD_LINEARSOLVERS_CUSOLVERGLU_HPP
3 
4 #include "VertexCFD_LinearSolvers_CusolverNonpublic.hpp"
5 #include "VertexCFD_LinearSolvers_LocalDirectSolver.hpp"
6 
7 #include <Teuchos_RCP.hpp>
8 #include <Tpetra_CrsMatrix.hpp>
9 #include <Tpetra_RowMatrix.hpp>
10 
11 #include <cusolverSp.h>
12 #include <cusolverSp_LOWLEVEL_PREVIEW.h>
13 #include <thrust/device_vector.h>
14 
15 namespace VertexCFD
16 {
17 namespace LinearSolvers
18 {
19 //---------------------------------------------------------------------------//
20 // Local preconditioner/solver using cuSOLVER GLU for on-GPU solves.
21 // This class uses the nonpublic GLU solver from the NVIDIA cuSOLVER library.
22 // This is a refactor-based solver where an initial factorization is performed
23 // on the host (using a corresponding cuSOLVER routine) and subsequent
24 // factorizations are performed on the GPU. The initial host-side
25 // factorization can be reused across multiple nonlinear iterations within a
26 // time step as well as multiple time steps. This process assumes that
27 // 1) the sparsity pattern of the matrix does not change, and 2) the locations
28 // of any necessary pivoting that are determined by the host-side
29 // factorization remain valid for all subsequent GPU solves. Effectively,
30 // the GPU solves are utilizing static pivoting. The solver does not currently
31 // attempt to recover if a factorization breaks down due to pivots becoming
32 // stale/invalid.
33 //---------------------------------------------------------------------------//
35 {
36  private:
37  // >>> DATA
38 
39  // Matrix
40  Teuchos::RCP<const Tpetra::RowMatrix<>> _A;
41 
42  // Device-side matrix data
43  thrust::device_vector<int> _A_rowptr;
44  thrust::device_vector<int> _A_colind;
45  thrust::device_vector<double> _A_values;
46 
47  // Host-side matrix data
48  std::vector<int> _A_rowptr_host;
49  std::vector<int> _A_colind_host;
50  std::vector<double> _A_values_host;
51 
52  // Pivoting data
53  double _pivot_threshold;
54  int _reorder;
55 
56  // Scratch space
57  thrust::device_vector<char> _work;
58 
59  // Persistent Cusparse info
60  cusolverSpHandle_t _handle;
61  csrluInfoHost_t _lu_info;
62  csrgluInfo_t _M_info;
63  cusparseMatDescr_t _A_descr, _M_descr;
64 
65  // Status flags
66  bool _matrix_set;
67  bool _initialized;
68  bool _computed;
69 
70  public:
71  // Constructor
72  CusolverGLU(const Teuchos::ParameterList& params);
73 
74  // Update internal matrix
75  void setMatrix(Teuchos::RCP<const Tpetra::RowMatrix<>> A) override;
76 
77  // Inherited interface from LocalDirectSolver
78  void initialize() override;
79  void compute() override;
80 
81  // Inherited interface from LocalDirectSolver
82  void
83  solve(const Tpetra::MultiVector<>& b, Tpetra::MultiVector<>& x) override;
84 
85  private:
86  // Check status condition and throw exception if failed
87  void
88  check_status(cusolverStatus_t stat, const std::string& identifier) const;
89 
90  // Get number of rows in matrix
91  int num_local_rows() const;
92  std::size_t num_local_entries() const;
93  std::size_t max_entries_per_row() const;
94 };
95 
96 //---------------------------------------------------------------------------//
97 
98 } // namespace LinearSolvers
99 } // namespace VertexCFD
100 
101 #endif // VERTEXCFD_LINEARSOLVERS_CUSOLVERGLU_HPP
VertexCFD
Definition: tstMethodManufacturedSolutionBC.cpp:23
VertexCFD::LinearSolvers::CusolverGLU
Definition: VertexCFD_LinearSolvers_CusolverGLU.hpp:35
VertexCFD::LinearSolvers::LocalDirectSolver
Definition: VertexCFD_LinearSolvers_LocalDirectSolver.hpp:19