title: Best way to debug OpenCL Kernel
body: <p>I have following openCL kernel I want to debug.
  I have put some printf in it but those are not useful as work items are schedules randomly and values printed are not always right.
  How I can make my work items in kernel execute in serial for debugging purpose?</p>
  
  <p>Following is code </p>
  
  <pre><code>__kernel
  void SampleKernel( __global float4* gVtx,  __global float4* gColor,  
                   __global float4* gDst,
                   const int cNvtx, 
                   const int4 cRes )
                   {
                     printf("nVertex : %d ", cNvtx);
  
                     for(int i =0 ; i &lt; 1; i+=4)
                     {
  
                     printf(" %f ",  gVtx[0].x);
  
                     printf(" %f ",  gVtx[0].y);
  
                     printf(" %f ",  gVtx[0].z);
  
                     printf(" %f ",  gVtx[0].w);
  
                     }
  
                   }
  </code></pre>
  
  <p>I have also tried putting calls <code>barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);</code> before and after <code>printf</code> but it was not useful.
  Can anybody please suggest me way I can serialize work item execution so I can print and debug kernel? Or some other better way to debug OpenCL kernel. I am using RX 580 AMD GPU.</p>