There are two ways to allocate shared memory : static and dynamic
1、static
__shared__ int Var1[10]
2、dynamic : should add "extern" keyword
extern __shared__ int Var1[]
If you use dynamic way to allocate shared memory, you should set the shared memory size when you call the function. for example:
testKernel <<< grid, threads, size>>>(...)
the third parameter is the size of shared memory. In this way, all the shared memories start from the same address. If you want to define several shared memory variables, you should write code like following.
__global__ void func(...)
{
extern __shared__ char array[];
short * array0 = (short*)array;
float * array1 = (float*)(&array0[128]);
}