title: How to pass structures into CUDA device?
body: <p>I've been stuck on this for a while. When I pass my structures into CUDA via kernel parameters, they contain no data and everything is undefined inside of them.</p>
  
  <p>Out in host global space</p>
  
  <pre><code>struct matl1
  {
      static const double cond;
  };
  
  const double matl1::cond = 420.5;
  </code></pre>
  
  <p>Then inside of main()</p>
  
  <pre><code>matl1 * h_matl1 = (matl1*)malloc(sizeof(matl1));
  matl1 * d_matl1;
  cudaMalloc((void**)&amp;d_matl1, sizeof(matl1));
  cudaMemcpy(d_matl1, h_matl1, sizeof(matl1), cudaMemcpyHostToDevice);
  kernel&lt;&lt;&lt;1,1&gt;&gt;&gt;(d_matl1,...);
  </code></pre>
  
  <p>Then inside of kernel()</p>
  
  <pre><code>__global__ void kernel(matl1* d_matl1,...)
  {
  double cond = d_matl1-&gt;cond;
  }
  </code></pre>
  
  <p>And I get the following error:</p>
  
  <pre><code>error : identifier "matl1::cond" is undefined in device code
  </code></pre>
  
  <p>As a quick test, if I do the following on the host in main()</p>
  
  <pre><code>cout &lt;&lt; h_matl1-&gt;cond &lt;&lt; endl;
  </code></pre>
  
  <p>It shows me the correct output of 420.5. I am not sure why this isn't making it into the device.</p>
  
  <p>Here's the rest of my output</p>
  
  <p>uild started: Project: test_struct, Configuration: Debug Win32 ------</p>
  
  <p>Compiling CUDA source file kernel.cu...</p>
  
  <p>C:\Users\User\Documents\Visual Studio 2012\Projects\test_struct\test_struct>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\bin\nvcc.exe" -gencode=arch=compute_35,code=\"sm_35,compute_35\" --use-local-env --cl-version 2012 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include"  -G   --keep-dir Debug -maxrregcount=0  --machine 32 --compile -cudart static  -g   -DWIN32 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o Debug\kernel.cu.obj "C:\Users\User\Documents\Visual Studio 2012\Projects\test_struct\test_struct\kernel.cu" 
  1>C:/Users/User/Documents/Visual Studio 2012/Projects/test_struct/test_struct/kernel.cu(15): error : identifier "matl1::cond" is undefined in device code</p>
  
  <p>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\BuildCustomizations\CUDA 5.5.targets(592,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\bin\nvcc.exe" -gencode=arch=compute_35,code=\"sm_35,compute_35\" --use-local-env --cl-version 2012 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\include"  -G   --keep-dir Debug -maxrregcount=0  --machine 32 --compile -cudart static  -g   -DWIN32 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o Debug\kernel.cu.obj "C:\Users\User\Documents\Visual Studio 2012\Projects\test_struct\test_struct\kernel.cu"" exited with code 2.</p>
  
  <p>========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========</p>