dynamic shared memory?

Hello,

Im quite new to cuda and C++, so this might be a newbie question

im usiung shared memory as a char array in my kernel, of which i know the size before the Kernel is launched

so my question and since declaration like

shared char A [3 * VariableA];

fails, how can i declare variable shared memory

(VariableA is part of the kernels parameter…)

Thanks !

Maz

Declare it like this

extern __shared__ char A[]

and give the kernel the amount of shared memory you want (in bytes) as a third parameter, after grid dimension and block dimension.

kernel<<<gridDim, blockDim, sharedSizeInBytes>>>(..)

thank you, thats sounds promising! :)

And… what happen if you want two or three arrays in shared memory with a different size and you CAN’T use templates?

shared extern float a; //128 elements
shared extern float b; //32 elemets
shared extern float c; …

Thanks.

Ok. I got it: Using one array and several pointers :)