Problems with cudaMemcpyToSymbol

Hi All,

I am simply not understanding this. I had working code (in v5) which now breaks in v5.5.

I declare:

constant double GRAVITY;

Then :

double hGRAVITY;
hGRAVITY = 9.81;

Then to send to a number of GPUs

for (int i = 0; i< GPU_N; i++)
{

checkCudaErrors(cudaSetDevice(i));
if( !(cudaMemcpyToSymbol(GRAVITY, &hGRAVITY, sizeof(hGRAVITY)) == cudaSuccess)) printf (“fail \n”);

}

I have tried a number of versions of this but none seem to transfer the value successfully.

I am probably just being a bit thick but I would appreciate some help.

Thanks

Darrel

OK problem solved when I used:

const double gravity = 9.81;
const double* hGRAVITY = &gravity;

and then used :

cudaMemcpyToSymbol(GRAVITY, hGRAVITY, sizeof(hGRAVITY));

I must say the programming guide is very poor when it comes to describing this and sources around the web tend to relate to older CUDA versions. Still maybe this wil help others.

Yes, agreed. The documentation is not the best explaining things like cudaMemcpyToSymbol.

Ive done it like this:

device constant double tp0_d;
const double tp0=9.0;
cudaMemcpyToSymbol(tp0_d, &tp0, sizeof(double), 0, cudaMemcpyHostToDevice);

Works fine here.