If you declare an array of pointers, eg.
float * myArray[10];
there are 3 memory spaces in play:
- the memory containing the address of that
myArrayarray. For this question we don’t care about this one. - the memory containing the 10 pointers in the array, i.e. the memory that the
myArraypointer value points at. - the memory that
myArray[0]points at.
Normally in C++, you do something like this:
volatile float *const myArray[10];
or
float volatile *const myArray[10];
In this example the const keyword is for the array (2) and the volatile keyword is for the floats (3).
So, now we want to store an array of pointers in CUDA shared memory. Those pointers each point somewhere else, let’s say, in device memory.
Analogous to the above that declaration would look like this:
extern __device__ float *__shared__ myArray[10];
except, this doesn’t work, and contra the usual spiral rule in C++, the line below declares an array that lives in shared memory.
extern __shared__ float * myArray[10];
This means those 10 pointers always point to generic memory and there is no way to declare pointers to a different memory space here. Is there a syntax to specify that those 10 pointers point to eg. device memory space?