Repository navigation
Elect one lane to issue the SM90/SM100 TMA epilogue stores, issue #3946 - #3950
Open
merrittttt wants to merge 1 commit into
Open
merrittttt wants to merge 1 commit into
merrittttt wants to merge 1 commit into
Conversation
…DIA#3946 The TMA store predicate selected the whole storing warp (`warp_idx == 0`), and SM90_TMA_STORE emits one cp.async.bulk.tensor per calling thread, so each of the warp's 32 lanes stored the same smem subtile to the same global box and committed and waited on its own bulk group. The values are equal, so D was correct, but this is a formal write-write race between unordered async-proxy stores and 32 TMA stores per subtile where one suffices. Elect a single lane, as the SM90 and SM100 array epilogues already do: `issue_tma_store = (warp_idx == 0) && cute::elect_one_sync()`. The commits and waits stay with that lane, and the existing named-barrier synchronize() still orders the other epilogue threads after them.
This branch has not been deployed
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.
Fixes #3946. The bug was found with Volta, a verifier that symbolically executes a kernel's compiled PTX and checks it for races (details in the issue).
Summary
The TMA epilogues' store predicate now selects a single lane of the storing warp instead of the whole warp:
Motivation
SM90_TMA_STOREissues onecp.async.bulk.tensorper calling thread, andissue_tma_store = warp_idx == 0is true on all 32 lanes of the warp. So each lane stores the same shared-memory subtile to the same global box, and commits and waits on its own bulk group. In the compiled sm_100a PTX the store's guard is(tid & 96) != 0, which is false for every thread of the first epilogue warp, so all 32 issue the store. D is correct, since the stores write equal bytes. But these are 32 unordered async-proxy writes to the same global memory (a formal write-write race), and 32 TMA store operations per subtile where one suffices. The SM90 and SM100 array epilogues already elect one lane with exactly this predicate (sm90_epilogue_array_tma_warpspecialized.hpp:832,sm100_epilogue_array_tma_warpspecialized.hpp:808).Changes
The same one-line predicate change at every warp-wide site:
sm100_epilogue_tma_warpspecialized.hpp(bothstoreoverloads)sm90_epilogue_tma_warpspecialized.hpp(((thread_idx / NumThreadsPerWarp) == 0) && cute::elect_one_sync())sm100_epilogue_array_tma_warpspecialized.hpp(the second store path,:1175)sm100_epilogue_planar_complex_tma_warpspecialized.hppsm100_epilogue_array_planar_complex_tma_warpspecialized.hppEvery use of
issue_tma_storeguards per-thread operations: the D store, the fusion callbacks' aux TMA stores (Sm90AuxStore::tma_store),producer_commit(cp.async.bulk.commit_group) andproducer_acquire(cp.async.bulk.wait_group.read). Each is followed by the existing named-barriersynchronize(), so the other epilogue threads are still ordered after the elected lane's wait before they reuse the smem buffer. This is the same structure the array epilogue's first path already uses. Because of the&&, only warp 0 executeselect_one_sync(), once perstorecall (warp 0 is converged there, aselect.syncrequires), and the result is reused.Performance
31 fewer TMA store instructions, bulk-group commits and waits per epilogue subtile. Whether the TMA unit already merged the duplicate stores is undocumented. I have not measured the effect on hardware.
Testing
sm100_epilogue_tma_warpspecialized.hpp, Volta finds 22 SM100 units race-free (bf16/f16/e4m3/tf32; TN/NN/NT; 128x128, 128x256, 64x128 tiles; 2-stage; batched; static persistent and CLC schedulers; ReLU/SiLU/GELU/bias/beta epilogues; conv2d fprop). 18 of them are also proved equal to their GEMM spec. GELU, blockwise e4m3 and MXFP8 have no spec, and SiLU's proof stays undecided. Without the change, all 22 report the write-write conflict on D.gemm_bf16_tn_128x128,gemm_bf16_tn_clcandconv2d_fprop_f16are race-free and proved equal to their specs (32,768, 16,384 and 16,384 outputs), and the MXFP8 block-scaled GEMM is race-free (with [BUG] SM100 block-scaled GEMM: the next k-tile's tcgen05.cp overwrites TMEM scale factors the previous MMAs may still read #3947's change too). Built against unmodifiedinclude/, all four report the write-write conflict on D between two lanes' TMA stores.:1175) and planar-complex sites were changed by reading the code; Volta did not check them. For each, I compiled an existing user (the SM90 cooperative GEMM unit test, example 81, and the two SM100 planar-complex unit tests) againstmainand against this branch, and the change appears in the generated PTX. The planar-complex tests don't build onmainas they stand (missing includes incollective_epilogue.hppand a missing testbed), so I compiled their kernels directly.test/unit/gemm/device/sm100_*,sm90_*with TMA epilogues) and the planar-complex tests.Dependencies
None. The SM100 dense sites are the ones verified with Volta; the SM90, array and planar-complex sites apply the same change by reading the code. Happy to split those into a separate PR if you'd rather stage it.
Breaking Changes
None.