正如这里所说:如何减少 CUDA 同步延迟/延迟 https://stackoverflow.com/questions/11953722/how-to-reduce-cuda-synchronize-latency-delay
等待设备结果有两种方法:
- “轮询” - 在旋转中消耗 CPU - 以减少等待结果时的延迟
- “阻塞”——线程处于休眠状态,直到发生中断——以提高总体性能
For “轮询”需要使用CudaDeviceScheduleSpin
.
But for “封锁”我需要用什么CudaDeviceScheduleYield
or cudaDeviceScheduleBlockingSync
?
之间有什么区别cudaDeviceScheduleBlockingSync
and cudaDeviceScheduleYield
?
cudaDeviceScheduleYield
如所写:http://developer.download.nvidia.com/compute/cuda/4_1/rel/toolkit/docs/online/group__CUDART__DEVICE_g18074e885b4d89f5a0fe1beab589e0c8.html http://developer.download.nvidia.com/compute/cuda/4_1/rel/toolkit/docs/online/group__CUDART__DEVICE_g18074e885b4d89f5a0fe1beab589e0c8.html“指导 CUDA放弃它的线程等待设备结果时。这个可以增加延迟等待设备时,但可以提高性能与设备并行执行工作的 CPU 线程数。” - 即等待结果而不在旋转中烧毁 CPU - 即“阻塞”。 cudaDeviceScheduleBlockingSync 也是 - 等待结果而不在旋转中烧毁 CPU。但是有什么区别呢?
据我了解,这两种方法都使用轮询来同步。在伪代码中CudaDeviceScheduleSpin
:
while (!IsCudaJobDone())
{
}
whereas CudaDeviceScheduleYield
:
while (!IsCudaJobDone())
{
Thread.Yield();
}
i.e. CudaDeviceScheduleYield
告诉操作系统它可以中断轮询线程并激活另一个线程执行其他工作。这提高了 CPU 上其他线程的性能,但也会增加延迟,以防 CUDA 作业在轮询线程以外的另一个线程此时处于活动状态时完成。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)