Declaration of shared memory arrays in kernel function

How do you declare shared memory arrays in kernel function?

I attempted the following, after referring to Programming Guide :: CUDA Toolkit Documentation

shared array;

int ix = blockIdx.x * blockDim.x + threadIdx.x;
if (ix <n) {
array[ix] = beta * array[ix];
}

but I end up getting errors. The array has a fixed size and is 1-dimensional.

When posting code on these forums, please use appropriate code formatting. An example is to select the code you have put in the edit window, then select the </> button at the top of the edit window.

The code you have shown will not compile. Maybe that’s what you mean by “getting errors”. This posting gives an example of both a dynamic shared memory allocation as well as a static shared memory allocation.

I can’t tell what datatypes you are using, but for example for int you would do something like:

const int COMPILE_TIME_CONSTANT = 32;
__shared__ int array[COMPILE_TIME_CONSTANT];

Thank you. I attempted the following:

const int size = 69789;
shared double eta_nbv[size];

My block size is 512. And my grid size is 240. The total shared memory per block on my GPU architecture is 49152 bytes.

I get the error “uses too much shared data”. Shouldn’t the total shared memory usage per block be equal to block size x precision type.
512 x 8 = 4096

The shared memory per block for statically allocated shared memory (what you are doing here) is limited to 48KB. For doubles, 8 bytes each, that would be 6144 doubles, max.

Please read the item I linked as it covers these topics already.