Opm::gpuistl::GpuSparseMatrixGeneric< T > Class Template Reference

The GpuSparseMatrixGeneric class uses cuSPARSE Generic API for sparse matrix operations. More...

#include <GpuSparseMatrixGeneric.hpp>

Inheritance diagram for Opm::gpuistl::GpuSparseMatrixGeneric< T >:
Inheritance graph

Public Types

using field_type = T
 

Public Member Functions

 GpuSparseMatrixGeneric (const T *nonZeroElements, const int *rowIndices, const int *columnIndices, size_t numberOfNonzeroBlocks, size_t blockSize, size_t numberOfRows)
 
 GpuSparseMatrixGeneric (const GpuVector< int > &rowIndices, const GpuVector< int > &columnIndices, size_t blockSize)
 
 GpuSparseMatrixGeneric (const GpuSparseMatrixGeneric &)
 
void preprocessSpMV ()
 Preprocess SpMV operation to optimize for sparsity pattern. More...
 
GpuSparseMatrixGenericoperator= (const GpuSparseMatrixGeneric &)=delete
 
virtual ~GpuSparseMatrixGeneric ()
 
size_t N () const
 N returns the number of rows (which is equal to the number of columns) More...
 
size_t nonzeroes () const
 nonzeroes behaves as the Dune::BCRSMatrix::nonzeros() function and returns the number of non zero blocks More...
 
GpuVector< T > & getNonZeroValues ()
 getNonZeroValues returns the GPU vector containing the non-zero values (ordered by block) More...
 
const GpuVector< T > & getNonZeroValues () const
 getNonZeroValues returns the GPU vector containing the non-zero values (ordered by block) More...
 
GpuVector< int > & getRowIndices ()
 getRowIndices returns the row indices used to represent the BSR structure. More...
 
const GpuVector< int > & getRowIndices () const
 getRowIndices returns the row indices used to represent the BSR structure. More...
 
GpuVector< int > & getColumnIndices ()
 getColumnIndices returns the column indices used to represent the BSR structure. More...
 
const GpuVector< int > & getColumnIndices () const
 getColumnIndices returns the column indices used to represent the BSR structure. More...
 
size_t dim () const
 dim returns the dimension of the vector space on which this matrix acts More...
 
size_t blockSize () const
 blockSize size of the blocks More...
 
virtual void mv (const GpuVector< T > &x, GpuVector< T > &y) const
 mv performs matrix vector multiply y = Ax More...
 
virtual void umv (const GpuVector< T > &x, GpuVector< T > &y) const
 umv computes y=Ax+y More...
 
virtual void usmv (T alpha, const GpuVector< T > &x, GpuVector< T > &y) const
 umv computes y=alpha * Ax + y More...
 
template<class MatrixType >
void updateNonzeroValues (const MatrixType &matrix, bool copyNonZeroElementsDirectly=false)
 updateNonzeroValues updates the non-zero values by using the non-zero values of the supplied matrix More...
 
void updateNonzeroValues (const GpuSparseMatrixGeneric< T > &matrix)
 updateNonzeroValues updates the non-zero values by using the non-zero values of the supplied matrix More...
 

Static Public Member Functions

template<class MatrixType >
static GpuSparseMatrixGeneric< T > fromMatrix (const MatrixType &matrix, bool copyNonZeroElementsDirectly=false)
 fromMatrix creates a new matrix with the same block size and values as the given matrix More...
 

Detailed Description

template<typename T>
class Opm::gpuistl::GpuSparseMatrixGeneric< T >

The GpuSparseMatrixGeneric class uses cuSPARSE Generic API for sparse matrix operations.

Note
We support raw primitives for T (double and float). Block size is handled through the blockSize parameter.
Template Parameters
Tthe type to store. Can be either float or double.
Note
we only support square matrices.

Member Typedef Documentation

◆ field_type

template<typename T >
using Opm::gpuistl::GpuSparseMatrixGeneric< T >::field_type = T

Constructor & Destructor Documentation

◆ GpuSparseMatrixGeneric() [1/3]

template<typename T >
Opm::gpuistl::GpuSparseMatrixGeneric< T >::GpuSparseMatrixGeneric ( const T *  nonZeroElements,
const int *  rowIndices,
const int *  columnIndices,
size_t  numberOfNonzeroBlocks,
size_t  blockSize,
size_t  numberOfRows 
)

