title: How do I allocate device memory to my array of pointers, in CUDA?
body: <p>I have the following data structures on my host:</p>
  
  <pre><code>typedef struct point{
     int x;
     int y;
  }Point;
  
   typedef struct pair{
       Point i;
       Point j;
       float cost;
   }Pair;
  
  Pair* pairs[n];   // allocates an array of pointers to pair
  </code></pre>
  
  <p>Now, I've to copy "pairs" to the GPU. So, I declare the following pointer:</p>
  
  <pre><code>Pair **d_pair;
  </code></pre>
  
  <p>and allocate the memory using the following:</p>
  
  <pre><code>cudaMalloc((void**)d_pair,(sizeof(Pair)+sizeof(Pair*))*n);
  </code></pre>
  
  <p>Now, I copy from host to device:</p>
  
  <pre><code>cudaMempy(d_pair,pair,(sizeof(Pair)+sizeof(Pair*))*n),cudaMemcpyHostToDevice);
  </code></pre>
  
  <p>The kernel prototype receives d_pair as:</p>
  
  <pre><code>__global__ my_kernel(Pair* d_pair[], ... ){ 
  ...
  }
  </code></pre>
  
  <p>Should the above sequence of statements work as intended? If not, what modifications I make? Basically, I want to copy Pair* pairs[n]; as such to "d_pair". How do I do this?</p>