constant memory as pointer?

Hello,

Can I do this?

__constant__ float * myconst;

and then in host , something like:

cudaMemcpyToSymbol( myconst , inputF , sizeof(inputF)

Because if I define

__constant__ float myconst[100];

it works fine.

Can I use the constant memory as dymanically ?

A pointer and an array are two different things. In the first case, only the pointer lives in constant memory. In the second case, the entire array lives in constant memory. The first example only allocates storage that is the size of a float pointer (so 4 bytes or 8 bytes). The second example allocates storage for the full array of float values.

The second example is probably what you want.

Hmm , ok!

And if I have this:

__constant__ float Rows;

__constant__ float Cols;

Is there a way to do :

__constant__ float myconst[Rows*Cols]

Not as far as I know. The myconst declaration you are showing implies a static allocation, which must be computable at compile time.

Note here:

http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#device-memory-qualifiers

shared and constant variables have implied static storage.”

Ok , thank you!

If you’re using a CC 3.5 or later GPU, the constant memory is the same as the texture cache (called the read-only cache), I believe.

Then, instead of partitioning the data yourself, you can just let the hardware cache it in the read-only cache. You can do that by declaring your array as const restrict or by explicitly using ldg().

(delete me)

Ok, thanks!