title: CUDA: Calling a __device__ function from a kernel
body: <p>I have a kernel that calls a <strong>device</strong> function inside an if statement. The code is as follows:</p>
  
  <pre><code>__device__ void SetValues(int *ptr,int id)
  {
      if(ptr[threadIdx.x]==id) //question related to here
            ptr[threadIdx.x]++;
  }
  
  __global__ void Kernel(int *ptr)
  {
      if(threadIdx.x&lt;2)
           SetValues(ptr,threadIdx.x);
  }
  </code></pre>
  
  <p>In the kernel threads 0-1 call SetValues concurrently. What happens after that? I mean there are now 2 concurrent calls to SetValues. Does every function call execute serially? So they behave like 2 kernel function calls?</p>