title: How to use CUDA constant memory in a programmer pleasant way?
body: <p>I'm working on a number crunching app using the CUDA framework. I have some static data that should be accessible to all threads, so I've put it in constant memory like this:</p>
  
  <pre><code>__device__ __constant__ CaseParams deviceCaseParams;
  </code></pre>
  
  <p>I use the call cudaMemcpyToSymbol to transfer these params from the host to the device:</p>
  
  <pre><code>void copyMetaData(CaseParams* caseParams)
  {
      cudaMemcpyToSymbol("deviceCaseParams", caseParams, sizeof(CaseParams));
  }
  </code></pre>
  
  <p>which works.</p>
  
  <p>Anyways, it seems (by trial and error, and also from reading posts on the net) that for some sick reason, the declaration of deviceCaseParams and the copy operation of it (the call to cudaMemcpyToSymbol) must be in the <em>same file</em>. At the moment I have these two in a .cu file, but I really want to have the parameter struct in a .cuh file so that any implementation could see it if it wants to. That means that I also have to have the copyMetaData function in the a header file, but this messes up linking (symbol already defined) since both .cpp and .cu files include this header (and thus both the MS C++ compiler and nvcc compiles it).</p>
  
  <p>Does anyone have any advice on design here?</p>
  
  <p><strong>Update:</strong> See the comments</p>