CUSPARSE - Add 2 sparse matrices in csr format

Hi,

im really new with cuda.
im using the cusparse library to perform some matrix-vector operations, but a also need a function do add to sparse matrices. But i cant find one in the cusparse library.
Does anyone know a solution?

Thx for your help!

sma87

Sparse matrix addition isn’t a very common or straightforward operation, except in the simplest case where the structure of both matrices is identical. The most efficient approach will depend a lot of the structure of the two matrices being added.

hm, so i wont find a implementaion in one the the nvidia libs, right?

in my case the matrices dont have the same structure,
do you know any other implemetation to add to sparse matrixes?

thx for your help!

Not that I am aware of, no.

Most codes that support addition do it by converting the matrices back to dense (or perhaps a block if the format and code supports slicing), performing the addition, then converting the results back to sparse. It is normally a very inefficient operation which is usually best avoided (and it usually can be).

my matrices have a size of round about 52000x52000 with 2,5*10^6 non zero elements, so i think it is not very practicalbe to convert them to dense.

so i have to write a implementation for myself

Are you really sure that you need to add the matrices? Could you “carry” the matrices separately and add their matrix-vector products instead?

maybe i can transform (A+B)v to Av+B*v, i think what would solve my problem

does what have a near equivalent performance?

thx very much avidday

I would expect it to be much, much faster than the alternative sparse addition operation. You can use something like CUBLAS axpy to add the vectors produced by the sparse matrix-vector products.