Question about using shared memory

Hello everyone,

I would like to allocate an array in the shared memory in my cuda kernel. What I would like to do is something along the lines:

[codebox]

const int dims = blockIdx.x * blockDim.x;

shared int myArray [blockIdx.x * blockDim.x];

[/codebox]

However, this fails with “Constant value is not known”. I guess it is expecting a constant compile time known value. Is there a way to get past this? I am trying to reduce registers usage in my kernel by allocating things as much as possible into the shared memory.

Thanks,

/x

Kernel launch has a 3rd paramter that specify the extra amount of shared mem for the kernel launch.

Search for “extern” in NVIDIA Prog guide.

But that would mean you allocate a “constant” amount of smem for EVERY block… But ur requirement seems to be different. That is NOT possible… (blockId * blockDim) amount of smem ??? (block 0 will have 0 elements??)