[Bug]: SM100 weight-only GEMM: no proxy fence between the transform warps' shared-memory reads and the TMA refill of the same stage

Aperta
#23,366 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
42/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp

Direzione di ricerca

Start with the transform loop in cpp/tensorrt_llm/cutlass_extensions/include/cutlass_extensions/gemm/collective/sm100_mma_warpspecialized_mixed_input.hpp, especially lines 974–981, and review the PTX proxy-fence requirements cited in the issue. Check generated SASS with cuobjdump to see whether transform-thread LDS results are first used after the stage-release arrive. Done means every transform thread's reads are ordered before the producer's TMA refill, with the stated B200 performance impact checked.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Customized kernels
System Info
  • Source: cpp/tensorrt_llm/cutlass_extensions/include/cutlass_extensions/gemm/collective/sm100_mma_warpspecialized_mixed_input.hpp at main 10e44bbf.
  • Binary: the 1.3.0rc26 wheel (tensorrt_llm-1.3.0rc26-cp312-cp312-manylinux_2_28_x86_64.whl). The affected kernels are in the cubins libth_common.2024–2027.sm_100.cubin inside tensorrt_llm/libs/libth_common.so, built by ptxas 13.2 (V13.2.78).
  • Measurements: B200, driver 595.58.03.
Who can help?

No response

Information
  • The official example scripts
  • My own modified scripts
Tasks
  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)
Reproduction

We found this by reading the source and the SASS of the shipped wheel. We have not reproduced a wrong result on hardware (see "actual behavior").

The problem is in the transform loop of CollectiveMmaSm100WeightOnly (lines 974–981):

  1. The 128 transform threads read A and the scales/zeros of stage s with ordinary shared-memory loads (lines 975 and 977).
  2. They sync on transform_bar (980). Then one elected thread releases s with consumer_release (981), which is an mbarrier arrive.
  3. The producer refills s with TMA for a later K tile.

The loads in step 1 go through the generic proxy, and TMA writes through the async proxy. There is no fence.proxy.async between them. The fence_view_async_shared() at line 996 comes after the release; it orders the writes of the dequantized A, not these reads.

The comment at line 979 says the loads are done. In SASS they are not: neither BAR.SYNC nor the arrive waits for outstanding LDS.

Below is the bf16 × int4 (scale only) kernel with a 64×128×64 tile, from libth_common.2027.sm_100.cubin, with unrelated instructions left out. The three loads are first used after the arrive:

/*05050*/ LDS.U16 R33, [R14+0x4908]
/*05080*/ LDS.U16 R32, [R30+0x31800]
/*050a0*/ LDS.U16 R30, [R30+0x31810]
/*050b0*/ BAR.SYNC.DEFER_BLOCKING 0x3, 0x80                      // transform_bar.sync()
          ... 9 PRMT/SHF instructions, none of which reads R30, R32 or R33 ...
/*05150*/ @!P3 SYNCS.ARRIVE.TRANS64.RED.A1T0 RZ, [R31+URZ], RZ   // consumer_release

The wheel has 22 instantiations of this collective, all with cluster 1×1×1. In 12 of them, loads of the stage are still in flight at the arrive:

Activation × weight, tile Loads in flight at the arrive
fp16 × int4/int8, 128×128 and 64×128 8 of 8
bf16 × int4/int8, 64×128 2 of 3 (in one, only in the other warps)
fp8 × int4 with zero points, 128×128 2 of 2
bf16 128×128 (3), fp8 128×128 without zero points (2), fp8 64×128 (4) 0 of 9

To check a build:

  1. Run cuobjdump -xelf all libth_common.so.
  2. In each CollectiveMmaSm100WeightOnly kernel, find the SYNCS.ARRIVE that follows BAR.SYNC 0x3, 0x80.
  3. See whether any earlier LDS result is first used after it.
Expected behavior

The TMA refill of a stage is ordered after every transform thread's reads of that stage.

PTX requires a proxy fence for this (PTX ISA 9.5, §8.6 "Proxies" and §9.7.10.28.2 "Async Proxy"). §9.7.10.28.2 states: "Accessing the same memory location across multiple proxies needs a cross-proxy fence." The mbarrier handoff alone does not provide that fence.

actual behavior

There is no fence. Under the PTX memory model, the refill may overwrite the stage before the reads complete. The transform would then dequantize data from a later K tile and report no error.

We have not seen this happen. On B200 we launched the wheel's own cubins through the driver API, filled D with NaN before each launch, and checked it against a float reference. Two of the kernels above (fp16 × int4 128×128 and bf16 × int4 64×128) ran 4.8×10¹¹ stage releases at M×N×K = 4096×5120×4096, with no wrong output. As a positive control, the same kernels with the loads moved after the release failed in 42% and 91% of launches.

Our explanation: these kernels fit only one CTA per SM (182–207 KB of shared memory). At that occupancy, 99.9% of refills took at least 261 ns after the release, which is longer than the loads take to finish.

A standalone litmus test with the same pattern (same-CTA arrive with loads in flight, no proxy fence, bulk-copy overwrite) does fail on B200 at 4 or more CTAs per SM: 239 stale reads in 7.9×10¹¹. With the fence it gives 0.

additional notes

Suggested fix: every transform thread calls fence_view_async_shared() before transform_bar.sync(). The barrier then orders all the fences before the single arrive. NVIDIA/cutlass#3974 uses the same placement for the SM120 blockwise-scaling mainloop.

             Utils::copy_scale_zeros_for_transform(partitioned_extra_info, load2transform_consumer_index);
 
-            // Loads from SMEM are done. Signal the mainloop load as early as possible
+            // Order this thread's reads of the stage before the producer's TMA refill
+            cutlass::arch::fence_view_async_shared();
             transform_bar.sync();
             load2transform_pipeline.consumer_release(curr_load2transform_pipeline_consumer_state);

Cost on B200 (bf16 × int4, group 64, 128×128×64 tile; GEMM time only):

M×N×K Change
4096×5120×4096 −0.2%
16×5120×4096 +0.9%
128×16384×16384 +0.4%

Whether a given build has loads in flight here depends on ptxas scheduling, not on the source. The bf16 × int4 128×128 instantiation is closed in the wheel, which was built with ptxas 13.2. The same PTX compiled with ptxas 13.3–13.5 is open. The other two instantiations we rebuilt changed in other ways between 13.2 and 13.5: one stayed open, and the other's window narrowed. A toolchain update can therefore open this window without any source change.

Upstream CUTLASS has the same loop in include/cutlass/gemm/collective/sm100_mma_warpspecialized_mixed_input.hpp. We will report it there and link the issue below.

Before submitting a new issue...
  • Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.
Lingua principale
Python
Stelle
15.2k
Fork
3k
Merge medio
2g 21h
PR unite (30g)
477

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NVIDIA/TensorRT-LLM

Tutte le issue di NVIDIA/TensorRT-LLM

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.