Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_cuSOLVER_decl.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Amesos2: Templated Direct Sparse Solver Package
4 //
5 // Copyright 2011 NTESS and the Amesos2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef AMESOS2_CUSOLVER_DECL_HPP
11 #define AMESOS2_CUSOLVER_DECL_HPP
12 
13 #include "Amesos2_SolverTraits.hpp"
14 #include "Amesos2_SolverCore.hpp"
15 #include "Amesos2_cuSOLVER_FunctionMap.hpp"
16 
17 namespace Amesos2 {
18 
23 template <class Matrix,
24  class Vector>
25 class cuSOLVER : public SolverCore<Amesos2::cuSOLVER, Matrix, Vector>
26 {
27  friend class SolverCore<Amesos2::cuSOLVER,Matrix,Vector>;
28 
29 public:
30 
32  static const char* name; // declaration. Initialization outside.
33 
34  typedef cuSOLVER<Matrix,Vector> type;
35  typedef SolverCore<Amesos2::cuSOLVER,Matrix,Vector> super_type;
36 
37  typedef typename super_type::scalar_type scalar_type;
38  typedef typename super_type::local_ordinal_type local_ordinal_type;
39  typedef typename super_type::global_ordinal_type global_ordinal_type;
40  typedef typename super_type::global_size_type global_size_type;
41  typedef typename super_type::node_type node_type;
42 
43  typedef TypeMap<Amesos2::cuSOLVER,scalar_type> type_map;
44 
45  typedef typename type_map::type cusolver_type;
46  typedef typename type_map::magnitude_type magnitude_type;
47 
48  typedef FunctionMap<Amesos2::cuSOLVER,cusolver_type> function_map;
49 
50  #ifdef KOKKOS_ENABLE_CUDA
51  // solver will be UVM off
52  typedef Kokkos::Device<Kokkos::Cuda, Kokkos::CudaSpace> device_type;
53  #else
54  typedef Kokkos::DefaultExecutionSpace::device_type device_type;
55  #endif
56 
57  typedef int size_type;
58  typedef int ordinal_type;
59  typedef Kokkos::View<size_type*, device_type> device_size_type_array;
60  typedef Kokkos::View<ordinal_type*, device_type> device_ordinal_type_array;
61  typedef Kokkos::View<cusolver_type*, device_type> device_value_type_array;
62 
64 
65 
72  cuSOLVER(Teuchos::RCP<const Matrix> A,
73  Teuchos::RCP<Vector> X,
74  Teuchos::RCP<const Vector> B);
75 
76 
78  ~cuSOLVER( );
79 
81 
82 private:
83 
87  int preOrdering_impl();
88 
97 
104 
116  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
117  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
118 
122  bool matrixShapeOK_impl() const;
123 
129  void setParameters_impl(
130  const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
131 
138  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
139 
148  bool loadA_impl(EPhase current_phase);
149 
153  bool do_optimization() const;
154 
155  // struct holds all data necessary to make a superlu factorization or solve call
156  mutable struct cuSolverData {
157  cusolverSpHandle_t handle;
158  csrcholInfo_t chol_info;
159  cusparseMatDescr_t desc;
160  bool bReorder;
161  } data_;
162 
163  typedef Kokkos::View<cusolver_type**, Kokkos::LayoutLeft, device_type> device_solve_array_t;
164 
165  mutable device_solve_array_t xValues_;
166  mutable device_solve_array_t bValues_;
167  mutable device_value_type_array buffer_;
168 
169  device_value_type_array device_nzvals_view_;
170  device_size_type_array device_row_ptr_view_;
171  device_ordinal_type_array device_cols_view_;
172  size_t sorted_nnz;
173 
174  // data for reordering
175  typedef Kokkos::View<ordinal_type*, device_type> permute_array_t;
176  permute_array_t device_perm_;
177  permute_array_t device_peri_;
178  mutable device_solve_array_t permute_result_;
179 }; // End class cuSOLVER
180 
181 template <>
182 struct solver_traits<cuSOLVER> {
183 #ifdef HAVE_TEUCHOS_COMPLEX
184  typedef Meta::make_list6<float, double,
185  std::complex<float>, std::complex<double>,
186  Kokkos::complex<float>, Kokkos::complex<double>>
187  supported_scalars;
188 #else
189  typedef Meta::make_list2<float, double> supported_scalars;
190 #endif
191 };
192 
193 template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
194 struct solver_supports_matrix<cuSOLVER,
195  KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace>> {
196  static const bool value = true;
197 };
198 
199 } // end namespace Amesos2
200 
201 #endif // AMESOS2_CUSOLVER_DECL_HPP
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:71
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition: Amesos2_cuSOLVER_def.hpp:244
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_cuSOLVER_def.hpp:237
Map types to solver-specific data-types and enums.
Definition: Amesos2_TypeMap.hpp:48
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_cuSOLVER_def.hpp:261
Amesos2 interface to cuSOLVER.
Definition: Amesos2_cuSOLVER_decl.hpp:25
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using cuSOLVER.
Definition: Amesos2_cuSOLVER_def.hpp:75
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_cuSOLVER_def.hpp:284
bool do_optimization() const
can we optimize size_type and ordinal_type for straight pass through
Definition: Amesos2_cuSOLVER_def.hpp:278
int numericFactorization_impl()
cuSOLVER specific numeric factorization
Definition: Amesos2_cuSOLVER_def.hpp:101
std::string name() const override
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:725
Passes functions to TPL functions based on type.
Definition: Amesos2_FunctionMap.hpp:42
Provides access to interesting solver traits.
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_cuSOLVER_def.hpp:52
int solve_impl(const Teuchos::Ptr< MultiVecAdapter< Vector > > X, const Teuchos::Ptr< const MultiVecAdapter< Vector > > B) const
cuSOLVER specific solve.
Definition: Amesos2_cuSOLVER_def.hpp:152