How to synchronize CuSPARSE functions (as cusparseDcsrmv, ...)

Hi

The documentation says about cusparseDcsrmv (and other CuSPARSE functions):

It is executed asynchronously with respect to the host and may return control to the application on the host before the result is ready.

BUT in the examples (conjugate gradient solver), I did NOT find any synchronization between subsequent calls to CuBLAS and/or CuSPARSE.

So I’m a bit confused: Is there’s some sort of automatic synchronisation or how can I make sure that the function has terminated on the GPU before the next one will be started?

Subsequent cuda calls in the same stream (default, in the case of the sample codes e.g. conjugate gradient) don’t need to be synchronized. cuda functions issued to the same stream are automatically serialized.

If you did actually want to synchronize against the host thread, you could use

cudaDeviceSynchronize();