Thread data sharing giving WAR hazard warning

0

The code snippit calcs a 3D vector magnitude: mag= sqrt(X*X + Y*Y + Z*Z)

// Note: blockDim.x = 300, gMem= ptr to global mem chunk
__shared__ sMem[100];
float regA;
for (j=0; j<50; j++) {
  if(threadIdx.x < 3) {
    regA= gMem[j];
    sMem[threadIdx.x]= regA*regA;  // Line A   write 5193
  }  
  __syncthreads();
  if(threadIdx.x == 0) {
    regA= sMem[0];                 // Line B   read 5197
    regA+= sMem[1];
    regA+= sMem[2];                // Line C   read 5199 
    sMem[0]= sqrt(regA);
  }
}

The syncthreads is preventing RAW hazards. W/o it, I get RAW & WAR hazard warnings. W/ it, I still get WAR warnings. The warning is coming from line pairs AB & AC.

 WARN:(Warp Level Programming) Potential WAR hazard detected at __shared__ 0x30b in block (0, 0, 0) :
     Read Thread (0, 0, 0) at 0x000000b0 in /src/trap.cu:5199:Mag(float const *, float const *, int, float*, int)
     Write Thread (2, 0, 0) at 0x00000080 in /src/trap.cu:5193:Mag(float const *, float const *, int, float*, int)
     Current Value : 64, Incoming Value : 66

 WARN:(Warp Level Programming) Potential WAR hazard detected at __shared__ 0x307 in block (0, 0, 0) :
     Read Thread (0, 0, 0) at 0x000000a8 in /src/trap.cu:5197::Mag(float const *, float const *, int, float*, int)
     Write Thread (1, 0, 0) at 0x00000080 in /src/trap.cu:5193::Mag(float const *, float const *, int, float*, int)
     Current Value : 67, Incoming Value : 66

Why doesn't the __synthreads(); prevent the WAR hazards?

cuda
asked on Stack Overflow Sep 27, 2013 by Doug

1 Answer

2

There is no intervening __synthreads() when the code executes lines 5197 and 5199 and then loops back to line 5193.

answered on Stack Overflow Sep 27, 2013 by njuffa

User contributions licensed under CC BY-SA 3.0