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
14#include "Amesos2_SolverCore.hpp"
15#include "Amesos2_cuSOLVER_FunctionMap.hpp"
16
17namespace Amesos2 {
18
27template <class Matrix,
28 class Vector>
29class cuSOLVER : public SolverCore<Amesos2::cuSOLVER, Matrix, Vector>
30{
31 friend class SolverCore<Amesos2::cuSOLVER,Matrix,Vector>;
32
33public:
34
36 static const char* name; // declaration. Initialization outside.
37
38 typedef cuSOLVER<Matrix,Vector> type;
39 typedef SolverCore<Amesos2::cuSOLVER,Matrix,Vector> super_type;
40
41 typedef typename super_type::scalar_type scalar_type;
42 typedef typename super_type::local_ordinal_type local_ordinal_type;
43 typedef typename super_type::global_ordinal_type global_ordinal_type;
44 typedef typename super_type::global_size_type global_size_type;
45 typedef typename super_type::node_type node_type;
46
47 typedef TypeMap<Amesos2::cuSOLVER,scalar_type> type_map;
48
49 typedef typename type_map::type cusolver_type;
50 typedef typename type_map::magnitude_type magnitude_type;
51
52 typedef FunctionMap<Amesos2::cuSOLVER,cusolver_type> function_map;
53
54 #ifdef KOKKOS_ENABLE_CUDA
55 // solver will be UVM off
56 typedef Kokkos::Device<Kokkos::Cuda, Kokkos::CudaSpace> device_type;
57 #else
58 typedef Kokkos::DefaultExecutionSpace::device_type device_type;
59 #endif
60
61 typedef int size_type;
62 typedef int ordinal_type;
63 typedef Kokkos::View<size_type*, device_type> device_size_type_array;
64 typedef Kokkos::View<ordinal_type*, device_type> device_ordinal_type_array;
65 typedef Kokkos::View<cusolver_type*, device_type> device_value_type_array;
66
68
69
76 cuSOLVER(Teuchos::RCP<const Matrix> A,
77 Teuchos::RCP<Vector> X,
78 Teuchos::RCP<const Vector> B);
79
80
82 ~cuSOLVER( );
83
85
86private:
87
91 int preOrdering_impl();
92
103
115
127 int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
128 const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
129
133 bool matrixShapeOK_impl() const;
134
141 const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
142
149 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
150
159 bool loadA_impl(EPhase current_phase);
160
165 void describe_impl(Teuchos::FancyOStream &out,
166 const Teuchos::EVerbosityLevel verbLevel) const;
167
171 bool do_optimization() const;
172
173 // cuSOLVER/cuBLAS handles and options for both threshold-selected paths.
174 mutable struct cuSolverData {
175 cusolverDnHandle_t dn_handle;
176 cusolverSpHandle_t sp_handle;
177 csrcholInfo_t chol_info;
178 cusparseMatDescr_t desc;
179 cublasHandle_t blas_handle;
180 bool bReorder = false;
181 int small_matrix_threshold = 2500;
182 } data_;
183
184 typedef Kokkos::View<cusolver_type**, Kokkos::LayoutLeft, device_type>
185 device_value_type_matrix;
186
187 typedef Kokkos::View<cusolver_type**, Kokkos::LayoutLeft, device_type>
188 device_solve_array_t;
189
190 // Scratch n×n matrix for LU factorization (overwritten by getrf, not used in solve)
191 mutable device_value_type_matrix device_matrix_;
192
193 // Cached explicit inverse A^{-1} (n×n, column-major); used every solve via GEMM
194 mutable device_value_type_matrix device_inverse_;
195
196 // Pivot indices from LU factorization (length n); only needed during numericFactorization
197 mutable Kokkos::View<int*, device_type> device_ipiv_;
198
199 // Scalar device integer for cusolverDn status output
200 mutable Kokkos::View<int, device_type> device_info_;
201
202 // Factorization workspace (length determined by bufferSize query)
203 mutable device_value_type_array buffer_;
204
205 // RHS and solution vectors (column-major, n × nrhs)
206 mutable device_solve_array_t xValues_;
207 mutable device_solve_array_t bValues_;
208
209 device_value_type_array device_nzvals_view_;
210 device_size_type_array device_row_ptr_view_;
211 device_ordinal_type_array device_cols_view_;
212 size_t sorted_nnz;
213
214 // data for reordering
215 typedef Kokkos::View<ordinal_type*, device_type> permute_array_t;
216 permute_array_t device_perm_;
217 permute_array_t device_peri_;
218 mutable device_solve_array_t permute_result_;
219
222 mutable Teuchos::RCP<const Tpetra::Map<local_ordinal_type,
223 global_ordinal_type,
224 node_type>> distributionMap_;
225
226}; // End class cuSOLVER
227
228template <>
229struct solver_traits<cuSOLVER> {
230#ifdef HAVE_TEUCHOS_COMPLEX
231 typedef Meta::make_list6<float, double,
232 std::complex<float>, std::complex<double>,
233 Kokkos::complex<float>, Kokkos::complex<double>>
234 supported_scalars;
235#else
236 typedef Meta::make_list2<float, double> supported_scalars;
237#endif
238};
239
240template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
241struct solver_supports_matrix<cuSOLVER,
242 KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace>> {
243 static const bool value = true;
244};
245
246} // end namespace Amesos2
247
248#endif // AMESOS2_CUSOLVER_DECL_HPP
Provides access to interesting solver traits.
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers.
Definition Amesos2_SolverCore_decl.hpp:72
Amesos2 interface to cuSOLVER sparse Cholesky and dense inverse solves.
Definition Amesos2_cuSOLVER_decl.hpp:30
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition Amesos2_cuSOLVER_def.hpp:438
void describe_impl(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Prints the status information about the current solver with some level of verbosity.
Definition Amesos2_cuSOLVER_def.hpp:510
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition Amesos2_cuSOLVER_def.hpp:99
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition Amesos2_cuSOLVER_def.hpp:494
static const char * name
Name of this solver interface.
Definition Amesos2_cuSOLVER_decl.hpp:36
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition Amesos2_cuSOLVER_def.hpp:431
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:292
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition Amesos2_cuSOLVER_def.hpp:467
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using cuSOLVER.
Definition Amesos2_cuSOLVER_def.hpp:123
bool do_optimization() const
can we optimize size_type and ordinal_type for straight pass through
Definition Amesos2_cuSOLVER_def.hpp:488
int numericFactorization_impl()
cuSOLVER specific numeric factorization
Definition Amesos2_cuSOLVER_def.hpp:181
Teuchos::RCP< const Tpetra::Map< local_ordinal_type, global_ordinal_type, node_type > > distributionMap_
Definition Amesos2_cuSOLVER_decl.hpp:224
Passes functions to TPL functions based on type.
Definition Amesos2_FunctionMap.hpp:43
Map types to solver-specific data-types and enums.
Definition Amesos2_TypeMap.hpp:48
Provides traits about solvers.
Definition Amesos2_SolverTraits.hpp:37