cuLite v0.3.1
A lite CUDA C++ Interface
Loading...
Searching...
No Matches
culite::CuSparseHandler Class Reference

The cuSparse handler class. More...

Public Member Functions

 CuSparseHandler ()
 Constructor.
 ~CuSparseHandler ()
 Destructor.
cusparseHandle_t handle ()
 Get the cuSPARSE handle.
void clear ()
 Clear the internal workspace buffers.
cusparsePointerMode_t setPointerMode (cusparsePointerMode_t mode)
 Set the pointer mode for cuSPARSE operations.
cusparsePointerMode_t pointerMode ()
 Get the current pointer mode.
template<typename T_Scalar>
void reserveSpmv (op_t opA, const T_Scalar *alpha, const cusparse::SpMatBase &matA, const cusparse::DnVec< T_Scalar > &vecX, const T_Scalar *beta, cusparse::DnVec< T_Scalar > &vecY, cusparseSpMVAlg_t alg=cusparseSpMVAlg_t::CUSPARSE_SPMV_CSR_ALG1)
 Reserve workspace memory for sparse matrix-vector multiplication (SpMV).
template<typename T_Scalar>
void preprocessSpmv (op_t opA, const T_Scalar *alpha, const cusparse::SpMatBase &matA, const cusparse::DnVec< T_Scalar > &vecX, const T_Scalar *beta, cusparse::DnVec< T_Scalar > &vecY, cusparseSpMVAlg_t alg=cusparseSpMVAlg_t::CUSPARSE_SPMV_CSR_ALG1)
 Preprocess the sparse matrix-vector multiplication operation.
template<typename T_Scalar>
void performSpmv (op_t opA, const T_Scalar *alpha, const cusparse::SpMatBase &matA, const cusparse::DnVec< T_Scalar > &vecX, const T_Scalar *beta, cusparse::DnVec< T_Scalar > &vecY, cusparseSpMVAlg_t alg=cusparseSpMVAlg_t::CUSPARSE_SPMV_CSR_ALG1)
 Perform sparse matrix-vector multiplication.
template<typename T_Scalar>
void reserveSpmm (op_t opA, op_t opB, const T_Scalar *alpha, const cusparse::SpMatBase &matA, const cusparse::DnMat< T_Scalar > &matB, const T_Scalar *beta, cusparse::DnMat< T_Scalar > &matC, cusparseSpMMAlg_t alg=cusparseSpMMAlg_t::CUSPARSE_SPMM_CSR_ALG1)
 Reserve workspace memory for sparse matrix-matrix multiplication (SpMM).
template<typename T_Scalar>
void preprocessSpmm (op_t opA, op_t opB, const T_Scalar *alpha, const cusparse::SpMatBase &matA, const cusparse::DnMat< T_Scalar > &matB, const T_Scalar *beta, cusparse::DnMat< T_Scalar > &matC, cusparseSpMMAlg_t alg=cusparseSpMMAlg_t::CUSPARSE_SPMM_CSR_ALG1)
 Preprocess the sparse matrix-matrix multiplication operation.
template<typename T_Scalar>
void performSpmm (op_t opA, op_t opB, const T_Scalar *alpha, const cusparse::SpMatBase &matA, const cusparse::DnMat< T_Scalar > &matB, const T_Scalar *beta, cusparse::DnMat< T_Scalar > &matC, cusparseSpMMAlg_t alg=cusparseSpMMAlg_t::CUSPARSE_SPMM_CSR_ALG1)
 Perform sparse matrix-matrix multiplication.

Detailed Description

The cuSparse handler class.

This class provides a wrapper around the cuSPARSE library for performing sparse linear algebra operations on GPU devices. It manages the cuSPARSE handle and internal workspace buffers required for factorization and solve operations.

Constructor & Destructor Documentation

◆ CuSparseHandler()

culite::CuSparseHandler::CuSparseHandler ( )

Constructor.

Initializes the cuSPARSE handle and internal state.

◆ ~CuSparseHandler()

culite::CuSparseHandler::~CuSparseHandler ( )

Destructor.

Destroys the cuSPARSE handle and releases all allocated resources.

Member Function Documentation

◆ handle()

cusparseHandle_t culite::CuSparseHandler::handle ( )

