Upgrade to CUDA 5.0: cudaMemcpyToSymbol invalid device symbol error

You have just upgraded to CUDA 5.0 and the function cudaMemcpyToSymbol() throws you the infamous "invalid device symbol" error. Here is what to do.

Since CUDA 5.0 the following usage of cudaMemcpyToSymbol() is no longer supported (c.f. CUDA 5.0 release notes):

namespace Test_name {
__device__ __constant__ float c_array[10];

void test(){    
    // You can't designate the variable symbol with a character string anymore:
    cudaMemcpyToSymbol("Test_name::c_array", h_array, sizeof(float)*10, 0, cudaMemcpyHostToDevice );
}
}

Instead of using a character string use directly the symbol name:

cudaMemcpyToSymbol(Test_name::c_array, h_array, sizeof(float)*10, 0, cudaMemcpyHostToDevice );

If the variable is not accessible from the file you want to do the cudaMemcpyToSymbol(), you can encapsulate it in a function accessor. Or do a forward definition of the constant by "re-declaring" it as an extern:

namespace Test_name {
extern __device__ __constant__ float c_array[];
}