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_tExpand 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
alphaorbetais zero, the non-zero structure of matrixCaligns with the sparsity pattern ofBorA, respectively; if bothalphaandbetaare zero, the sparsity pattern ofCis empty. - Since
matAandmatBmay have different sparsity patterns,cusparseSpGEAMcomputesmatCin two steps. First, the user callscusparseSpGEAM_nnzwith amatCwhosecsrRowOffsetsarray has already been allocated. Then, after retrievingnnzC(the number of nonzero elements inmatC) usingcusparseSpMatGetSize, the user allocates thecsrColIndandcsrValuesarrays and callscusparseSpGEAMto compute the output matrix. If the sparsity pattern ofmatCis already known, the user can skip the call tocusparseSpGEAM_nnz
cusparseSpGEAM supports the following index type for representing the sparse matrices A, B and C (all matrices must have the same index type):
- 32-bit indices (
cusparseIndexType_t::CUSPARSE_INDEX_32I) - 64-bit indices (
cusparseIndexType_t::CUSPARSE_INDEX_64I)
Currently, the function has the following limitations:
- Only CSR format
cusparseFormat_t::CUSPARSE_FORMAT_CSRis supported - The indices of
matAandmatBmust be sorted - Only
opAandopBequal tocusparseOperation_t::CUSPARSE_OPERATION_NON_TRANSPOSEare supported
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:
| Algorithm | Notes |
|---|---|
cusparseSpGEAMAlg_t::CUSPARSE_SPGEAM_ALG1 | Default algorithm |
cusparseSpGEAM has the following properties:
- The routine supports asynchronous execution
- The routine guarantees the indices of
matCto 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: Operationop(A).opB: Operationop(B).alpha: $\alpha$ scalar used for addition.matA: Sparse matrixA.beta: $\beta$ scalar used for addition.matB: Sparse matrixB.matC: Output sparse matrixC.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 bycusparseSpGEAM_nnzandcusparseSpGEAM.