How to initialize shared memory ?


I’m wondering if it is possible to initialize the shared memory at the very beginning the execution of the kernel -like the function memSet for cuda pointers.
If not, is it better to ask a thread to initialize the shared memory at the beginning of the kernel and then making a __syncthreads() or to ask each thread to initialize ?

Make as many threads as necessary initialize the smem and sync if needed. This is the normal way to go. Im not aware of a function to init like you said but because smem is allocated and initialized block wise you would need to call it from inside your kernel neitherway. The way it is you can init whenever you want and oc also at the very beginning so Im not quite sure how such a function could aid you.

typical ex

shared float smem_block[block_dim_x];

smem_block[threadIdx.x] = src[threadIdx.x + blockIdx.x*block_dim_x];


Thanks for the replys.
I’m actually filling my shared memory like you both said. In fact, I am trying to optimize my cuda code and I wondered if there was a simple way to get rid of my __syncthreads() which comes with the initialisation of the shared memory.