Loading...
Searching...
No Matches
Opm::gpuistl::GpuSparseMatrixGeneric< T > Class Template Reference

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

`#include <GpuSparseMatrixGeneric.hpp>`

## 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)
| Create the sparse matrix specified by the raw data.
| 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.
| GpuSparseMatrixGeneric (const GpuSparseMatrixGeneric &)
void | preprocessSpMV ()
| Preprocess SpMV operation to optimize for sparsity pattern.
GpuSparseMatrixGeneric & | operator= (const GpuSparseMatrixGeneric &)=delete
size_t | N () const
| N returns the number of rows (which is equal to the number of columns).
size_t | nonzeroes () const
| nonzeroes behaves as the Dune::BCRSMatrix::nonzeros() function and returns the number of non zero blocks
GpuVector< T > & | getNonZeroValues ()
| getNonZeroValues returns the GPU vector containing the non-zero values (ordered by block)
const GpuVector< T > & | getNonZeroValues () const
| getNonZeroValues returns the GPU vector containing the non-zero values (ordered by block)
GpuVector< int > & | getRowIndices ()
| getRowIndices returns the row indices used to represent the BSR structure.
const GpuVector< int > & | getRowIndices () const
| getRowIndices returns the row indices used to represent the BSR structure.
GpuVector< int > & | getColumnIndices ()
| getColumnIndices returns the column indices used to represent the BSR structure.
const GpuVector< int > & | getColumnIndices () const
| getColumnIndices returns the column indices used to represent the BSR structure.
size_t | dim () const
| dim returns the dimension of the vector space on which this matrix acts
size_t | blockSize () const
| blockSize size of the blocks
virtual void | mv (const GpuVector< T > &x, GpuVector< T > &y) const
| mv performs matrix vector multiply y = Ax
virtual void | umv (const GpuVector< T > &x, GpuVector< T > &y) const
| umv computes y=Ax+y
virtual void | usmv (T alpha, const GpuVector< T > &x, GpuVector< T > &y) const
| umv computes y=alpha * Ax + y
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
void | updateNonzeroValues (const GpuSparseMatrixGeneric< T > &matrix)
| updateNonzeroValues updates the non-zero values by using the non-zero values of the supplied matrix
template<class FunctionType>
auto | dispatchOnBlocksize (FunctionType function) const
| Dispatches a function based on the block size of the matrix.

## 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

## Static Public Attributes

static constexpr int | max_block_size = 6
| Maximum block size supported by this implementation.

## 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

  T | the type to store. Can be either float or double.

Note
  we only support square matrices.

## Constructor & Destructor Documentation

## GpuSparseMatrixGeneric() [1/2]

template<class 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] | nonZeroElements | the non-zero values of the matrix
  [in] | rowIndices | the row indices of the non-zero elements
  [in] | columnIndices | the column indices of the non-zero elements
  [in] | numberOfNonzeroBlocks | number of nonzero elements
  [in] | blockSize | size of each block matrix (typically 3)
  [in] | numberOfRows | the number of rows

## GpuSparseMatrixGeneric() [2/2]

template<class 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] | rowIndices | the row indices of the non-zero elements
  [in] | columnIndices | the column indices of the non-zero elements
  [in] | blockSize | size of each block matrix (typically 3)

## Member Function Documentation

## 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()

## dispatchOnBlocksize()

template<typename T>
template<class FunctionType>

auto Opm::gpuistl::GpuSparseMatrixGeneric< T >::dispatchOnBlocksize | ( | FunctionType | function | ) | const

inline

Dispatches a function based on the block size of the matrix.

This method allows executing different code paths depending on the block size of the matrix, up to the maximum block size specified by max_block_size.

Use this function if you need the block size to be known at compile time.

Template Parameters

  FunctionType | Type of the function to be dispatched

Parameters

  function | The function to be executed based on the block size

Returns
  The result of the function execution

You can use this function as

matrix.dispatchOnBlocksize([](auto val) {
constexpr int blockSize = decltype(val)::value;
});
Opm::gpuistl::GpuSparseMatrixGeneric::blockSize
size_t blockSize() const
blockSize size of the blocks
Definition GpuSparseMatrixGeneric.hpp:217

## fromMatrix()

template<typename T>
template<typename MatrixType>

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

  matrix | the matrix to copy from
  copyNonZeroElementsDirectly | if 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

  MatrixType | is 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>

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

virtual

mv performs matrix vector multiply y = Ax

Parameters

  [in] | x | the vector to multiply the matrix with
  [out] | y | the output vector

## 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.

## preprocessSpMV()

template<class 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>

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

virtual

umv computes y=Ax+y

Parameters

  [in] | x | the vector to multiply with A
  [in,out] | y | the vector to add and store the output in

## updateNonzeroValues() [1/2]

template<class 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

  matrix | the matrix to extract the non-zero values from

Note
  This assumes the given matrix has the same sparsity pattern.

## updateNonzeroValues() [2/2]

template<class 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

  matrix | the matrix to extract the non-zero values from
  copyNonZeroElementsDirectly | if 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

  MatrixType | is assumed to be a Dune::BCRSMatrix compatible matrix.

## usmv()

template<typename T>

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

virtual

umv computes y=alpha * Ax + y

Parameters

  [in] | alpha | The scaling factor for the matrix-vector product
  [in] | x | the vector to multiply with A
  [in,out] | y | the vector to add and store the output in

## Member Data Documentation

## max_block_size

template<typename T>

int Opm::gpuistl::GpuSparseMatrixGeneric< T >::max_block_size = 6

static constexpr

Maximum block size supported by this implementation.

This constant defines an upper bound on the block size to ensure reasonable compilation times. While this class itself could support larger values, functions that call dispatchOnBlocksize() might have limitations. This value can be increased if needed, but will increase compilation time due to template instantiations.

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

- opm/simulators/linalg/gpuistl/detail/gpu_type_detection.hpp
- opm/simulators/linalg/gpuistl/GpuSparseMatrixGeneric.hpp
- opm/simulators/linalg/gpuistl/GpuSparseMatrixGeneric.cpp