Fix data race between two writes on a shared memory in soft_max_autoregressive_backward_kernel - #847
Open
ziqiaozhou wants to merge 1 commit into
Open
Fix data race between two writes on a shared memory in soft_max_autoregressive_backward_kernel#847ziqiaozhou wants to merge 1 commit into
ziqiaozhou wants to merge 1 commit into
Conversation
…ax_autoregressive_backward_kernel There are three locations in softmax_autoregressive_backward_kernel to access block_acc: 1. write to init; 2. write local sum per warp; 3. read local sum per block. The first write is indexed by thread id inside warp 0, the second and future writes are indexed by wrap id. In theory, if warp 1 starts before warp 0, warp 0 may set that element to zero between the warp-wide local sum write and the block-wide sum read. Thus, it may cause wrong result due to data race.
ziqiaozhou
marked this pull request as ready for review
April 22, 2026 20:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…ax_autoregressive_backward_kernel
There are three access sites to block_acc in softmax_autoregressive_backward_kernel:
A. Initialization write
B. Per-warp local sum write
C. Block-wide read of accumulated values
The indexing differs across these accesses. The initialization (A) is performed by threads in warp 0 and indexed by the thread’s lane ID. The per-warp writes (B) are indexed by the warp ID, while the read (C) is indexed again by thread ID.
Although there is a synchronization barrier between (B) and (C), there is no synchronization between (A) and (B). As a result, the relative ordering between initialization and per-warp writes is not guaranteed.
In particular, if warp 1 executes its write (B) before warp 0 completes initialization (A), warp 0 may overwrite a previously written local sum with zero. This creates a data race, and the subsequent block-wide read (C) may observe incorrect values.
Thus, it may cause wrong result due to data race.