I’m relatively new to CUDA and I have a question about current best practices in using shared memory, in particular with the use of dynamic shared memory variables. The question has two parts:
Is it still best practice to define one shared memory variable and then point into that variable at different positions in its allocated memory to carve out multiple variable spaces?
I ask because most of the references I can find online use a pointer method to carve out variable spaces from a single larger shared memory allocation, BUT, the newest edition of Kirk and Hwu’s book (Programming Massively Parallel Processors - 3rd Ed 2017) makes a reference to multiple variables on page 98.
The Kirk and Hwu example is as follows (noting the missing variable data type in their example):
extern shared Mds;
extern shared Nds;
While the shared memory space for the Kernel is defined in the usual way.
Using the pointer method is fine but it clearly limits the variable to a data type. Are there any methods available to mix types, or is it best practice to force variables through casting?
For example, define one shared variable as a data type float and use a point method to carve out multiple spaces as needed. If one of the spaces is used to hold a data type int, simply cast the int to a float to store it.
Thanks in advance for all assistance.