Error "invalid device symbol" in cudaMemcpyToSymbol using CUDA 5.5

Hi guys,

I finally came accross this infamous issue, and still didn’t figure it out yet, can someone help me?

Here is my data structure:

struct myParams
  float3 A;
  float3 B;
  int3 C;
  int3 D;
  float E;
  float F;
  int G;
  int H;
  1. allocate host memory
myParams *h_params = new myParams;
  1. copy data to constant memory
__constant__ myParams d_params;
   cudaMemcpyToSymbol ( d_params, h_params, sizeof(myParams) );

it can pass through compilation, but get “invalid device symbol” when trying to run this code.

However, if I use cuda 4.2 with deprecated character string like

cudaMemcpyToSymbol ( "d_params", h_params, sizeof(myParams)

then, it can run without any problems.

Thanks in advance for any advice.

String arguments in CUDA API calls were removed in CUDA 5.0. Please use the symbol name directly.


Yes, that’s why I use

cudaMemcpyToSymbol ( d_params, h_params, sizeof(myParams) );

instead in cuda 5.5.

But the problem is that I still got the error “invalid device symbol” while running it. If I just use one float element in struct myParams, it workes fine. Is there anything wrong with the struct alignment?

Hard to tell whether it could be an alignment issue, as float3 and int3 are not built-in types. In general CUDA tries to achieve interoperability of structs between host and device by enforcing the same alignment and padding. I am aware of at least one case where restrictions on the host side prevent this. It would probably be a good idea to check on the struct sizes on both host and device for both CUDA 4.2 and CUDA 5.5 to see whether there are any discrepeancies.

I never use this API and thus have no insights what likely causes of “invalid device symbol” are.


In cuda sdk sample “particles”, they used a struct pretty much the same as i did :

struct SimParams
    float3 colliderPos;
    float  colliderRadius;

    float3 gravity;
    float globalDamping;
    float particleRadius;

    uint3 gridSize;
    uint numCells;
    float3 worldOrigin;
    float3 cellSize;

    uint numBodies;
    uint maxParticlesPerCell;

    float spring;
    float damping;
    float shear;
    float attraction;
    float boundaryDamping;
__constant__ SimParams params;
checkCudaErrors(cudaMemcpyToSymbol(params, hostParams, sizeof(SimParams)));

So alignment shouldn’t be an issue in this case. It’s really weird.