Is the time of allocating the shared memory dependent on the shared memory size?

Hi,

I wonder whether it is more expensive to activate a thread block with 32KB shared memory than a thread block with 10KB shared memory or even 0. Is it a similar process to CPU dynamic memory allocating? Is the time cost proportional to the shared memory size associated with one thread block?

Thanks!

Best regards,
Mingcheng Chen
March 23rd, 2013

Hi,
as far as I understand shared memory is not allocated.
It’s stated during compilation time, and it’s only a suggestion to a compiler, so it knows how many thread blocks can be run at the same time.
Whenever your kernel runs every thread block that is executed gets a pointer to a beginning of chunk of memory of size that you stated.
It’s entirely up to you to make sure you don’t read/write to memory assigned to different thread block, which wouldn’t make sense, as there’s no way to synchronize between blocks.
Hope it helps and if I’'m wrong, please correct me.
My best,
G.

While there is no time cost for increasing the size of a dynamic shared memory allocation itself, your kernel will most likely run slower due to decreased occupancy.