cusparseCsrSetStridedBatch with unequal number of non-zeros

I have a situation where I need to calculate G^T * K * G, where both G and K are sparse and represented using CSR. G is unchanging, but I have a number of different K’s for which I need to calculate this value, and so would like to use batched multiplication. My issue is that although each K is the same size, they do not have the same number of non-zero elements, so the length of the column indices and value arrays are different for each K. As I understand, the parameter columnsValuesBatchStride in cusparseCsrSetStridedBatch is described as “Address offset between consecutive batches for the column and value arrays”, so it’s expected that each matrix has the same number of non-zero elements. I was wondering if I could determine the maximum number of non-zero elements of all the K’s, then pad all the other K’s with dummy values (e.g. entries with a value of 0), such that they all have the same number of non-zero elements. Would this be valid? Or would this invalidate the calculations? If so, what else could I do to enable batched multiplication?

Thanks, Ben.

Hi @ben.pollock. Are you using cusparseSpGEMM? At the moment, cusparseSpGEMM doesn’t support batch computation.

Nevertheless, adding zeros to matrices shouldn’t break cusparseSpGEMM. Note that, the output may contain zero entries.

Thanks @qanhpham, I wasn’t aware cuspraseSpGEMM doesn’t support batched computation so I’ll resort to doing the multiplications in a loop. I’ll keep in mind the workaround of adding zeros to the matrix for future problems.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.