CuSparse csrmm example

cuda

Solution

Referring to the documentation, the `csrmm` function is intended for multiplication of a sparse matrix times a dense matrix:

C=α∗op(A)∗B+β∗C 

"where A is m×n sparse matrix ... B and C are dense matrices..."

If you would like to see an example usage, there is an example given in appendix B of the documentation:

/* exercise Level 3 routines (csrmm) */
cudaStat1 = cudaMalloc((void**)&z, 2*(n+1)*sizeof(z[0]));   
if (cudaStat1 != cudaSuccess) {
    CLEANUP("Device malloc failed (z)");
    return 1;
}
cudaStat1 = cudaMemset((void *)z,0, 2*(n+1)*sizeof(z[0]));    
if (cudaStat1 != cudaSuccess) {
    CLEANUP("Memset on Device failed");
    return 1;
}
status= cusparseDcsrmm(handle, CUSPARSE_OPERATION_NON_TRANSPOSE, n, 2, n, 
                       nnz, &dfive, descr, cooVal, csrRowPtr, cooColIndex, 
                       y, n, &dzero, z, n+1);
if (status != CUSPARSE_STATUS_SUCCESS) {
    CLEANUP("Matrix-matrix multiplication failed");
    return 1;
}  

In this extract from the complete worked example given in appendix B, the sparse matrix `A` is represented by `descr` (matrix type descriptor), `cooVal` (the non-zero values of A), `csrRowPtr` (the CSR row pointers of A), and `cooColIndex` (the COO column indices of A). `y` is a pointer to the dense matrix corresponding to `B`, and `z` is a pointer to the dense matrix corresponding to `C` in the general formula.

If you want to do dense times sparse, you may also be interested in @talonmies comment on this question:

It is a basic associative property of the matrix dot product that (Dense * Sparse).T == Sparse.T * Dense.T

Problem

I just wanted to know if there are any examples provided by Nvidia or any other trusted source that uses the `csrmm` function from the `cusparse` library, to multiply a sparse matrix with a dense matrix. Thank you in advance

Original source