title: accessing memory allocated with cudaMallocPitch
body: <p>I'm trying to create a 2d array in cuda and initializing it but failing miserably.
  Here's my initialization kernel:</p>
  
  <pre><code>__global__ void initMap(float* map, size_t pitch, int w, int h, int numX, int numY){
  int idx=blockIdx.x*blockDim.x+threadIdx.x;
  int idy=blockIdx.y*blockDim.y;
  int i;
  int j;
  for (i=0; i&lt;numX; i++){
      for (j=0; j&lt;numY; j++){
          int idMC=idx+i;
          int idMR=threadIdx.y+j;
          if(idMC&lt;w &amp;&amp; idy+idMR&lt;h){
               float* row=(float*)(map+idy+idMR*pitch);
               row[idMC]=0.5;
          }
      }
  }
  
  __syncthreads();
  }
  </code></pre>
  
  <p>And here's how I allocate the array and call the initialization kernel in the main:</p>
  
  <pre><code>int width=map_size;
  int height=map_size;
  float* map;
  size_t pitch;
  checkCudaErrors(cudaMallocPitch(&amp;map, &amp;pitch, width*sizeof(float), height));
  int numT=32;
  int numBX=(int)ceil((float)width/numT);
  int numBY=(int)ceil((float)height/numT);
  dim3 numBlocks(numBX, numBY);
  dim3 numThr(numT, numT);
  initMap &lt;&lt;&lt;numBlocks, numThr&gt;&gt;&gt; (map, pitch/sizeof(float), width, height, 1, 1);
  cudaError_t err=cudaGetLastError();
  if (err != cudaSuccess) 
      printf("Error: %s\n", cudaGetErrorString(err));
  checkCudaErrors(cudaDeviceSynchronize());
  </code></pre>
  
  <p>Basically, what I'm trying to do is dividing the 2D array into 32x32 chunks, and assign each of those to a block which would then fill it with 0.5. However, when I try to either write the array to disk or access its elements from another kernel, I can see that there's many QNANs in there, so I guess I'm not filling up the whole array but rather missing some spots. </p>