我正在编写一个混合cpu-gpu程序,需要多个cpu线程访问多个gpu。CUDA Stream是线程安全的吗?具体来说,我想知道以下做法是否正确:
// 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);
});