Does anyone know if the following usage of cudaSetDevice
is correct? I want to repeatedly call resources created on different devices at any time, in any host thread; is there a way to do this in 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.../
};
};
Yes, something like that should work. Make sure that all things you created on device 0, you only use in OpenMP thread 0, and likewise for device 1 and thread 1.
You may also want to look at the CUDA OpenMP Sample Code , which demonstrates how to use OpenMP threads to each manage an individual device.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.