cudaMemcpyToSymbol not copying data from host to __constant__ memory

Alec Jacobson

December 10, 2010

weblog/

I had declared some constant memory variable at the top of my program like this:
__device__ __constant__ float constant_T[M];
Then I tried to fill it from my host array T with the following:
cudaMemcpyToSymbol("constant_T", T, sizeof(float)*M,cudaMemcpyHostToDevice);
Surprisingly I got no compilation errors and no cuda errors at runtime via
printf("Cuda errors: %s\n", cudaGetErrorString( cudaGetLastError() ) );
After some staring I finally figured it out, the copying doesn't need the last parameter. It should be:
cudaMemcpyToSymbol("constant_T", T, sizeof(float)*M);