title: cudaMalloc of a structure and an element of same structure
body: <p>I would like to know what happens on the device (memory wise) when I allocate a structure and then <strong>allocate(?) and copy</strong> a pointer element of the same structure. </p>
  
  <p>Do I need <code>cudaMalloc</code> of the element <strong>*a</strong> again?</p>
  
  <p>Example code:</p>
  
  <pre><code>typedef struct {
    int *a;
    ...
  } StructA;
  
  int main() 
  {
    int row, col, numS = 10; // defined at runtime
  
    StructA *d_A = (StructA*)malloc(numS * sizeof(StructA));
    int *h_A = d_a-&gt;a;
  
    cudaMalloc( (void**)&amp;(d_A), numS * sizeof(StructA) );
  
    cudaMalloc( &amp;(d_A-&gt;a), row*col*sizeof(int) ); // no (void**) needed?
    cudaMemcpy( d_A-&gt;a, h_A, row*col*sizeof(int), cudaMemcpyHostToDevice );
  
    kernel&lt;&lt;&lt;grid, block&gt;&gt;&gt;(d_A); // Passing pointer to StructA in device
    ...
  }
  </code></pre>
  
  <p>The kernel definition:</p>
  
  <pre><code>__global__ kernel(StructA *d_A)
  {
    d_A-&gt;a = ...;
    ...
  }
  </code></pre>
  
  <p>This question is another extension of <a href="https://stackoverflow.com/questions/19404965/how-to-use-cudamalloc-cudamemcpy-for-a-pointer-to-a-structure-containing-point">this question</a> and related to <a href="https://stackoverflow.com/questions/22078399/cudamalloc-cast-void-and-struct-member-allocation-copy-and-sizeof">this question</a>.</p>