有谁知道cudaSetDevice
的以下用法是否正确?我想在任何主机线程中随时重复调用在不同设备上创建的资源;有没有办法在CUDA中做到这一点?
cudaSetDevice(0);
/...create cuda streams and do some memory allocation on gpu.../
cudaSetDevice(1);
/...create cuda streams and do some memory allocation on gpu.../
#pragma omp parallel num_threads(2)
{
int omp_threadID=omp_get_thread_num();
....
if (omp_threadID==0)
{
cudaSetDevice(0);
/...calling streams/memory created on device 0.../
}
else
{
cudaSetDevice(1);
/...calling streams/memory created on device 1.../
};
};
答案 0 :(得分:1)
是的,这样的事情应该有效。确保您在设备0上创建的所有内容,仅在OpenMP线程0中使用,同样在设备1和线程1中使用。
您可能还想查看CUDA OpenMP Sample Code,它演示了如何使用OpenMP线程来管理单个设备。