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

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -