Skip to content

Elect one lane to issue the SM90/SM100 TMA epilogue stores, issue #3946 - #3950

Open
merrittttt wants to merge 1 commit into
NVIDIA:mainfrom
merrittttt:users/merrittttt/tma-epilogue-elect-one-store
Open

merrittttt wants to merge 1 commit into
NVIDIA:mainfrom
merrittttt:users/merrittttt/tma-epilogue-elect-one-store

Conversation

@merrittttt

Copy link
Copy Markdown

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:

-    // Predication for TMA store (one warp issues TMA store)
-    bool issue_tma_store = warp_idx == 0;
+    // Predication for TMA store (a single thread from one warp issues TMA store)
+    bool issue_tma_store = (warp_idx == 0) && cute::elect_one_sync();

Motivation

SM90_TMA_STORE issues one cp.async.bulk.tensor per calling thread, and issue_tma_store = warp_idx == 0 is 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 (both store overloads)
  • 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.hpp
  • sm100_epilogue_array_planar_complex_tma_warpspecialized.hpp

Every use of issue_tma_store guards per-thread operations: the D store, the fusion callbacks' aux TMA stores (Sm90AuxStore::tma_store), producer_commit (cp.async.bulk.commit_group) and producer_acquire (cp.async.bulk.wait_group.read). Each is followed by the existing named-barrier synchronize(), 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 executes elect_one_sync(), once per store call (warp 0 is converged there, as elect.sync requires), 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

  • With this change at the two sites in 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.
  • I re-ran Volta on this branch myself, building the units with nvcc 12.9 for sm_100a (CUDA container, no GPU). gemm_bf16_tn_128x128, gemm_bf16_tn_clc and conv2d_fprop_f16 are 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 unmodified include/, all four report the write-write conflict on D between two lanes' TMA stores.
  • The SM90, array (: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) against main and against this branch, and the change appears in the generated PTX. The planar-complex tests don't build on main as they stand (missing includes in collective_epilogue.hpp and a missing testbed), so I compiled their kernels directly.
  • I have not run it on a GPU. Suggested check: the SM90/SM100 GEMM unit tests (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.

…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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] SM100/SM90 TMA epilogue: every lane of the storing warp issues the same TMA store

1 participant