Reference documentation for deal.II version Git 92ca227 2018-05-25 19:47:08 -0500
Public Types | List of all members
CUDAWrappers::SparseMatrix< Number > Class Template Reference

#include <deal.II/lac/cuda_sparse_matrix.h>

Inheritance diagram for CUDAWrappers::SparseMatrix< Number >:
[legend]

Public Types

typedef unsigned int size_type
 
typedef Number value_type
 
typedef Number real_type
 

Public Member Functions

Constructors and initialization
 SparseMatrix ()
 
 SparseMatrix (Utilities::CUDA::Handle &handle, const ::SparseMatrix< Number > &sparse_matrix_host)
 
 SparseMatrix (CUDAWrappers::SparseMatrix< Number > &&)
 
 SparseMatrix (const CUDAWrappers::SparseMatrix< Number > &)=delete
 
 ~SparseMatrix ()
 
void reinit (Utilities::CUDA::Handle &handle, const ::SparseMatrix< Number > &sparse_matrix_host)
 
Information on the matrix
size_type m () const
 
size_type n () const
 
std::size_t n_nonzero_elements () const
 
Modifying entries
SparseMatrixoperator*= (const Number factor)
 
SparseMatrixoperator/= (const Number factor)
 
Multiplications
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
 
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 matrix_norm_square (const LinearAlgebra::CUDAWrappers::Vector< Number > &v) const
 
Number matrix_scalar_product (const LinearAlgebra::CUDAWrappers::Vector< Number > &u, const LinearAlgebra::CUDAWrappers::Vector< Number > &v) const
 
Number residual (LinearAlgebra::CUDAWrappers::Vector< Number > &dst, const LinearAlgebra::CUDAWrappers::Vector< Number > &x, const LinearAlgebra::CUDAWrappers::Vector< Number > &b) const
 
Matrix norms
Number l1_norm () const
 
Number linfty_norm () const
 
Number frobenius_norm () const
 
- Public Member Functions inherited from Subscriptor
 Subscriptor ()
 
 Subscriptor (const Subscriptor &)
 
 Subscriptor (Subscriptor &&) noexcept
 
virtual ~Subscriptor ()
 
Subscriptoroperator= (const Subscriptor &)
 
Subscriptoroperator= (Subscriptor &&) noexcept
 
void subscribe (const char *identifier=nullptr) const
 
void unsubscribe (const char *identifier=nullptr) const
 
unsigned int n_subscriptions () const
 
void list_subscribers () const
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Access to underlying CUDA data

cusparseHandle_t cusparse_handle
 
int nnz
 
int n_rows
 
int n_cols
 
Number * val_dev
 
int * column_index_dev
 
int * row_ptr_dev
 
cusparseMatDescr_t descr
 
std::tuple< Number *, int *, int *, cusparseMatDescr_t > get_cusparse_matrix () const
 

Additional Inherited Members

- Static Public Member Functions inherited from Subscriptor
static::ExceptionBase & ExcInUse (int arg1, std::string arg2, std::string arg3)
 
static::ExceptionBase & ExcNoSubscriber (std::string arg1, std::string arg2)
 

Detailed Description

template<typename Number>
class CUDAWrappers::SparseMatrix< Number >

This class is a wrapper around cuSPARSE csr sparse matrix. Unlike deal.II's own SparseMatrix all elements within each row are stored in increasing column index order.

Note
Instantiations for this template are provided for <float> and <double>.
Author
Bruno Turcksin
Date
2018

Definition at line 48 of file cuda_sparse_matrix.h.

Member Typedef Documentation

template<typename Number>
typedef unsigned int CUDAWrappers::SparseMatrix< Number >::size_type

Declare type for container size.

Definition at line 54 of file cuda_sparse_matrix.h.

template<typename Number>
typedef Number CUDAWrappers::SparseMatrix< Number >::value_type

Type of the matrix entries.

Definition at line 59 of file cuda_sparse_matrix.h.

template<typename Number>
typedef Number CUDAWrappers::SparseMatrix< Number >::real_type

Declare a type that holds real-valued numbers with the same precision as the template argument to this class.

Definition at line 65 of file cuda_sparse_matrix.h.

Constructor & Destructor Documentation

template<typename Number>
CUDAWrappers::SparseMatrix< Number >::SparseMatrix ( )

Constructor. Initialize the matrix to be empty, without any structure, i.e., the matrix is not usable at all. This constructor is therefore only useful for matrices which are members of a class.