Create the sparse matrix specified by the raw data.

Parameters
[in]nonZeroElementsthe non-zero values of the matrix
[in]rowIndicesthe row indices of the non-zero elements
[in]columnIndicesthe column indices of the non-zero elements
[in]numberOfNonzeroBlocksnumber of nonzero elements
[in]blockSizesize of each block matrix (typically 3)
[in]numberOfRowsthe number of rows

◆ GpuSparseMatrixGeneric() [2/3]

template<typename T >
Opm::gpuistl::GpuSparseMatrixGeneric< T >::GpuSparseMatrixGeneric ( const GpuVector< int > &  rowIndices,
const GpuVector< int > &  columnIndices,
size_t  blockSize 
)

Create a sparse matrix by copying the sparsity structure of another matrix, not filling in the values

Parameters
[in]rowIndicesthe row indices of the non-zero elements
[in]columnIndicesthe column indices of the non-zero elements
[in]blockSizesize of each block matrix (typically 3)

◆ GpuSparseMatrixGeneric() [3/3]

template<typename T >
Opm::gpuistl::GpuSparseMatrixGeneric< T >::GpuSparseMatrixGeneric ( const GpuSparseMatrixGeneric< T > &  )

◆ ~GpuSparseMatrixGeneric()

template<typename T >
virtual Opm::gpuistl::GpuSparseMatrixGeneric< T >::~GpuSparseMatrixGeneric ( )
virtual

Member Function Documentation

◆ blockSize()

template<typename T >
size_t Opm::gpuistl::GpuSparseMatrixGeneric< T >::blockSize ( ) const
inline

blockSize size of the blocks

References Opm::gpuistl::detail::to_size_t().

◆ dim()

template<typename T >
size_t Opm::gpuistl::GpuSparseMatrixGeneric< T >::dim ( ) const
inline

dim returns the dimension of the vector space on which this matrix acts

This is equivalent to matrix.N() * matrix.blockSize()

Returns
matrix.N() * matrix.blockSize()

References Opm::gpuistl::detail::to_size_t().

◆ fromMatrix()

template<typename T >
template<class MatrixType >
static GpuSparseMatrixGeneric< T > Opm::gpuistl::GpuSparseMatrixGeneric< T >::fromMatrix ( const MatrixType &  matrix,
bool  copyNonZeroElementsDirectly = false 
)
static

fromMatrix creates a new matrix with the same block size and values as the given matrix

Parameters
matrixthe matrix to copy from
copyNonZeroElementsDirectlyif true will do a memcpy from matrix[0][0][0][0], otherwise will build up the non-zero elements by looping over the matrix. Note that setting this to true will yield a performance increase, but might not always yield correct results depending on how the matrix has been initialized. If unsure, leave it as false.
Template Parameters
MatrixTypeis assumed to be a Dune::BCRSMatrix compatible matrix.

◆ getColumnIndices() [1/2]

template<typename T >
GpuVector< int > & Opm::gpuistl::GpuSparseMatrixGeneric< T >::getColumnIndices ( )
inline

getColumnIndices returns the column indices used to represent the BSR structure.

Returns
Read the CuSPARSE documentation on Block Compressed Sparse Row Format (BSR) for the exact ordering.

◆ getColumnIndices() [2/2]

template<typename T >
const GpuVector< int > & Opm::gpuistl::GpuSparseMatrixGeneric< T >::getColumnIndices ( ) const
inline

getColumnIndices returns the column indices used to represent the BSR structure.

Returns
Read the CuSPARSE documentation on Block Compressed Sparse Row Format (BSR) for the exact ordering.

◆ getNonZeroValues() [1/2]

template<typename T >
GpuVector< T > & Opm::gpuistl::GpuSparseMatrixGeneric< T >::getNonZeroValues ( )
inline

getNonZeroValues returns the GPU vector containing the non-zero values (ordered by block)

Note
Read the CuSPARSE documentation on Block Compressed Sparse Row Format (BSR) for the exact ordering.

◆ getNonZeroValues() [2/2]

template<typename T >
const GpuVector< T > & Opm::gpuistl::GpuSparseMatrixGeneric< T >::getNonZeroValues ( ) const
inline

getNonZeroValues returns the GPU vector containing the non-zero values (ordered by block)

