Skip to content

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
NVIDIA:mainfrom
merrittttt:users/merrittttt/blockscaled-sf-refill-tcgen05-fence
Open

merrittttt wants to merge 1 commit into
NVIDIA:mainfrom
merrittttt:users/merrittttt/blockscaled-sf-refill-tcgen05-fence

Conversation

@merrittttt

Copy link
Copy Markdown

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 to fence_view_async_tmem_load/store:

CUTE_DEVICE static void fence_tcgen05_before_thread_sync() {
#if defined(CUTLASS_ARCH_TCGEN_ENABLED)
  asm volatile ("{\n\t" "tcgen05.fence::before_thread_sync; \n" "}" ::: "memory");
#else
  CUTLASS_NOT_IMPLEMENTED();
#endif
}

Motivation

sm100_blockscaled_mma_warpspecialized.hpp keeps one Tensor Memory buffer for the scale factors (thr_tCtSFA_s2t / thr_tCtSFB_s2t have no stage index). Each k-tile, the MMA thread does three things. It tcgen05.cps the stage's SFA/SFB into that buffer. It issues the k-tile's block-scaled tcgen05.mmas, which read them. Then consumer_release commits to free the smem stage. The next k-tile's tcgen05.cp overwrites 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.mma is one of them, so each k-tile's MMAs see the copy just before them. tcgen05.mma -> tcgen05.cp is 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 existing cp -> mma pipelining already relies on.

Changes

  • cutlass::arch::fence_tcgen05_before_thread_sync() in barrier.h.
  • Called before both scale-factor refills in sm100_blockscaled_mma_warpspecialized.hpp: the manually unrolled first iteration of the overlapping-accumulator path, and the main loop.
  • Not changed here: the other collectives that refill an unstaged TMEM scale-factor buffer the same way. From reading the code, those are the SM100 array, sparse, rcggemm and mixed TMA/cp.async block-scaled collectives, and the SM103 and SM107 ones. I can extend this PR to them if you agree with the approach. Double-buffering the TMEM scale factors by k-tile would be an alternative that needs no fence.

Performance

One tcgen05.fence::before_thread_sync per 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

  • With the same fence before the copies, Volta finds the MXFP8 GEMM it analyzed race-free on the tensor-operation ordering check. That GEMM is 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.
  • I re-ran Volta on this branch myself, building the MXFP8 GEMM with nvcc 12.9 for sm_100a (CUDA container, no GPU). Its tensor-operation ordering check now passes, and the whole graph verifies (with [BUG] SM100/SM90 TMA epilogue: every lane of the storing warp issues the same TMA store #3946's change). Built against unmodified include/, Volta reports the scale-factor conflicts. examples/72_blackwell_narrow_precision_gemm/72a_blackwell_nvfp4_bf16_gemm.cu also compiles against this branch, with the fence before both refill sites.
  • I have not run it on a GPU. Suggested check: the SM100 block-scaled GEMM unit tests (test/unit/gemm/device/sm100_blockscaled_tensorop_gemm/) and examples/72_blackwell_narrow_precision_gemm.

Dependencies

None.

Breaking Changes

None. Adds one device helper.

…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

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 block-scaled GEMM: the next k-tile's tcgen05.cp overwrites TMEM scale factors the previous MMAs may still read

1 participant