You have to initialize the matrix before usage with reinit.

template<typename Number>
CUDAWrappers::SparseMatrix< Number >::SparseMatrix ( Utilities::CUDA::Handle handle,
const ::SparseMatrix< Number > &  sparse_matrix_host 
)

Constructor. Takes a Utilities::CUDA::Handle and a sparse matrix on the host. The sparse matrix on the host is copied on the device and the elements are reordered according to the format supported by cuSPARSE.

template<typename Number>
CUDAWrappers::SparseMatrix< Number >::SparseMatrix ( CUDAWrappers::SparseMatrix< Number > &&  )

Move constructor. Create a new SparseMatrix by stealing the internal data.

template<typename Number>
CUDAWrappers::SparseMatrix< Number >::SparseMatrix ( const CUDAWrappers::SparseMatrix< Number > &  )
delete

Copy constructor is deleted.

template<typename Number>
CUDAWrappers::SparseMatrix< Number >::~SparseMatrix ( )

Destructor. Free all memory.

Member Function Documentation

template<typename Number>
void CUDAWrappers::SparseMatrix< Number >::reinit ( Utilities::CUDA::Handle handle,
const ::SparseMatrix< Number > &  sparse_matrix_host 
)

Reinitialize the sparse matrix. The sparse matrix on the host is copied to the device and the elementes are reordered according to the format supported by cuSPARSE.

template<typename Number >
unsigned int SparseMatrix< Number >::m ( ) const
inline

Return the dimension of the codomain (or range) space. Note that the matrix is of dimension \(m \times n\).

Definition at line 321 of file cuda_sparse_matrix.h.

template<typename Number >
unsigned int SparseMatrix< Number >::n ( ) const
inline

Return the dimension of the domain space. Note that the matrix is of dimension \(m \times n\).

Definition at line 330 of file cuda_sparse_matrix.h.

template<typename Number >
std::size_t SparseMatrix< Number >::n_nonzero_elements ( ) const
inline

Return the number of nonzero elements of this matrix. Actually, it returns the number of entries in the sparsity pattern; if any of the entries should happen to be zero, it is counted anyway.

Definition at line 339 of file cuda_sparse_matrix.h.

template<typename Number>
SparseMatrix& CUDAWrappers::SparseMatrix< Number >::operator*= ( const Number  factor)

Multiply the entire matrix by a fixed factor.

template<typename Number>
SparseMatrix& CUDAWrappers::SparseMatrix< Number >::operator/= ( const Number  factor)

Divide the entrie matrix by a fixed factor.

template<typename Number>
void CUDAWrappers::SparseMatrix< Number >::vmult ( LinearAlgebra::CUDAWrappers::Vector< Number > &  dst,
const LinearAlgebra::CUDAWrappers::Vector< Number > &  src 
) const

Matrix-vector multiplication: let \(dst = M \cdot src\) with \(M\) being this matrix.

template<typename Number>
void CUDAWrappers::SparseMatrix< Number >::Tvmult ( LinearAlgebra::CUDAWrappers::Vector< Number > &  dst,
const LinearAlgebra::CUDAWrappers::Vector< Number > &  src 
) const

Matrix-vector multiplication: let \(dst = M^T \cdot src\) with \(M\) being this matrix. This function does the same as vmult() but takes this transposed matrix.

template<typename Number>
void CUDAWrappers::SparseMatrix< Number >::vmult_add ( LinearAlgebra::CUDAWrappers::Vector< Number > &  dst,
const LinearAlgebra::CUDAWrappers::Vector< Number > &  src 
) const

Adding matrix-vector multiplication. Add \(M \cdot src\) on \(dst\) with \(M\) being this matrix.

template<typename Number>
void CUDAWrappers::SparseMatrix< Number >::Tvmult_add ( LinearAlgebra::CUDAWrappers::Vector< Number > &  dst,
const LinearAlgebra::CUDAWrappers::Vector< Number > &  src 
) const

Adding matrix-vector multiplication. Add \(M^T \cdot src\) to \(dst\) with \(M\) being this matrix. This function foes the same as vmult_add() but takes the transposed matrix.

template<typename Number>
Number CUDAWrappers::SparseMatrix< Number >::matrix_norm_square ( const LinearAlgebra::CUDAWrappers::Vector< Number > &  v) const

Return the square of the norm of the vector \(v\) with respect to the norm induced by this matrix, i.e., \(\left(v,Mv\right)\). This is useful, e.g., in the finite context, where the \(L_2\) norm of a function equals the matrix norm with respect to the mass matrix of the vector representing the nodal values of the finite element function.

