Skip to main content

cusparseSpGEAM

Function cusparseSpGEAM 

Source
pub unsafe extern "C" fn cusparseSpGEAM(
    handle: cusparseHandle_t,
    opA: cusparseOperation_t,
    opB: cusparseOperation_t,
    alpha: *const c_void,
    matA: cusparseSpMatDescr_t,
    beta: *const c_void,
    matB: cusparseSpMatDescr_t,
    matC: cusparseSpMatDescr_t,
    computeType: cudaDataType,
    alg: cusparseSpGEAMAlg_t,
    spgeamDescr: cusparseSpGEAMDescr_t,
    externalBuffer: *mut c_void,
) -> cusparseStatus_t
Expand description

This function performs the addition of two sparse matrices matA and matB.

where $\alpha$ and $\beta$ are scalars.

Functions cusparseSpGEAM_bufferSize, cusparseSpGEAM_nnz, and cusparseSpGEAM return the required buffer size, compute the number of nonzero elements of C, and perform the actual computation, respectively.

Notes:

  • In cases where alpha or beta is zero, the non-zero structure of matrix C aligns with the sparsity pattern of B or A, respectively; if both alpha and beta are zero, the sparsity pattern of C is empty.
  • Since matA and matB may have different sparsity patterns, cusparseSpGEAM computes matC in two steps. First, the user calls cusparseSpGEAM_nnz with a matC whose csrRowOffsets array has already been allocated. Then, after retrieving nnzC (the number of nonzero elements in matC) using cusparseSpMatGetSize, the user allocates the csrColInd and csrValues arrays and calls cusparseSpGEAM to compute the output matrix. If the sparsity pattern of matC is already known, the user can skip the call to cusparseSpGEAM_nnz

cusparseSpGEAM supports the following index type for representing the sparse matrices A, B and C (all matrices must have the same index type):

Currently, the function has the following limitations:

The data type combinations currently supported for cusparseSpGEAM are listed below:

Uniform-precision computation:

A/B/C/computeType
cudaDataType_t::CUDA_R_32F
cudaDataType_t::CUDA_R_64F
cudaDataType_t::CUDA_C_32F
cudaDataType_t::CUDA_C_64F

cusparseSpGEAM supports the following algorithm:

AlgorithmNotes
cusparseSpGEAMAlg_t::CUSPARSE_SPGEAM_ALG1Default algorithm

cusparseSpGEAM has the following properties:

  • The routine supports asynchronous execution
  • The routine guarantees the indices of matC to be sorted

cusparseSpGEAM supports the following optimizations:

  • CUDA graph capture
  • Hardware Memory Compression

Please visit cuSPARSE Library Samples - cusparseSpGEAM for a code example.

ยงParameters

  • handle: Handle to the cuSPARSE library context.
  • opA: Operation op(A).
  • opB: Operation op(B).
  • alpha: $\alpha$ scalar used for addition.
  • matA: Sparse matrix A.
  • beta: $\beta$ scalar used for addition.
  • matB: Sparse matrix B.
  • matC: Output sparse matrix C.
  • computeType: Enumerator specifying the datatype in which the computation is executed.
  • alg: Enumerator specifying the algorithm for the computation (only one algorithm is available, cusparseSpGEAMAlg_t::CUSPARSE_SPGEAM_ALG1).
  • spgeamDescr: Opaque descriptor for storing internal data used across the three steps.
  • externalBuffer: Pointer to workspace buffer needed by cusparseSpGEAM_nnz and cusparseSpGEAM.