Get the cuSPARSE handle.

Returns
The cuSPARSE handle.

◆ clear()

void culite::CuSparseHandler::clear ( )

Clear the internal workspace buffers.

Releases all internal workspace memory allocated for cuSPARSE operations.

◆ setPointerMode()

cusparsePointerMode_t culite::CuSparseHandler::setPointerMode ( cusparsePointerMode_t mode)

Set the pointer mode for cuSPARSE operations.

Changes the pointer mode and returns the previous mode. The pointer mode determines whether scalar values (alpha, beta) are passed by reference on the host or device.

Parameters
[in]modeThe new pointer mode to set.
Returns
The pointer mode that was active before this call.

◆ pointerMode()

cusparsePointerMode_t culite::CuSparseHandler::pointerMode ( )

Get the current pointer mode.

Returns the current pointer mode setting for cuSPARSE operations.

Returns
The current pointer mode.

◆ reserveSpmv()

template<typename T_Scalar>
void culite::CuSparseHandler::reserveSpmv ( op_t opA,
const T_Scalar * alpha,
const cusparse::SpMatBase & matA,
const cusparse::DnVec< T_Scalar > & vecX,
const T_Scalar * beta,
cusparse::DnVec< T_Scalar > & vecY,
cusparseSpMVAlg_t alg = cusparseSpMVAlg_t::CUSPARSE_SPMV_CSR_ALG1 )

Reserve workspace memory for sparse matrix-vector multiplication (SpMV).

Queries the required buffer size for the SpMV operation and allocates the necessary workspace memory on the device.

Template Parameters
T_ScalarThe scalar type (e.g., float, double, complex).
Parameters
[in]opAOperation to apply to matrix A (e.g., no-transpose, transpose, conjugate-transpose).
[in]alphaPointer to scalar alpha.
[in]matASparse matrix.
[in]vecXInput dense vector X.
[in]betaPointer to scalar beta.
[in,out]vecYDense vector Y for buffer size computation.
[in]algAlgorithm to use for SpMV (default: CUSPARSE_SPMV_CSR_ALG1).

◆ preprocessSpmv()

template<typename T_Scalar>
void culite::CuSparseHandler::preprocessSpmv ( op_t opA,
const T_Scalar * alpha,
const cusparse::SpMatBase & matA,
const cusparse::DnVec< T_Scalar > & vecX,
const T_Scalar * beta,
cusparse::DnVec< T_Scalar > & vecY,
cusparseSpMVAlg_t alg = cusparseSpMVAlg_t::CUSPARSE_SPMV_CSR_ALG1 )

Preprocess the sparse matrix-vector multiplication operation.

Performs any necessary preprocessing steps for the SpMV operation, which may optimize subsequent repeated operations with the same sparsity pattern.

Template Parameters
T_ScalarThe scalar type (e.g., float, double, complex).
Parameters
[in]opAOperation to apply to matrix A (e.g., no-transpose, transpose, conjugate-transpose).
[in]alphaPointer to scalar alpha.
[in]matASparse matrix.
[in]vecXInput dense vector X.
[in]betaPointer to scalar beta.
[in,out]vecYDense vector Y for preprocessing.
[in]algAlgorithm to use for SpMV (default: CUSPARSE_SPMV_CSR_ALG1).

◆ performSpmv()

template<typename T_Scalar>
void culite::CuSparseHandler::performSpmv ( op_t opA,
const T_Scalar * alpha,
const cusparse::SpMatBase & matA,
const cusparse::DnVec< T_Scalar > & vecX,
const T_Scalar * beta,
cusparse::DnVec< T_Scalar > & vecY,
cusparseSpMVAlg_t alg = cusparseSpMVAlg_t::CUSPARSE_SPMV_CSR_ALG1 )

Perform sparse matrix-vector multiplication.

Computes Y = alpha * op(A) * X + beta * Y, where A is a sparse matrix, X and Y are dense vectors, and op(A) is either A, A^T, or A^H.

