简体   繁体   English

关于Open MP和cudaSetDevice()

[英]About Open MP and cudaSetDevice()

Does anyone know if the following usage of cudaSetDevice is correct? 有谁知道cudaSetDevice的以下用法是否正确? 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? 有没有办法在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. 确保您在设备0上创建的所有内容,仅在OpenMP线程0中使用,同样在设备1和线程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. 您可能还想查看CUDA OpenMP示例代码 ,该代码演示了如何使用OpenMP线程来管理单个设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM