Repository navigation
Description
src/tmem.rs has no relinquish anywhere. alloc_block calls tcgen05_alloc
and dealloc_block calls tcgen05_dealloc, and neither issues
tcgen05_relinquish_alloc_permit, which cuda-oxide does expose
(generated/tcgen05.rs:2495, plus the _cg2 form at 2503).
A CTA that exits still holding its allocation permit leaves the SM's
allocator short, and the next CTA scheduled there waits in tcgen05.alloc for
columns that are never coming back.
This is not theoretical — the identical bug was just found and fixed in the GEMM example
examples/src/gemm.rs had the same omission (plus issuing the cta_group::2
allocator instructions from rank 0 alone). #40 found it by being the first
thing that ever launched a kernel twice in one process. The first launch was
always fine; the second hung forever. Confirmed on a B200 twice, and adding the
relinquish alone was necessary but not sufficient there — the participation
had to be fixed too.
The library's cta_group::1 path has the relinquish half of that same defect.
Why every existing test misses it
Every device case and both example runs launch each kernel once, with a grid
that fits in one wave. A permit leaked at exit is invisible when nothing is
scheduled behind you. modal_app.py::examples cannot see this: one launch is a
strictly weaker claim than two.
So the bug is latent for exactly as long as nobody writes a persistent kernel or
a grid larger than the GPU — which is to say, until the first realistic
workload. #15's persistent scaffold and any benchmark loop both trip it.
What to do
- Issue
tcgen05_relinquish_alloc_permiton thecta_group::1path, from the
warp that allocated, once it will not allocate again. - Get the placement right relative to
dealloc_block— relinquishing the
permit and deallocating are different operations and the ordering
matters. Read the intrinsic docs rather than inferring from the GEMM fix,
whose_cg2path has different participation rules ("one full warp in each
peer CTA"). - Add a device case that launches a kernel twice, or with a grid exceeding
one wave. Without it this class of bug stays invisible to the harness — and
it is a whole class, not one instance: the same "fine once, broken twice"
shape applies to any resource acquired at entry and released at exit. - Lift
alloc_clusterout ofexamples/src/gemm.rsintotmem.rswhile here —
it is now a correct, hardware-verified reference implementation of the_cg2
path, and it is Cluster scope: the library is CTA-scoped, and the GEMM works around it four ways #24 item 5. Keeping a fixed version in an example while the
library keeps the bug is the worst of both.
Related: #24 (cluster scope), #15 (persistent scaffold — the first consumer that
would trip this), #40 (found it).
Activity
TMEM: relinquish the allocation permit, and lift alloc_cluster into t…
feitreim commentedon Jul 28, 2026
Correction: the premise in this issue was wrong
I filed this predicting a deadlock — the next CTA on the SM stuck in
tcgen05.allocbehind an unrelinquished permit. That does not happen on a B200 forcta_group::1, and the agent measured it rather than taking my word:alloc_block, one with a local copy minus the relinquish, each holding an allocation 5 ms across 296 blocks. If a held permit blocked a co-resident CTA's alloc, the leaked variant would serialize at ~2x. Result:relinquished 20.29/20.14 msvsleaked 20.14/20.15 ms.alloc: 7 / relinquish: 7 / dealloc: 7.So what shipped is conformance — PTX requires the permit back before CTA exit and doesn't define what happens otherwise; the hardware evidently reclaims it anyway. It is worth having, but nobody should read this as a fixed deadlock.
Where #40's hang actually came from: the other half of the same defect.
gemm_cg2issued all threecta_group::2allocator instructions from rank 0 alone, so the pair's dealloc returned only half the columns — and leaked columns genuinely don't come back. That is also why adding relinquish alone would not have fixed the GEMM. The participation rule (one full warp in each peer CTA, each reading its own staging word) is now intmem::alloc_cluster/dealloc_cluster.The device case is a guard, not a reproduction, and its doc says so:
relaunch_probe(296 blocks x 3 launches, each CTA taking all 512 columns) cannot fail without the relinquish. It earns its place as the harness's only "fine once, broken twice" case — every other case launches once over a single wave, which by construction cannot see a resource acquired at CTA entry and leaked at exit. TMEM is just the first resource with that shape.Also added:
finish_or_abort, a polled CUDA event with a 30 s deadline, so a launch that never returns is a reportedFAILinstead of a container sitting until its timeout.