Copy one constant value

Hi all

I want to store in contant memory a float value. I declare it as:

__constant__ float RADIUS;

And then I want to copy the value “radius” to RADIUS as:

cutilSafeCall(cudaMemcpyToSymbol(RADIUS,radius,sizeof(float),0,cudaMemcpyHostToDevice));

The compiler out:

Using arrays I have no problem. But does anybody know how can I copy just one value to constant memory?

Thank you everyone for your time.

PD: If it is possible I don’t want to pass it by kernel parameter.

I tried this:

cutilSafeCall(cudaMemcpyToSymbol(&RADIUS,&radius,sizeof(float),0,cudaMemcpyHostToDevice));

It complies fine, but the execution outs:

Does anyboydy know why?

Thank you again

Copy an array of floats of size 1.

BTW, why not use a simple #define???

eyal

Just because it’s going into constant memory doesn’t mean it’s a compile time constant.

Silly me :"> you’re correct of course… :)

You’re right :)

That’s what I did before and It works, but I don’t like that way. It’s just for doing things the best way.

I think that you can do:

cutilSafeCall(cudaMemcpyToSymbol("RADIUS",radius,sizeof(float),0,cudaMemcpyHostToDevice));

This is from the reference manual:

symbol can either be a variable that resides in

global or constant memory space, or it can be a character string, naming a variable that resides in global or constant

memory space.

Hope this helps.

You’re right. Thanks for the information. Anyway, my problem wasn’t this. I finally did it like this:

__constant__ float RADIUS;

cutilSafeCall(cudaMemcpyToSymbol(*(&RADIUS),&radius,sizeof(float),0,cudaMemcpyHostToDevice));

This works fine.

On the other hand this only works with contant memory but in global memory I do:

cutilSafeCall(cudaMalloc((void**)finishedDevice, sizeof(bool)));

bool finished=false;

cutilSafeCall(cudaMemcpy(&finishedDevice,&finished,sizeof(bool),cudaMemcpyHostToDevice));

This compiles but I get an error in execution time of “invalid device pointer”. Any sugestions?

Thank you everyone.

I don’t know what type is your finishedDevice, but if it’s a simple pointer, you miss one & :

bool* finishedDevice;

cutilSafeCall(cudaMalloc((void**)&finishedDevice, sizeof(bool)));

It’s not a pointer. Just a primitive.

bool finishedDevice;

Thank you anyone.