title: How can I add up two 2d (pitched) arrays using nested for loops?
body: <p>I'm new to cuda. I want to add up two 2d array into a third array.
  I use following code:</p>
  
  <pre><code>cudaMallocPitch((void**)&amp;device_a, &amp;pitch, 2*sizeof(int),2);
  cudaMallocPitch((void**)&amp;device_b, &amp;pitch, 2*sizeof(int),2);
  cudaMallocPitch((void**)&amp;device_c, &amp;pitch, 2*sizeof(int),2);
  </code></pre>
  
  <p>now my problem is that i dont want to use these array as flattened 2-d array
  all in my kernel code i want to di is use two for loop &amp; put the result in the third array like</p>
  
  <pre><code>__global__ void add(int *dev_a ,int *dev_b,int* dec_c)
  {
      for i=0;i&lt;2;i++)
      { 
        for j=0;j&lt;2;j++)
        {
          dev_c[i][j]=dev_a[i][j]+dev_b[i][j];
        }
      }
  }
  </code></pre>
  
  <p>How i can do this in CUDA?
  please tell me how to use 2-d array in this way ?</p>
  
  <p>What should be the kernel call for using 2d-array ?
  If possible, please explain using code samples.</p>