# Matrix requirements for cusparse*csrgemm2

I would like to perform a matrix multiplication like:
$$C=A*B*A'$$
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?

• 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. Feb 25 '20 at 3:31
• Yes, the resulting matrix is needed explicitly. Feb 25 '20 at 7:00
• 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. Feb 25 '20 at 21:52
• Thanks for your comment. I will take this into account for the next development steps. Feb 26 '20 at 10:16