NVIDIA / CUDALibrarySamples

CUDA Library Samples
Other
1.62k stars 348 forks source link

Question about the external buffer in cusparseSpMV #212

Closed jczhang07 closed 2 months ago

jczhang07 commented 2 months ago

Hello, See https://docs.nvidia.com/cuda/cusparse/#cusparsespmv.

Suppose I want to compute both y = Ax and u = A^t v with the same matrix A, do I need to call cusparseSpMV_bufferSize() and cusparseSpMV_preprocess() twice, one for CUSPARSE_OPERATION_NON_TRANSPOSE and the other for CUSPARSE_OPERATION_TRANSPOSE, to get two external buffers, and use them selectively in the subsequent cusparseSpMV() call?

qanhpham commented 2 months ago

Yes, you should use different buffers and run cusparseSpMV_preprocess() with each buffer for your SpMVs respectively.

jczhang07 commented 2 months ago

From my preliminary experiment, it seems I have to use the same external buffer for both y = Ax and u = A^t v. I am not sure that is the meaning of

The same external_buffer must be used for all cusparseSpMV calls. [CUSPARSE-1897]

at https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cusparse-release-12-6

qanhpham commented 2 months ago

The release note means that the same external buffer must be used for all SpMVs with a same matrix. Here, you have 2 SpMVs on different matrices A and A^t. Each SpMV needs to use its own buffer, and they can't use different buffers for all SpMV calls.

qanhpham commented 2 months ago

There's a bug at the moment that you must use a same buffer for a matrix descriptor. To use a different buffer for A^t * v, you need to create a different matrix descriptor to perform SpMV with A^t.

jczhang07 commented 2 months ago

Thanks, I now knew the crash in our CI is not my fault :)