I would like to perform a matrix multiplication like:
using cusparse library function cusparseDcsrgemm2.
To do this I split it into two matrix-matrix multiplications where all matrices are stored in CSR format with zero based index which is specified in the cusparse matrix description. However the first matrix multiplication works fine but the second one failed when determining the number of non-zeros for the resulting matrix. The CSR format of the matrix should be ok. Unfortunately the matrix is so big, that I cannot check the format by hand. What requirements need the matrices fullfil when performing the cusparseDcsrgemm2 function? Are there any helper functions where I can check the matrix? Maybe outside cuda?

  • $\begingroup$ Do you need the matrix explicitly? Because if you multiply two sparse matrices, it is very likely that you are going to get a dense matrix. $\endgroup$ Feb 25, 2020 at 3:31
  • $\begingroup$ Yes, the resulting matrix is needed explicitly. $\endgroup$
    – vydesaster
    Feb 25, 2020 at 7:00
  • $\begingroup$ Then you are better off not using sparse matrices at all. I am pretty sure that during second GEMM operation there are more than 4,294,967,295 nonzeros (which is the maximum value an unsigned 32-bit integer can take). For example, by multiplying two 100,000-by-100,000 sparse matrices, it is possible to create 10,000,000,000 nonzeros. If you use dense matrices, you may still have problems with memory allocation and access but at least you will get a segmentation fault which is easier to debug. $\endgroup$ Feb 25, 2020 at 21:52
  • $\begingroup$ Thanks for your comment. I will take this into account for the next development steps. $\endgroup$
    – vydesaster
    Feb 26, 2020 at 10:16

1 Answer 1


It seems that cusparse library expects the CSR matrix to be ordered. If the matrix is not ordered, the cusparse functions fail. Ordering helps to fix the above mentioned issue.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.