title: Cuda block/grid dimensions: when to use dim3?
body: <p>I need some clearing up regarding the use of dim3 to set the number of threads in my CUDA kernel.</p>
  
  <p>I have an image in a 1D float array, which I'm copying to the device with:</p>
  
  <pre><code>checkCudaErrors(cudaMemcpy( img_d, img.data, img.row * img.col * sizeof(float), cudaMemcpyHostToDevice));
  </code></pre>
  
  <p>Now I need to set the grid and block sizes to launch my kernel:</p>
  
  <pre><code>dim3 blockDims(512);
  dim3 gridDims((unsigned int) ceil(img.row * img.col * 3 / blockDims.x));
  myKernel&lt;&lt;&lt; gridDims, blockDims&gt;&gt;&gt;(...)
  </code></pre>
  
  <p>I'm wondering: in this case, since the data is 1D, does it matter if I use a dim3 structure? Any benefits over using</p>
  
  <pre><code>unsigned int num_blocks = ceil(img.row * img.col * 3 / blockDims.x));
  myKernel&lt;&lt;&lt;num_blocks, 512&gt;&gt;&gt;(...)
  </code></pre>
  
  <p>instead?</p>
  
  <p>Also, is my understanding correct that when using dim3, I'll reference the thread ID with 2 indices inside my kernel:</p>
  
  <pre><code>int x = blockIdx.x * blockDim.x + threadIdx.x;
  int y = blockIdx.y * blockDim.y + threadIdx.y;
  </code></pre>
  
  <p>And when I'm not using dim3, I'll just use one index?</p>
  
  <p>Thank you very much,</p>