A read-after-write hazard occurs when one thread reads a shared-memory slot before another thread’s preceding write is complete. In a parallel reduction, one round writes results that the next round reads; without synchronization, a thread may read too soon. section 11.4
Use a block-wide __syncthreads() barrier to keep those accesses in order:
- Place a barrier after shared-memory writes that other threads will read, and between reduction rounds that read one another’s results. section 11.4
- Every thread in the block must reach the barrier. Skip it when accesses are thread-private or shared memory is no longer used. section 11.4
