I thought that shared memory of a cuda-device is private to a block. However, it seems to me that the pointer of shared memory across two blocks is identical:
#include <stdio.h>
__global__ void foo() {
__shared__ int ar[8];
printf("shared memory pointer %p at blockidx %i\n", ar, blockIdx.x);
}
int main() {
dim3 blockDim(1);
dim3 gridDim(2);
foo<<<gridDim, blockDim>>>();
cudaDeviceSynchronize();
}
Running to code above produces:
shared memory pointer 0x7f88f5000000 at blockidx 0
shared memory pointer 0x7f88f5000000 at blockidx 1
With this program, I expected to create two different blocks, initialize shared memory on each block and obtain two different locations for the memory. Am I misunderstanding something? Or do these pointer indeed have a different physical location but within a block the addresses seem to be the same?