Using the Cublas_v2/Cusparse libraries


I am trying to compute the subtraction of two vectors:

b-A*x, where b and x are vectors and A is a sparse Matrix.I am using Cuda with C++. Is there a library function in cuBlas_v2/CuSparse libraries which can subtract the two vectors?

I appreciate your help.


Use the cusparse csrmv function:

Set alpha to -1
set A and x to your A and x
set y to your b
set beta to 1

The result will overwrite your y (b) vector. If you need that b vector after this operation, then make a separate copy of it as y, perhaps using cublas copy routine.