OpenCL:SIMT执行模型的基本问题

发布于 2024-09-15 15:02:27 字数 414 浏览 4 评论 0原文

“SIMT”架构的一些概念和设计我仍然不清楚。

根据我所看到和阅读的内容,不同的代码路径和 if() 一起是一个相当糟糕的主意,因为许多线程可能会同步执行。那么这究竟意味着什么呢?怎么样:

kernel void foo(..., int flag)
{
    if (flag)
        DO_STUFF
    else
        DO_SOMETHING_ELSE
}

参数“flag”对于所有工作单元都是相同的,并且所有工作单元都采用相同的分支。现在,GPU 是否会执行所有代码,序列化所有内容,并且基本上仍然采用未采用的分支?或者它更聪明一点,只要所有线程都同意所采用的分支,就只会执行所采用的分支?这里的情况总是如此。

即序列化总是发生还是仅在需要时发生?抱歉问了这个愚蠢的问题。 ;)

Some of the concepts and designs of the "SIMT" architecture are still unclear to me.

From what I've seen and read, diverging code paths and if() altogether are a rather bad idea, because many threads might execute in lockstep. Now what does that exactly mean? What about something like:

kernel void foo(..., int flag)
{
    if (flag)
        DO_STUFF
    else
        DO_SOMETHING_ELSE
}

The parameter "flag" is the same for all work units and the same branch is taken for all work units. Now, is a GPU going to execute all of the code, serializing everything nonetheless and basically still taking the branch that is not taken? Or is it a bit more clever and will only execute the branch taken, as long as all threads agree on the branch taken? Which would always be the case here.

I.e. does serialization ALWAYS happen or only if needed? Sorry for the stupid question. ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤独岁月 2024-09-22 15:02:27

不,并不总是发生。仅当本地工作组中的线程之间的条件不一致时,才会执行两个分支,这意味着如果本地工作组中的工作项之间的条件计算结果不同,则当前一代 GPU 将执行两个分支,但仅执行正确的分支会写入值并产生副作用。

因此,保持一致性对于 GPU 分支的性能至关重要。

No, doesn´t happen always. Executing both branches happens only if the condition is not coherent between threads in a local work group, that means if the condition evaluates to different values between work items in a local work group, current generation GPUs will execute both branches, but only the correct branches will write values and have side effects.

So, maintaining coherency is vital to performance in GPU branches.

森林很绿却致人迷途 2024-09-22 15:02:27

不确定 ati 的情况,但对于 nvidia 来说 - 它很聪明。
如果 warp 中的每个线程都以相同的方式运行,则不会出现序列化。

not sure about ati, but for nvidia - it is clever.
There will be no serialization, if every thread in warp goes the same way.

酒与心事 2024-09-22 15:02:27

在您的示例中,flag 对于所有工作项都具有相同的值,因此一个好的编译器将生成使所有工作项朝同一方向发展的代码。

但请考虑以下情况:

kernel void foo(..., int *buffer)
{
    if (buffer[get_global_id(0)])
        DO_STUFF
    else
        DO_SOMETHING_ELSE
}

这里不能保证所有工作项都将采用相同的路径,因此需要序列化或控制流消除。

in your example, flag will have the same value for all work items, so a good compiler will generate code which will take all work-items in the same direction.

But consider the following case:

kernel void foo(..., int *buffer)
{
    if (buffer[get_global_id(0)])
        DO_STUFF
    else
        DO_SOMETHING_ELSE
}

Here it is not guaranteed that all work-items will take the same path, so serialization or control-flow elimination is required.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文