Reference documentation for deal.II version 9.1.0-pre
cuda_sparse_matrix.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_sparse_matrix_h
17 #define dealii_cuda_sparse_matrix_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <deal.II/base/subscriptor.h>
22 
23 #ifdef DEAL_II_WITH_CUDA
24 # include <deal.II/base/cuda.h>
25 
26 # include <deal.II/lac/cuda_vector.h>
27 # include <deal.II/lac/sparse_matrix.h>
28 
29 # include <cusparse.h>
30 
31 DEAL_II_NAMESPACE_OPEN
32 
33 namespace CUDAWrappers
34 {
47  template <typename Number>
48  class SparseMatrix : public virtual Subscriptor
49  {
50  public:
54  using size_type = unsigned int;
55 
59  using value_type = Number;
60 
65  using real_type = Number;
66 
78  SparseMatrix();
79 
86  const ::SparseMatrix<Number> &sparse_matrix_host);
87 
93 
98 
102  ~SparseMatrix();
103 
109  void
111  const ::SparseMatrix<Number> &sparse_matrix_host);
113 
122  size_type
123  m() const;
124 
129  size_type
130  n() const;
131 
137  std::size_t
138  n_nonzero_elements() const;
140 
148  SparseMatrix &
149  operator*=(const Number factor);
150 
154  SparseMatrix &
155  operator/=(const Number factor);
157 
166  void
169 
175  void
178 
183  void
186 
192  void
195 
205  Number
208 
212  Number
216 
224  Number
229 
240  Number
241  l1_norm() const;
242 
250  Number
251  linfty_norm() const;
252 
257  Number
258  frobenius_norm() const;
260 
270  std::tuple<Number *, int *, int *, cusparseMatDescr_t>
271  get_cusparse_matrix() const;
273 
274  private:
279  mutable cusparseHandle_t cusparse_handle;
280 
284  int nnz;
285 
289  int n_rows;
290 
294  int n_cols;
295 
299  Number *val_dev;
300 
305 
310 
314  cusparseMatDescr_t descr;
315  };
316 
317 
318 
319  template <typename Number>
320  inline unsigned int
322  {
323  return n_rows;
324  }
325 
326 
327 
328  template <typename Number>
329  inline unsigned int
331  {
332  return n_cols;
333  }
334 
335 
336 
337  template <typename Number>
338  inline std::size_t
340  {
341  return nnz;
342  }
343 } // namespace CUDAWrappers
344 
345 DEAL_II_NAMESPACE_CLOSE
346 
347 #endif
348 #endif
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
Number matrix_scalar_product(const LinearAlgebra::CUDAWrappers::Vector< Number > &u, const LinearAlgebra::CUDAWrappers::Vector< Number > &v) const
Number matrix_norm_square(const LinearAlgebra::CUDAWrappers::Vector< Number > &v) const
SparseMatrix & operator*=(const Number factor)
SparseMatrix & operator/=(const Number factor)
std::size_t n_nonzero_elements() const
void reinit(Utilities::CUDA::Handle &handle, const ::SparseMatrix< Number > &sparse_matrix_host)
Number residual(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &x, const LinearAlgebra::CUDAWrappers::Vector< Number > &b) const
Number frobenius_norm() const
std::tuple< Number *, int *, int *, cusparseMatDescr_t > get_cusparse_matrix() const
void vmult_add(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &src) const
void Tvmult_add(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &src) const
Number linfty_norm() const