Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__syncthreads() Deadlock

Tags:

c++

cuda

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 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?

like image 586
lina Avatar asked Oct 15 '25 16:10

lina


1 Answers

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

like image 165
CygnusX1 Avatar answered Oct 18 '25 05:10

CygnusX1