开发者

__syncthreads() Deadlock

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

i have a kernel like this:

__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()
       }
    }
}

if the number of threads in the block is g开发者_StackOverflow社区reater than N, then some threads will not execute the code. will this cause a deadlock?

if yes, then how can i modify the code?


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

__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).


Technically, kernels can't deadlock; they can only time out. But yes, what you are describing is real and can happen. The issue has actually been discussed before, for example: Realistic deadlock example in CUDA/OpenCL

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