在 cudaStreamSynchronize 之前我需要 cudaSetDevice 吗?

Do I need cudaSetDevice before cudaStreamSynchronize?

在我的系统中,我同时对多个 GPU 进行编程。我需要在调用 cudaStreamSynchronize() 之前调用 cudaSetDevice() 吗?

创建 cudaStream_t 对象时,我确实在调用 cudaStreamCreate() 之前正确设置了设备。

我可能错了,但我认为如果您在创建流时已经使用了函数 cudaSetDevice(),则不需要再次调用它。

资源:

https://developer.nvidia.com/blog/cuda-pro-tip-always-set-current-device-avoid-multithreading-bugs/

https://forums.developer.nvidia.com/t/how-many-times-does-cudasetdevice-need-to-be-called/10646