CUDA阻塞标志 [英] CUDA blocking flags

查看:576
本文介绍了CUDA阻塞标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建CUDA事件时,您可以选择打开 cudaEventBlockingSync 标志。但是 - 如果创建一个事件与有或没有标志之间的区别?我阅读精细手册;它对我来说没有意义。什么是调用主机线程,什么阻止,当你不使用该标志?


4.6.2.7 cudaError_t cudaEventSynchronize(cudaEvent_t event)



阻塞,直到事件实际记录了
。 ...等待使用
cudaEventBlockingSync 标志创建的
事件将导致
调用主机线程阻塞,直到
事件实际上



解决方案

当您调用该函数时,线程将停止执行,直到该事件发生,此时程序继续。这是一种确保您知道正在运行的程序的状态的方法。这在CUDA中尤其重要,因为这么多东西是异步的。



调用主机线程是在主机的CPU上运行的线程,其中CUDA设备。





我认为阻塞同步和常规同步之间的区别是线程阻塞并且将不会运行,直到事件完成,而不是等待时旋转的线程,不断检查值。这意味着线程不会使用任何额外的CPU时间旋转,而是会在事件完成后被唤醒。这是有用的,例如,你在一个服务器上运行这个程序,其中CPU时间是溢价或你必须支付每单位时间。


When creating a CUDA event, you can optionally turn on the cudaEventBlockingSync flag. But - what if the difference between creating an event with or without the flag? I read the fine manual; it just doesn't make sense to me. What is the "calling host thread", and what "blocks" when you don't use the flag?

4.6.2.7 cudaError_t cudaEventSynchronize(cudaEvent_t event)

Blocks until the event has actually been recorded. ... Waiting for an event that was created with the cudaEventBlockingSync flag will cause the calling host thread to block until the event has actually been recorded.

解决方案

when you call that function, the thread will stop executing until that event happens, at which time the program continues. It is a way of making sure you know the state of the running program. This is especially important in CUDA because so many things are asynchronous.

The "calling host thread" is the thread that is running on the CPU of the host computer in which the CUDA device resides.


edit in response to comment below:

I believe that the difference between a "blocking sync" and a regular sync is that the thread blocks and will not run until the event is completed, as opposed to a thread that "spins" as it waits, constantly checking the value. This means that the thread will not use any extra CPU time spinning, but will instead be awakened once the event is completed. This is useful if, say, you're running this program on a server where CPU time is at a premium or you have to pay per unit time.

这篇关于CUDA阻塞标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