cuda - Why can't I use a single thread to initialize shared memory? -


this seems should simple, can't find references, i'm asking here.

i have following cuda kernel, launching in grid of 2-d thread blocks:

__global__ void kernel(){      if (threadidx.x == 0 && threadidx.y == 0) {         __shared__ int test = 100;     }     __syncthreads();      // more stuff } 

when try compile, error "initializer not allowed shared variable"

what doing wrong? seems me have 1 thread doing initializing...

thanks!

do instead:

__global__ void kernel(){     __shared__ int test;     if (threadidx.x == 0 && threadidx.y == 0) {         test = 100;     }     __syncthreads();      // more stuff } 

the declaration of __shared___ variable must separate code manipulates it.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -