Repository navigation
Description
System Info
- CPU architecture: x86_64
- GPU: NVIDIA B200 (sm100a); expected on any SM100-class part running this kernel (the kernel also targets SM103)
- Libraries
- TensorRT-LLM branch: main (reproduced at 2e70be3 and current tip)
- nvidia-cutlass-dsl: 4.6.1 (the
requirements.txtpin); also reproduces on 4.7.0 and 4.8.0.dev0 — kernel bug, not a DSL toolchain issue - torch 2.13 + cu13
- CUDA: 13.3; driver 590.48.01
- OS: Ubuntu 22.04
Who can help?
Information
- The official example scripts
- My own modified scripts
Tasks
- An officially supported task in the
examplesfolder (such as GLUE/SQuAD, ...) - My own task or dataset (give details below)
Reproduction
Minimal direct-drive repro (indices-only GvrTopKKernel.launch, the same entry the production runner and the tier dispatcher's fallback use). Two input classes:
# CUDA_VISIBLE_DEVICES=<one B200>; python repro.py {zeros|ties}
import sys
import torch
from tensorrt_llm._torch.cute_dsl_kernels.blackwell.top_k.gvr_topk_decode import (
GvrTopKKernel,
)
mode = sys.argv[1] if len(sys.argv) > 1 else "zeros"
torch.cuda.set_device(0)
top_k = 1024 if mode == "zeros" else 512
if mode == "zeros":
# All-zeros pre_idx = the cold-start hint state (the GVR prior buffer
# starts zeroed; production fills it with the previous step's top-k
# only after the first real decode step).
num_rows, n = 4096, 4096
torch.manual_seed(7)
logits = torch.randn(num_rows, n, dtype=torch.float32, device="cuda") * 2.0
pre_idx = torch.zeros(num_rows, top_k, dtype=torch.int32, device="cuda")
else:
# Tie-heavy rows (quantized logits) + argmax-slot hint. Also reproduces
# with PERFECT previous-step hints: on tie-heavy rows the gathered hint
# values collide bitwise regardless of hint quality.
num_rows, n = 1024, 16384
torch.manual_seed(11)
logits = (torch.randn(num_rows, n, dtype=torch.float32, device="cuda") * 8.0).round() / 4.0
pre_idx = torch.zeros(num_rows, top_k, dtype=torch.int32, device="cuda")
pre_idx[:, 0] = logits.argmax(dim=-1).int()
seq_lens = torch.full((num_rows,), n, dtype=torch.int32, device="cuda")
ref = torch.topk(logits, top_k, dim=-1).values
for it in range(300):
out = torch.full((num_rows, top_k), -777777, dtype=torch.int32, device="cuda")
GvrTopKKernel.launch(logits, pre_idx, seq_lens, out, top_k, next_n=1, compress_ratio=1)
torch.cuda.synchronize() # "ties" mode: intermittent illegal memory access here
sent = int((out == -777777).sum())
oob = int(((out >= n) | ((out < 0) & (out != -1))).sum())
got = logits.gather(1, out.clamp(0, n - 1).long()).masked_fill(out < 0, float("-inf"))
bad = int((got.sort(-1, descending=True).values != ref).any(1).sum())
if sent or oob or bad:
print(f"iter {it}: unwritten_slots={sent} out_of_range={oob} bad_rows={bad}")Expected behavior
Exact (tie-aware) top-k for any in-contract pre_idx content — including the all-zeros cold start — with no crashes: correct index sets, no unwritten output slots, no out-of-range indices.
actual behavior
zerosmode (B200, 300-launch sweeps): wrong index sets, unwritten output slots (the poison sentinel survives), and out-of-range index values on most launches at this shape (up to ~187 corrupt slots per launch); occasionally an illegal memory access. Frequency grows with batch size (more resident CTAs).tiesmode:CUDA error: an illegal memory access was encounteredwithin ~10-200 launches, at every K in {512, 1024, 2048}; also reproduces with perfect previous-step hints.
additional notes
Root cause: a recurring shared-memory read-vs-rewrite race. In _run_phases, every thread reads the Phase-1 hint bracket s_thr[1]/s_thr[2]; when the bracket is degenerate (all gathered hint values bitwise-equal — exactly the all-zeros cold start, or tie-class collisions), tid0 rewrites those same slots with a synthetic bracket inside a conditional that contains a barrier. A straggler warp that reads the already-rewritten bracket evaluates the condition differently and skips the guarded barrier — barrier divergence, after which the CTA's phases run on torn state (wrong sets, unwritten slots, garbage indices, IMA).
compute-sanitizer --tool racecheck shows the WAR/RAW hazards at __shared__ addresses that resolve exactly to s_thr[1]/s_thr[2], with incoming values -1.0f/1.0f (the synthetic bracket constants). The same read-then-leader-rewrite pattern (racecheck-confirmed) recurs on the Phase-2 done flag in the refine/plateau-collapse loops and on the Phase-4 coarse bin-search publish (s_iscalars[2]/[3]).
Note the unit-test hint convention (argmax slot + junk arange) gathers the argmax column plus top_k - 1 distinct arange columns, whose randn values essentially never all collide into one tie class — which is why the existing sweeps could not see this.
Exposure: the CuTe DSL GVR path is the opt-in CUTE_DSL_GVR top-k configuration (default decode top-k is the C++ CUDA_RADIX path, unaffected). Under CUTE_DSL_GVR, this kernel is the tier dispatcher's fallback target and the measured fallback-band table routes real shape buckets to it.
A fix PR (one block barrier between the reads and each leader rewrite, plus regression tests) accompanies this issue.
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.
Activity
[#18338][fix] Fix barrier-divergence races in the Blackwell CuTe DSL …