Note
Read the CuSPARSE documentation on Block Compressed Sparse Row Format (BSR) for the exact ordering.

◆ getRowIndices() [1/2]

template<typename T >
GpuVector< int > & Opm::gpuistl::GpuSparseMatrixGeneric< T >::getRowIndices ( )
inline

getRowIndices returns the row indices used to represent the BSR structure.

Note
Read the CuSPARSE documentation on Block Compressed Sparse Row Format (BSR) for the exact ordering.

◆ getRowIndices() [2/2]

template<typename T >
const GpuVector< int > & Opm::gpuistl::GpuSparseMatrixGeneric< T >::getRowIndices ( ) const
inline

getRowIndices returns the row indices used to represent the BSR structure.

Note
Read the CuSPARSE documentation on Block Compressed Sparse Row Format (BSR) for the exact ordering.

◆ mv()

template<typename T >
virtual void Opm::gpuistl::GpuSparseMatrixGeneric< T >::mv ( const GpuVector< T > &  x,
GpuVector< T > &  y 
) const
virtual

mv performs matrix vector multiply y = Ax

Parameters
[in]xthe vector to multiply the matrix with
[out]ythe output vector

◆ N()

template<typename T >
size_t Opm::gpuistl::GpuSparseMatrixGeneric< T >::N ( ) const
inline

N returns the number of rows (which is equal to the number of columns)

References Opm::gpuistl::detail::to_size_t().

◆ nonzeroes()

template<typename T >
size_t Opm::gpuistl::GpuSparseMatrixGeneric< T >::nonzeroes ( ) const
inline

nonzeroes behaves as the Dune::BCRSMatrix::nonzeros() function and returns the number of non zero blocks

Returns
number of non zero blocks.

References Opm::gpuistl::detail::to_size_t().

◆ operator=()

template<typename T >
GpuSparseMatrixGeneric & Opm::gpuistl::GpuSparseMatrixGeneric< T >::operator= ( const GpuSparseMatrixGeneric< T > &  )
delete

◆ preprocessSpMV()

template<typename T >
void Opm::gpuistl::GpuSparseMatrixGeneric< T >::preprocessSpMV ( )

Preprocess SpMV operation to optimize for sparsity pattern.

This function preprocesses the sparsity pattern of the matrix to optimize for the SpMV operation.

◆ umv()

template<typename T >
virtual void Opm::gpuistl::GpuSparseMatrixGeneric< T >::umv ( const GpuVector< T > &  x,
GpuVector< T > &  y 
) const
virtual

umv computes y=Ax+y

Parameters
[in]xthe vector to multiply with A
[in,out]ythe vector to add and store the output in

◆ updateNonzeroValues() [1/2]

template<typename T >
void Opm::gpuistl::GpuSparseMatrixGeneric< T >::updateNonzeroValues ( const GpuSparseMatrixGeneric< T > &  matrix)

updateNonzeroValues updates the non-zero values by using the non-zero values of the supplied matrix

Parameters
matrixthe matrix to extract the non-zero values from
Note
This assumes the given matrix has the same sparsity pattern.

◆ updateNonzeroValues() [2/2]

template<typename T >
template<class MatrixType >
void Opm::gpuistl::GpuSparseMatrixGeneric< T >::updateNonzeroValues ( const MatrixType &  matrix,
bool  copyNonZeroElementsDirectly = false 
)

updateNonzeroValues updates the non-zero values by using the non-zero values of the supplied matrix

Parameters
matrixthe matrix to extract the non-zero values from
copyNonZeroElementsDirectlyif true will do a memcpy from matrix[0][0][0][0], otherwise will build up the non-zero elements by looping over the matrix. Note that setting this to true will yield a performance increase, but might not always yield correct results depending on how the matrix matrix has been initialized. If unsure, leave it as false.
Note
This assumes the given matrix has the same sparsity pattern.
Template Parameters
MatrixTypeis assumed to be a Dune::BCRSMatrix compatible matrix.

◆ usmv()

template<typename T >
virtual void Opm::gpuistl::GpuSparseMatrixGeneric< T >::usmv ( alpha,
const GpuVector< T > &  x,
GpuVector< T > &  y 
) const
virtual

umv computes y=alpha * Ax + y

Parameters
[in]alphaThe scaling factor for the matrix-vector product
[in]xthe vector to multiply with A
[in,out]ythe vector to add and store the output in

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