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

未关闭
#23,366 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.
主要语言
Python
星标
15.2k
派生
3k
平均合并
2 天 21 小时
30 天内合并 PR
477

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

NVIDIA/TensorRT-LLM 的其他 Issue

查看 NVIDIA/TensorRT-LLM 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。