Reference documentation for deal.II version 9.0.0
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 at
12 // the top level of the deal.II distribution.
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 #include <deal.II/base/subscriptor.h>
21 
22 #ifdef DEAL_II_WITH_CUDA
23 #include <deal.II/base/cuda.h>
24 #include <deal.II/lac/sparse_matrix.h>
25 #include <deal.II/lac/cuda_vector.h>
26 #include <cusparse.h>
27 
28 DEAL_II_NAMESPACE_OPEN
29 
30 namespace CUDAWrappers
31 {
44  template <typename Number>
45  class SparseMatrix: public virtual Subscriptor
46  {
47  public:
51  typedef unsigned int size_type;
52 
56  typedef Number value_type;
57 
62  typedef Number real_type;
63 
75  SparseMatrix();
76 
83  const ::SparseMatrix<Number> &sparse_matrix_host);
84 
90 
95 
99  ~SparseMatrix();
100 
106  void reinit(Utilities::CUDA::Handle &handle,
107  const ::SparseMatrix<Number> &sparse_matrix_host);
109 
118  size_type m() const;
119 
124  size_type n() const;
125 
131  std::size_t n_nonzero_elements() const;
133 
141  SparseMatrix &operator*= (const Number factor);
142 
146  SparseMatrix &operator/= (const Number factor);
148 
159 
167 
174 
182 
193 
199 
211 
222  Number l1_norm() const;
223 
231  Number linfty_norm() const;
232 
237  Number frobenius_norm() const;
239 
249  std::tuple<Number *, int *, int *, cusparseMatDescr_t>
250  get_cusparse_matrix() const;
251  //*}
252 
253  private:
258  mutable cusparseHandle_t cusparse_handle;
259 
263  int nnz;
264 
268  int n_rows;
269 
273  int n_cols;
274 
278  Number *val_dev;
279 
284 
289 
293  cusparseMatDescr_t descr;
294  };
295 
296 
297 
298  template <typename Number>
299  inline
300  unsigned int SparseMatrix<Number>::m() const
301  {
302  return n_rows;
303  }
304 
305 
306 
307  template <typename Number>
308  inline
309  unsigned int SparseMatrix<Number>::n() const
310  {
311  return n_cols;
312  }
313 
314 
315 
316  template <typename Number>
317  inline
319  {
320  return nnz;
321  }
322 }
323 
324 DEAL_II_NAMESPACE_CLOSE
325 
326 #endif
327 #endif
Number matrix_norm_square(const LinearAlgebra::CUDAWrappers::Vector< Number > &v) const
std::tuple< Number *, int *, int *, cusparseMatDescr_t > get_cusparse_matrix() const
Number matrix_scalar_product(const LinearAlgebra::CUDAWrappers::Vector< Number > &u, const LinearAlgebra::CUDAWrappers::Vector< Number > &v) const
SparseMatrix & operator*=(const Number factor)
Number frobenius_norm() const
SparseMatrix & operator/=(const Number factor)
Number residual(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &x, const LinearAlgebra::CUDAWrappers::Vector< Number > &b) const
void reinit(Utilities::CUDA::Handle &handle, const ::SparseMatrix< Number > &sparse_matrix_host)
Number linfty_norm() const
void Tvmult_add(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &src) const
void vmult_add(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
void vmult(LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &src) const
std::size_t n_nonzero_elements() const