__syncthreads()死锁 [英] __syncthreads() Deadlock

查看:210
本文介绍了__syncthreads()死锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果只有一些线程执行,__syncthreads()会导致死锁吗?

Will __syncthreads() cause a dead lock if only some threads execute it?

我有一个这样的内核:

__global__ void Kernel(int N,int *a)
{
    if(threadIdx.x<N)
    {
      for(int i=0;i<N;i++)
       {
        a[threadIdx.x]= //Some calculation using a and i
        __syncthreads()
       }
    }
}

如果块中的线程数大于N ,那么一些线程将不会执行代码。这将导致死锁吗?

如果是,那么我如何修改代码?

if the number of threads in the block is greater than N, then some threads will not execute the code. will this cause a deadlock?
if yes, then how can i modify the code?

推荐答案

应该在分歧代码中使用 __ syncthreads()。它在这种情况下的行为是未定义的。

You should not use __syncthreads() in a divergent code. Its behaviour in such circumstances is undefined.

__ syncthreads() ,这个分支将以相同的方式由一个块中的所有线程(或者全部,或者一个块中没有线程取分支)统一计算。

__syncthreads() may appear in a conditional branch only if you are sure, this branch will be evaluated uniformly, in the same way, by all threads in a block (either all, or no threads from a block take the branch).

这篇关于__syncthreads()死锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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