Cuda 提供战争危险警告的线程数据共享

Cuda 提供战争危险警告的线程数据共享,cuda,Cuda,代码snippit计算3D矢量幅值:mag=sqrt(X*X+Y*Y+Z*Z) 为什么\uuuu synthreads()防止战争危险?当代码执行第5197行和第5199行,然后循环回第5193行时,没有干预性的合成读取()。当代码执行第5197行和第5199行,然后循环回第5193行时,没有干预性的合成读取()。是的,这就是问题所在。我忽略了5197行执行B4行5193的事实。(操作员头部间隙错误)@njuffa如果您将其作为答案发布,我将对此进行投票。 // Note: blockDim.x

代码snippit计算3D矢量幅值:mag=sqrt(X*X+Y*Y+Z*Z)


为什么\uuuu synthreads()防止战争危险?

当代码执行第5197行和第5199行,然后循环回第5193行时,没有干预性的合成读取()。

当代码执行第5197行和第5199行,然后循环回第5193行时,没有干预性的合成读取()。是的,这就是问题所在。我忽略了5197行执行B4行5193的事实。(操作员头部间隙错误)@njuffa如果您将其作为答案发布,我将对此进行投票。
// 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);
  }
}
 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