Template Parameters
T_ScalarThe scalar type (e.g., float, double, complex).
Parameters
[in]opAOperation to apply to matrix A (e.g., no-transpose, transpose, conjugate-transpose).
[in]alphaPointer to scalar alpha.
[in]matASparse matrix.
[in]vecXInput dense vector X.
[in]betaPointer to scalar beta.
[in,out]vecYOutput dense vector Y.
[in]algAlgorithm to use for SpMV (default: CUSPARSE_SPMV_CSR_ALG1).

◆ reserveSpmm()

template<typename T_Scalar>
void culite::CuSparseHandler::reserveSpmm ( op_t opA,
op_t opB,
const T_Scalar * alpha,
const cusparse::SpMatBase & matA,
const cusparse::DnMat< T_Scalar > & matB,
const T_Scalar * beta,
cusparse::DnMat< T_Scalar > & matC,
cusparseSpMMAlg_t alg = cusparseSpMMAlg_t::CUSPARSE_SPMM_CSR_ALG1 )

Reserve workspace memory for sparse matrix-matrix multiplication (SpMM).

Queries the required buffer size for the SpMM operation and allocates the necessary workspace memory on the device.

Template Parameters
T_ScalarThe scalar type (e.g., float, double, complex).
Parameters
[in]opAOperation to apply to matrix A (e.g., no-transpose, transpose, conjugate-transpose).
[in]opBOperation to apply to matrix B (e.g., no-transpose, transpose, conjugate-transpose).
[in]alphaPointer to scalar alpha.
[in]matASparse matrix A.
[in]matBDense matrix B.
[in]betaPointer to scalar beta.
[in,out]matCDense matrix C for buffer size computation.
[in]algAlgorithm to use for SpMM (default: CUSPARSE_SPMM_CSR_ALG1).

◆ preprocessSpmm()

template<typename T_Scalar>
void culite::CuSparseHandler::preprocessSpmm ( op_t opA,
op_t opB,
const T_Scalar * alpha,
const cusparse::SpMatBase & matA,
const cusparse::DnMat< T_Scalar > & matB,
const T_Scalar * beta,
cusparse::DnMat< T_Scalar > & matC,
cusparseSpMMAlg_t alg = cusparseSpMMAlg_t::CUSPARSE_SPMM_CSR_ALG1 )

Preprocess the sparse matrix-matrix multiplication operation.

Performs any necessary preprocessing steps for the SpMM operation, which may optimize subsequent repeated operations with the same sparsity pattern.

Template Parameters
T_ScalarThe scalar type (e.g., float, double, complex).
Parameters
[in]opAOperation to apply to matrix A (e.g., no-transpose, transpose, conjugate-transpose).
[in]opBOperation to apply to matrix B (e.g., no-transpose, transpose, conjugate-transpose).
[in]alphaPointer to scalar alpha.
[in]matASparse matrix A.
[in]matBDense matrix B.
[in]betaPointer to scalar beta.
[in,out]matCDense matrix C for preprocessing.
[in]algAlgorithm to use for SpMM (default: CUSPARSE_SPMM_CSR_ALG1).

◆ performSpmm()

template<typename T_Scalar>
void culite::CuSparseHandler::performSpmm ( op_t opA,
op_t opB,
const T_Scalar * alpha,
const cusparse::SpMatBase & matA,
const cusparse::DnMat< T_Scalar > & matB,
const T_Scalar * beta,
cusparse::DnMat< T_Scalar > & matC,
cusparseSpMMAlg_t alg = cusparseSpMMAlg_t::CUSPARSE_SPMM_CSR_ALG1 )

Perform sparse matrix-matrix multiplication.

Computes C = alpha * op(A) * op(B) + beta * C, where A is a sparse matrix, B and C are dense matrices, and op(X) is either X, X^T, or X^H.

Template Parameters
T_ScalarThe scalar type (e.g., float, double, complex).
Parameters
[in]opAOperation to apply to matrix A (e.g., no-transpose, transpose, conjugate-transpose).
[in]opBOperation to apply to matrix B (e.g., no-transpose, transpose, conjugate-transpose).
[in]alphaPointer to scalar alpha.
[in]matASparse matrix A.
[in]matBDense matrix B.
[in]betaPointer to scalar beta.
[in,out]matCOutput dense matrix C.
[in]algAlgorithm to use for SpMM (default: CUSPARSE_SPMM_CSR_ALG1).