title: Maximum blocks number on a GTX TITAN
body: <p>I'm trying to compute Fourier transforms using CUDA on a nvidia GTX TITAN graphic card. I have a problem when reaching a certain number of blocks of my card.</p>
  
  <p>Here is what my card tells me when using cudaGetDeviceProperties:</p>
  
  <ul>
  <li>maxThreadsPerBlock: 1024</li>
  <li>maxThreadsDim: 1024 x 1024 x 64</li>
  <li>maxGridSize: 2147483647 x 65535 x 65535</li>
  </ul>
  
  <p>Here is the code I use to call my kernel function:</p>
  
  <pre><code>cudaDeviceProp prop;
  cudaGetDeviceProperties(&amp;prop, 0);
  
  unsigned int threads = prop.maxThreadsPerBlock;
  unsigned int max_blocks = prop.maxGridSize[0];
  unsigned int blocks = (pixel_size + threads - 1) / threads;
  
  // Hardware limit
  if (blocks &gt; max_blocks)
    blocks = max_blocks;
  
  kernel_function &lt;&lt;&lt;blocks, threads&gt;&gt;&gt;(pixel_size);
  </code></pre>
  
  <p>And the kernel code: </p>
  
  <pre><code>__global__ void kernel_function(unsigned int pixel_size)
  {
    unsigned int index = blockIdx.x * blockDim.x + threadIdx.x;
  
    while (index &lt; pixel_size)
    {
      // Treatment here
      index += blockDim.x * gridDim.x;
    }
  }
  </code></pre>
  
  <p>Where pixel_size is the size in pixels of an image block I want to do transforms on.</p>
  
  <p>So <code>threads</code> is always equal to 1024, which is what I want. Whenever <code>blocks</code> are inferior or equals to 65535, then my code works fine. But when <code>blocks</code> reaches a value above 65535, the results I have are a nonsense and totally random. So what is the maximum number of blocks I can have in a one dimension problem ? I assumed in the previous code that it was 2147483647 ? What am I doing wrong ?</p>
  
  <p>I feel like I am using the wrong hardware limit for my number of blocks because when I set it to 65535, this code is working fine.</p>
  
  <p>Thank you in advance for your answers.</p>