I am writing a mixed cpu-gpu program that require multiple cpu threads to access multiple gpus. Is CUDA stream thread-safe? Specifically, I wonder if the following is correct:
// two threads concurrently enter cuda device 1 and
// launch kernel on the same stream
std::thread t1([&](){
cudaSetDevice(1);
cudaEventRecord(begin_t1, stream);
kernel<<<mygrid, myblock, 0, stream>>>(...);
cudaEventRecord(end_t1, stream);
});
std::thread t2([&](){
cudaSetDevice(1);
cudaEventRecord(begin_t2, stream);
kernel<<<mygrid, myblock, 0, stream>>>(...);
cudaEventRecord(end_t2, stream);
});