Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_cuSOLVER_decl.hpp
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Amesos2: Templated Direct Sparse Solver Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //
42 // @HEADER
43 
44 #ifndef AMESOS2_CUSOLVER_DECL_HPP
45 #define AMESOS2_CUSOLVER_DECL_HPP
46 
47 #include "Amesos2_SolverTraits.hpp"
48 #include "Amesos2_SolverCore.hpp"
49 #include "Amesos2_cuSOLVER_FunctionMap.hpp"
50 
51 namespace Amesos2 {
52 
57 template <class Matrix,
58  class Vector>
59 class cuSOLVER : public SolverCore<Amesos2::cuSOLVER, Matrix, Vector>
60 {
61  friend class SolverCore<Amesos2::cuSOLVER,Matrix,Vector>;
62 
63 public:
64 
66  static const char* name; // declaration. Initialization outside.
67 
68  typedef cuSOLVER<Matrix,Vector> type;
69  typedef SolverCore<Amesos2::cuSOLVER,Matrix,Vector> super_type;
70 
71  typedef typename super_type::scalar_type scalar_type;
72  typedef typename super_type::local_ordinal_type local_ordinal_type;
73  typedef typename super_type::global_ordinal_type global_ordinal_type;
74  typedef typename super_type::global_size_type global_size_type;
75  typedef typename super_type::node_type node_type;
76 
77  typedef TypeMap<Amesos2::cuSOLVER,scalar_type> type_map;
78 
79  typedef typename type_map::type cusolver_type;
80  typedef typename type_map::magnitude_type magnitude_type;
81 
82  typedef FunctionMap<Amesos2::cuSOLVER,cusolver_type> function_map;
83 
84  #ifdef KOKKOS_ENABLE_CUDA
85  // solver will be UVM off
86  typedef Kokkos::Device<Kokkos::Cuda, Kokkos::CudaSpace> device_type;
87  #else
88  typedef Kokkos::DefaultExecutionSpace::device_type device_type;
89  #endif
90 
91  typedef int size_type;
92  typedef int ordinal_type;
93  typedef Kokkos::View<size_type*, device_type> device_size_type_array;
94  typedef Kokkos::View<ordinal_type*, device_type> device_ordinal_type_array;
95  typedef Kokkos::View<cusolver_type*, device_type> device_value_type_array;
96 
98 
99 
106  cuSOLVER(Teuchos::RCP<const Matrix> A,
107  Teuchos::RCP<Vector> X,
108  Teuchos::RCP<const Vector> B);
109 
110 
112  ~cuSOLVER( );
113 
115 
116 private:
117 
121  int preOrdering_impl();
122 
131 
138 
150  int solve_impl(const Teuchos::Ptr<MultiVecAdapter<Vector> > X,
151  const Teuchos::Ptr<const MultiVecAdapter<Vector> > B) const;
152 
156  bool matrixShapeOK_impl() const;
157 
163  void setParameters_impl(
164  const Teuchos::RCP<Teuchos::ParameterList> & parameterList );
165 
172  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters_impl() const;
173 
182  bool loadA_impl(EPhase current_phase);
183 
187  bool do_optimization() const;
188 
189  // struct holds all data necessary to make a superlu factorization or solve call
190  mutable struct cuSolverData {
191  cusolverSpHandle_t handle;
192  csrcholInfo_t chol_info;
193  cusparseMatDescr_t desc;
194  bool bReorder;
195  } data_;
196 
197  typedef Kokkos::View<cusolver_type**, Kokkos::LayoutLeft, device_type> device_solve_array_t;
198 
199  mutable device_solve_array_t xValues_;
200  mutable device_solve_array_t bValues_;
201  mutable device_value_type_array buffer_;
202 
203  device_value_type_array device_nzvals_view_;
204  device_size_type_array device_row_ptr_view_;
205  device_ordinal_type_array device_cols_view_;
206  size_t sorted_nnz;
207 
208  // data for reordering
209  typedef Kokkos::View<ordinal_type*, device_type> permute_array_t;
210  permute_array_t device_perm_;
211  permute_array_t device_peri_;
212  mutable device_solve_array_t permute_result_;
213 }; // End class cuSOLVER
214 
215 template <>
216 struct solver_traits<cuSOLVER> {
217 #ifdef HAVE_TEUCHOS_COMPLEX
218  typedef Meta::make_list6<float, double,
219  std::complex<float>, std::complex<double>,
220  Kokkos::complex<float>, Kokkos::complex<double>>
221  supported_scalars;
222 #else
223  typedef Meta::make_list2<float, double> supported_scalars;
224 #endif
225 };
226 
227 template <typename Scalar, typename LocalOrdinal, typename ExecutionSpace>
228 struct solver_supports_matrix<cuSOLVER,
229  KokkosSparse::CrsMatrix<Scalar, LocalOrdinal, ExecutionSpace>> {
230  static const bool value = true;
231 };
232 
233 } // end namespace Amesos2
234 
235 #endif // AMESOS2_CUSOLVER_DECL_HPP
Amesos2::SolverCore: A templated interface for interaction with third-party direct sparse solvers...
Definition: Amesos2_SolverCore_decl.hpp:105
void setParameters_impl(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Definition: Amesos2_cuSOLVER_def.hpp:278
bool matrixShapeOK_impl() const
Determines whether the shape of the matrix is OK for this solver.
Definition: Amesos2_cuSOLVER_def.hpp:271
Map types to solver-specific data-types and enums.
Definition: Amesos2_TypeMap.hpp:82
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters_impl() const
Definition: Amesos2_cuSOLVER_def.hpp:295
Amesos2 interface to cuSOLVER.
Definition: Amesos2_cuSOLVER_decl.hpp:59
int symbolicFactorization_impl()
Perform symbolic factorization of the matrix using cuSOLVER.
Definition: Amesos2_cuSOLVER_def.hpp:109
bool loadA_impl(EPhase current_phase)
Reads matrix data into internal structures.
Definition: Amesos2_cuSOLVER_def.hpp:318
bool do_optimization() const
can we optimize size_type and ordinal_type for straight pass through
Definition: Amesos2_cuSOLVER_def.hpp:312
int numericFactorization_impl()
cuSOLVER specific numeric factorization
Definition: Amesos2_cuSOLVER_def.hpp:135
std::string name() const override
Return the name of this solver.
Definition: Amesos2_SolverCore_def.hpp:759
Passes functions to TPL functions based on type.
Definition: Amesos2_FunctionMap.hpp:76
Provides access to interesting solver traits.
int preOrdering_impl()
Performs pre-ordering on the matrix to increase efficiency.
Definition: Amesos2_cuSOLVER_def.hpp:86
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:186