Obviously, the matrix needs to be quadratic for this operation.

template<typename Number>
Number CUDAWrappers::SparseMatrix< Number >::matrix_scalar_product ( const LinearAlgebra::CUDAWrappers::Vector< Number > &  u,
const LinearAlgebra::CUDAWrappers::Vector< Number > &  v 
) const

Compute the matrix scalar product \(\left(u,Mv\right)\).

template<typename Number>
Number CUDAWrappers::SparseMatrix< Number >::residual ( LinearAlgebra::CUDAWrappers::Vector< Number > &  dst,
const LinearAlgebra::CUDAWrappers::Vector< Number > &  x,
const LinearAlgebra::CUDAWrappers::Vector< Number > &  b 
) const

Compute the residual of an equation \(M \cdot x=b\), where the residual is defined to be \(r=b-M \cdot x\). Write the residual into \(dst\). The \(l_2\) norm of the residual vector is returned.

Source \(x\) and destination \(dst\) must not be the same vector.

template<typename Number>
Number CUDAWrappers::SparseMatrix< Number >::l1_norm ( ) const

Return the \(l_1\)-norm of the matrix, that is \(|M|_1=\max_{\mathrm{all\ columns\ }j}\sum_{\mathrm{all\ rows\ }i} |M_{ij}|\), (max. sum of columns). This is the natural matrix norm that is compatible to the \(l_1\)-norm for vectors, i.e., \(|Mv|_1\leq |M|_1 |v|_1\).

template<typename Number>
Number CUDAWrappers::SparseMatrix< Number >::linfty_norm ( ) const

Return the \(l_\infty\)-norm of the matrix, that is \(|M|_\infty=\max_{\mathrm{all\ rows\ }i}\sum_{\mathrm{all\ columns\ }j} |M_{ij}|\), (max. sum of rows). This is the natural norm that is compatible to the \(l_\infty\)-norm of vectors, i.e., \(|Mv|_\infty \leq |M|_\infty |v|_\infty\).

template<typename Number>
Number CUDAWrappers::SparseMatrix< Number >::frobenius_norm ( ) const

Return the frobenius norm of the matrix, i.e., the square root of the sum of squares of all entries in the matrix.

template<typename Number>
std::tuple<Number *, int *, int *, cusparseMatDescr_t> CUDAWrappers::SparseMatrix< Number >::get_cusparse_matrix ( ) const

Return a tuple containing the pointer to the values of matrix, the pointer to the columns indices, the pointer to the rows pointer, and the cuSPARSE matrix description.

Member Data Documentation

template<typename Number>
cusparseHandle_t CUDAWrappers::SparseMatrix< Number >::cusparse_handle
mutableprivate

cuSPARSE handle used to call cuSPARSE functions. The cuSPARSE handle needs to be mutable to be called in a const function.

Definition at line 279 of file cuda_sparse_matrix.h.

template<typename Number>
int CUDAWrappers::SparseMatrix< Number >::nnz
private

Number of non-zero elements in the sparse matrix.

Definition at line 284 of file cuda_sparse_matrix.h.

template<typename Number>
int CUDAWrappers::SparseMatrix< Number >::n_rows
private

Number of rows of the sparse matrix.

Definition at line 289 of file cuda_sparse_matrix.h.

template<typename Number>
int CUDAWrappers::SparseMatrix< Number >::n_cols
private

Number of columns of the sparse matrix.

Definition at line 294 of file cuda_sparse_matrix.h.

template<typename Number>
Number* CUDAWrappers::SparseMatrix< Number >::val_dev
private

Pointer to the values (on the device) of the sparse matrix.

Definition at line 299 of file cuda_sparse_matrix.h.

template<typename Number>
int* CUDAWrappers::SparseMatrix< Number >::column_index_dev
private

Pointer to the column indices (on the device) of the sparse matrix.

Definition at line 304 of file cuda_sparse_matrix.h.

template<typename Number>
int* CUDAWrappers::SparseMatrix< Number >::row_ptr_dev
private

Pointer to the row pointer (on the device) of the sparse matrix.

Definition at line 309 of file cuda_sparse_matrix.h.

template<typename Number>
cusparseMatDescr_t CUDAWrappers::SparseMatrix< Number >::descr
private

cuSPARSE description of the sparse matrix.

Definition at line 314 of file cuda_sparse_matrix.h.


The documentation for this class was generated from the following file: