title: Copying array of structs from host to device cuda
body: <p>Suppose I have a struct as follows:</p>
  
  <pre><code>typedef struct values{
  int one, int two, int three
  } values;
  </code></pre>
  
  <p>Now, suppose I create an array of values on the host and populate with random data</p>
  
  <pre><code>values vals*;
  __device__ values* d_vals;
  int main(){
       vals = (values*)malloc(sizeof(values) * A_LARGE_NUMBER);
       PopulateWithDate(); //populates vals with random data
  }
  </code></pre>
  
  <p>Now I want to be able to copy the values to the device such that I can access them in my kernel like so:</p>
  
  <pre><code>__global__ void myKernel(){
       printf("%d", d_vals[0].one);//I don't really want to print, but whenever I try to access I get an error
  }
  </code></pre>
  
  <p>Whatever I try I get an illegal memory access was encountered error.</p>
  
  <p>Here's my current attempt:</p>
  
  <pre><code>int main(){
       vals = (values*)malloc(sizeof(values) * A_LARGE_NUMBER);
       PopulateWithDate(); //populates vals with random data
  
       values* d_ptr;
       cudaGetSymbolAddress((void**)&amp;d_ptr, d_vals);
       cudaMalloc((void**)&amp;d_ptr, A_LARGE_NUMBER * sizeof(values));
  
       cudaMemcpyToSymbol(d_ptr, &amp;vals, sizeof(values) * A_LARGE_NUMBER);
       cudaDeviceSynchronize();
       dim3    blocksPerGrid(2, 2);
       dim3    threadsPerBlock(16, 16);
  
      myKernel&lt;&lt; &lt;blocksPerGrid, threadsPerBlock &gt;&gt; &gt;();
  }
  </code></pre>