19#ifndef OPM_GPUSPARSEMATRIX_HPP
20#define OPM_GPUSPARSEMATRIX_HPP
26#include <opm/common/ErrorMacros.hpp>
27#include <opm/simulators/linalg/gpuistl/GpuVector.hpp>
28#include <opm/simulators/linalg/gpuistl/GpuSparseMatrixGeneric.hpp>
29#include <opm/simulators/linalg/gpuistl/detail/CuMatrixDescription.hpp>
30#include <opm/simulators/linalg/gpuistl/detail/CuSparseHandle.hpp>
31#include <opm/simulators/linalg/gpuistl/detail/safe_conversion.hpp>
88 const int* rowIndices,
89 const int* columnIndices,
90 size_t numberOfNonzeroBlocks,
125 template <
class MatrixType>
183 if (m_genericMatrixForBlockSize1) {
184 return m_genericMatrixForBlockSize1->getNonZeroValues();
186 return m_nonZeroElements;
196 if (m_genericMatrixForBlockSize1) {
197 return m_genericMatrixForBlockSize1->getNonZeroValues();
199 return m_nonZeroElements;
209 if (m_genericMatrixForBlockSize1) {
210 return m_genericMatrixForBlockSize1->getRowIndices();
222 if (m_genericMatrixForBlockSize1) {
223 return m_genericMatrixForBlockSize1->getRowIndices();
235 if (m_genericMatrixForBlockSize1) {
236 return m_genericMatrixForBlockSize1->getColumnIndices();
238 return m_columnIndices;
248 if (m_genericMatrixForBlockSize1) {
249 return m_genericMatrixForBlockSize1->getColumnIndices();
251 return m_columnIndices;
290 return *m_matrixDescription;
326 template <
class MatrixType>
327 void updateNonzeroValues(
const MatrixType& matrix,
bool copyNonZeroElementsDirectly =
false);
357 template<
class FunctionType>
360 return dispatchOnBlocksizeImpl<max_block_size>(function);
372 const int m_numberOfNonzeroBlocks;
373 const int m_numberOfRows;
374 const int m_blockSize;
380 std::unique_ptr<GpuSparseMatrixGeneric<T>> m_genericMatrixForBlockSize1;
382 template <
class VectorType>
383 void assertSameSize(
const VectorType& vector)
const;
385 template<
int blockSizeCompileTime,
class FunctionType>
386 auto dispatchOnBlocksizeImpl(FunctionType function)
const
388 if (blockSizeCompileTime == m_blockSize) {
389 return function(std::integral_constant<int, blockSizeCompileTime>());
392 if constexpr (blockSizeCompileTime > 1) {
393 return dispatchOnBlocksizeImpl<blockSizeCompileTime - 1>(function);
395 OPM_THROW(std::runtime_error, fmt::format(
"Unsupported block size: {}", m_blockSize));
The GpuSparseMatrix class simple wrapper class for a CuSparse matrix.
Definition GpuSparseMatrix.hpp:60
const GpuVector< int > & getRowIndices() const
getRowIndices returns the row indices used to represent the BSR structure.
Definition GpuSparseMatrix.hpp:220
const GpuVector< int > & getColumnIndices() const
getColumnIndices returns the column indices used to represent the BSR structure.
Definition GpuSparseMatrix.hpp:246
static GpuSparseMatrix< T > fromMatrix(const MatrixType &matrix, bool copyNonZeroElementsDirectly=false)
fromMatrix creates a new matrix with the same block size and values as the given matrix
Definition GpuSparseMatrix.cpp:115
void setNonUnitDiagonal()
setNonUnitDiagonal sets the CuSparse flag that this has non-unit diagional.
Definition GpuSparseMatrix.cpp:211
void updateNonzeroValues(const MatrixType &matrix, bool copyNonZeroElementsDirectly=false)
updateNonzeroValues updates the non-zero values by using the non-zero values of the supplied matrix
Definition GpuSparseMatrix.cpp:148
virtual void umv(const GpuVector< T > &x, GpuVector< T > &y) const
umv computes y=Ax+y
Definition GpuSparseMatrix.cpp:253
detail::GpuSparseMatrixDescription & getDescription()
getDescription the cusparse matrix description.
Definition GpuSparseMatrix.hpp:288
GpuVector< int > & getRowIndices()
getRowIndices returns the row indices used to represent the BSR structure.
Definition GpuSparseMatrix.hpp:207
const GpuVector< T > & getNonZeroValues() const
getNonZeroValues returns the GPU vector containing the non-zero values (ordered by block)
Definition GpuSparseMatrix.hpp:194
size_t nonzeroes() const
nonzeroes behaves as the Dune::BCRSMatrix::nonzeros() function and returns the number of non zero blo...
Definition GpuSparseMatrix.hpp:166
size_t blockSize() const
blockSize size of the blocks
Definition GpuSparseMatrix.hpp:273
void setUpperTriangular()
setUpperTriangular sets the CuSparse flag that this is an upper diagonal (with unit diagonal) matrix.
Definition GpuSparseMatrix.cpp:190
size_t N() const
N returns the number of rows (which is equal to the number of columns).
Definition GpuSparseMatrix.hpp:152
void setLowerTriangular()
setLowerTriangular sets the CuSparse flag that this is an lower diagonal (with non-unit diagonal) mat...
Definition GpuSparseMatrix.cpp:197
static constexpr int max_block_size
Maximum block size supported by this implementation.
Definition GpuSparseMatrix.hpp:72
virtual void mv(const GpuVector< T > &x, GpuVector< T > &y) const
mv performs matrix vector multiply y = Ax
Definition GpuSparseMatrix.cpp:218
virtual void usmv(T alpha, const GpuVector< T > &x, GpuVector< T > &y) const
umv computes y=alpha * Ax + y
Definition GpuSparseMatrix.cpp:289
auto dispatchOnBlocksize(FunctionType function) const
Dispatches a function based on the block size of the matrix.
Definition GpuSparseMatrix.hpp:358
void setUnitDiagonal()
setUnitDiagonal sets the CuSparse flag that this has unit diagional.
Definition GpuSparseMatrix.cpp:204
GpuVector< int > & getColumnIndices()
getColumnIndices returns the column indices used to represent the BSR structure.
Definition GpuSparseMatrix.hpp:233
GpuSparseMatrix(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.
Definition GpuSparseMatrix.cpp:40
GpuVector< T > & getNonZeroValues()
getNonZeroValues returns the GPU vector containing the non-zero values (ordered by block)
Definition GpuSparseMatrix.hpp:181
size_t dim() const
dim returns the dimension of the vector space on which this matrix acts
Definition GpuSparseMatrix.hpp:260
Definition gpu_type_detection.hpp:30
The CuSparseHandle class provides a singleton for the simulator universal cuSparseHandle.
Definition CuSparseHandle.hpp:41
CuSparseResource< cusparseMatDescr_t > GpuSparseMatrixDescription
GpuSparseMatrixDescription holder.
Definition CuMatrixDescription.hpp:30
std::shared_ptr< CuSparseResource< cusparseMatDescr_t > > GpuSparseMatrixDescriptionPtr
Pointer to GpuSparseMatrixDescription holder.
Definition CuMatrixDescription.hpp:35
__host__ __device__ std::size_t to_size_t(int i)
to_size_t converts a (on most relevant platforms) a 32 bit signed int to a 64 bits unsigned int
Definition safe_conversion.hpp:86