copy only a small type from host to device cudaMemcpy not for an array

Hi all,

I have a very basic problem: I want to copy a simple element from the host to the device.
On the web, I can find examples showing how to do so for an array, but no for a simple value…

I defined a constant variable:

constant float3 c_lightPos;

and during a function executed on the host I try to give it a value:

float3 t = make_float3(2,2,2);
cudaError_t r = cudaMemcpy( &c_lightPos, &t, sizeof(float3), cudaMemcpyHostToDevice );

but r == cudaErrorInvalidValue

Where does come from this “invalid value”?
What am I doing wrong?

Thank you.

– Pium

cudaMemcpy cannot be used to copy to constant memory, it is restrict to GPU global memory only. Use cudaMemcpyToSymbol() instead.

ahhhh :D Thanks
I saw it, but the char* parameter disturbed me.
How course, you can’t access to a pointer in the device memory, so a mecanism uses the variable name (smart cuda!)

What I understood is that, if a variable is declared using constant we have to use ‘cudaMemcpyToSymbol’ instead of ‘cudaMemcpy’ for copying.

constant float3 c_lightPos;

float3 t = make_float3(2,2,2);
cudaError_t r = cudaMemcpyToSymbol(c_lightPos, &t, sizeof(t));