Repository navigation
Order the previous k-tile's MMAs before the SM100 block-scaled scale-factor refill, issue #3947 - #3951
Open
merrittttt wants to merge 1 commit into
Conversation
…factor refill, issue NVIDIA#3947 The SM100 block-scaled mainloop keeps one Tensor Memory buffer for the scale factors. Each k-tile the MMA thread copies the stage's SFA/SFB into it with tcgen05.cp and then issues the MMAs that read them; the next k-tile's tcgen05.cp overwrites the same cells with nothing ordering it after those MMAs. PTX ISA 9.7.16.6.2 lets asynchronous tcgen05 operations execute out of issue order except for listed pairs, which include tcgen05.cp -> tcgen05.mma but not tcgen05.mma -> tcgen05.cp. Add cutlass::arch::fence_tcgen05_before_thread_sync() (tcgen05.fence::before_thread_sync, 9.7.16.6.3: a prior asynchronous tcgen05 operation is ordered before all subsequent tcgen05 operations) and issue it before each refill.
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 #3947. The bug was found with Volta, a verifier that symbolically executes a kernel's compiled PTX and checks Tensor Memory accesses against the PTX ISA's tcgen05 ordering rules (details in the issue). This is latent: it can only go wrong if the tensor pipe runs one thread's tcgen05 operations out of issue order, which the ISA allows but current hardware may never do.
Summary
if (cute::elect_one_sync()) { + // The scale factors' Tensor Memory is not staged: order the previous k-tile's MMAs, which read it, before + // the copies that overwrite it (tcgen05.mma -> tcgen05.cp is not a pipelined pair in the PTX ISA). + cutlass::arch::fence_tcgen05_before_thread_sync(); copy(tiled_copy_s2t_SFA, thr_tCsSFA_s2t(_,_,_,_,read_stage), thr_tCtSFA_s2t); copy(tiled_copy_s2t_SFB, thr_tCsSFB_s2t(_,_,_,_,read_stage), thr_tCtSFB_s2t); }plus the new helper in
cutlass/arch/barrier.h, next tofence_view_async_tmem_load/store:Motivation
sm100_blockscaled_mma_warpspecialized.hppkeeps one Tensor Memory buffer for the scale factors (thr_tCtSFA_s2t/thr_tCtSFB_s2thave no stage index). Each k-tile, the MMA thread does three things. Ittcgen05.cps the stage's SFA/SFB into that buffer. It issues the k-tile's block-scaledtcgen05.mmas, which read them. Thenconsumer_releasecommits to free the smem stage. The next k-tile'stcgen05.cpoverwrites the same cells with nothing ordering it after the earlier MMAs.PTX ISA 9.7.16.6.2: "The asynchronous tcgen05 operations may execute and complete in a different order than they were issued", except for five listed pipelined pairs.
tcgen05.cp -> tcgen05.mmais one of them, so each k-tile's MMAs see the copy just before them.tcgen05.mma -> tcgen05.cpis not. The commit only signals the smem stage's empty barrier, and the MMA thread does not wait on it before the next copy. So per the ISA, a refill may overwrite scale factors that the previous k-tile's MMAs are still reading.9.7.16.6.3: "An asynchronous tcgen05 operation prior to a tcgen05.fence::before_thread_sync is ordered before all subsequent tcgen05 and the execution ordering operations." One fence before each refill therefore orders every earlier MMA before it. The fence is issued by the same elected lane that issues the copies and, through the UMMA atom's own
elect_one_sync, the MMAs. This is the same-lane assumption the existingcp -> mmapipelining already relies on.Changes
cutlass::arch::fence_tcgen05_before_thread_sync()inbarrier.h.sm100_blockscaled_mma_warpspecialized.hpp: the manually unrolled first iteration of the overlapping-accumulator path, and the main loop.Performance
One
tcgen05.fence::before_thread_syncper k-tile in the MMA warp's elected lane. If the hardware already runs these in order, it should cost close to nothing, but I have not measured it.Testing
mx_float8_t<float_e4m3_t>A/B, bf16 D, 128x128x128 tile,KernelTmaWarpSpecialized1SmMxf8f6f4Sm100, M = 256, N = 128, K = 256, on one persistent CTA. That run also had [BUG] SM100/SM90 TMA epilogue: every lane of the storing warp issues the same TMA store #3946's epilogue change. Without the fence, Volta reports 12 write-write conflicts between consecutive copies and 768 read-write conflicts between a k-tile's MMAs and the next copies, all on the scale-factor columns.include/, Volta reports the scale-factor conflicts.examples/72_blackwell_narrow_precision_gemm/72a_blackwell_nvfp4_bf16_gemm.cualso compiles against this branch, with the fence before both refill sites.test/unit/gemm/device/sm100_blockscaled_tensorop_gemm/) andexamples/72_blackwell_narrow_precision_gemm.Dependencies
None.
Breaking Changes
None. Adds one device helper.