title: 2D array with CUDA and cudaMallocPitch
body: <p>I have been reading a few threads on stackoverflow about 2D arrays and cudaMallocPitch and I have tried to use cudaMallocPitch with the small documentation I have found. However I'm now facing a problem. </p>
  
  <p>I need to go through an array and do something similar : </p>
  
  <pre><code> for(int k=0; k&lt;100; ++k){
       for(i=SID; i&lt;SID+stride; ++i){
          while(-1 &lt; j &amp;&amp; Driver[k][j] != Road[i]){
              j = Pilot[j][k];
  
          }
          ++j;
       }
    }
  </code></pre>
  
  <p>I was thus wondering, how should I adapt this code to make it work with the pitch, because I have read that I had to update the pointer to the beginning of the row. Of course my kernel receives the following :</p>
  
  <pre><code>__global__ void driving(char *Driver, size_t pitch_driver, 
                          char *Road, int *Pilot, size_t pitch_pilot) 
  </code></pre>
  
  <p>And I'm not really sure how to make things working, I've been reading and trying, but it seems not working at the moment. </p>
  
  <p>Thank you.</p>
  
  <p><strong>Edit 1:</strong> I have been reading this thread in particular :<a href="https://stackoverflow.com/questions/5029920/how-to-use-2d-arrays-in-cuda/9974989#9974989">How to use 2D Arrays in CUDA?</a> and came across the lines : </p>
  
  <pre><code>for (int row = 0; row &lt; rowCount; row++)  
   {  
       // update the pointer to point to the beginning of the next row  
      float* rowData = (float*)(((char*)d_array) + (row * pitch));  
      for (int column = 0; column &lt; columnCount; column++)  
       {  
         rowData[column] = 123.0; // make every value in the array 123.0  
         destinationArray[(row*columnCount) + column] = rowData[column];  
        }  
   }  
  </code></pre>
  
  <p>Which is updating the pointer of the next row, I'am not sure how to use to make my 2 for loops and while working such as in the previous code. </p>
  
  <p>At the moment I can only access one dimension of my array but not the other one.</p>
  
  <p>it returns the value 2, but when I try my multiple comparisons, it only returns 0, or even comparing two values do not work.</p>