Skip to content

The drain a deferred job owes is Job::finish, and thirteen entry points stop remembering it (#132) - #200

Merged
feitreim merged 3 commits into
mainfrom
fix/132-job-finish-hook
Aug 6, 2026
Merged

feitreim merged 3 commits into
mainfrom
fix/132-job-finish-hook

Conversation

@feitreim

@feitreim feitreim commented Aug 6, 2026 •

Copy link
Copy Markdown
Owner

Closes #132.

The hook

Job::finish(&mut self), empty default, called by run and run_stealing
after their item loops. A job that defers its last item's store had nowhere on
the trait to put the drain it owes, so both deferred jobs invented the same
thing — a pending: u32 with a u32::MAX sentinel and a finish() the entry
point
had to remember. gemm_ws has nine entry points, so it had nine chances
to forget, and forgetting is a whole output tile computed by nobody rather than
anything a type says something about.

It runs after the loop's last inval and before the caller's dealloc_*
— which is where every hand-rolled call already sat, immediately after
pipeline::run(...) returned and immediately before release. Both loops are
#[inline(always)] and so is finish, so nothing moves in any launch's
instruction stream; this is the same call from a place it cannot be dropped
from.

The call sites removed — thirteen, not ten

file entry point(s) what it called
experiments/src/gemm.rs gemm_cg2_lcsf job.finish() → Lcsf::finish
experiments/src/gemm_ws.rs gemm_ws, gemm_ws_clc, gemm_ws_s6, gemm_ws_staged, gemm_ws_staged_x8, gemm_ws_staged_x4, gemm_ws_staged_x8x4, gemm_ws_staged_no_drain, gemm_ws_no_drain job.finish() → Ws::finish
experiments/src/gemm.rs gemm_cg2_staged_x8x4_tma, gemm_cg2_staged_x8x4_tma_cta, gemm_cg2_staged_x8x4_tma_2g job.ring.drain() → StagedTma::finish / StagedTmaCta::finish

The last three are the StoreRing::drain obligation the issue names as having
the same shape; now that the hook exists there is no reason for them to be the
one kind of teardown still spelled at the launch site.

Acceptance: no GEMM entry point calls a finish of its own, and the
sentence in pipeline.rs about the drain a job owes points at Job::finish
rather than at the caller.

Scope item 1 — the warp-asynchronous item stream

Written down on the Job trait itself, per the issue's "do not leave it stated
only in gemm_ws.rs, which is being restructured": what cannot be expressed
(warp groups of one cluster sitting at different items), why it follows from the
item boundary being a whole-cluster rendezvous, that the way to admit one is a
second scaffold rather than a change to this one, and what the boundary it buys
costs — #90 and #94 put it at a fifth to a third of the launch. The paragraph in
gemm_ws.rs now points at it rather than being the only copy.

Gates

gate result
cargo test (library, host + doctests) 112 / 1 / 82 pass
cargo clippy --all-targets (library) clean
scripts/fmt --check clean
scripts/modal-run build pass — the only thing that typechecks experiments/, since cuda.h is not available locally
scripts/modal-run regcount pass — occupancy-step gate green, .local census still 1 of 12 shipped kernels
scripts/modal-run examples pass — gemm and gemm_ws element-exact at both check sizes, all three traversal widths, both schedulers, every epilogue rung including lcsf

The three TMA-store rungs are on no correctness gate (they are among the
entry points the tier-2 codegen is the only gate for), which is why the move
there was kept to relocating the identical call rather than changing it.

One correction to the issue's citations

The two files it names moved in #134: the jobs are experiments/src/gemm.rs and
experiments/src/gemm_ws.rs, not examples/. And the sentence it quotes —
"a job that defers its last item's store owes one drain after run returns,
which is a whole output tile computed by nobody if it is forgotten"
— is at
docs/library/pipeline.md:177-178, which is the line number the issue gives,
rather than in src/pipeline.rs. Both now point at the hook; the doc's stale
examples/src/gemm.rs path is fixed in the same paragraph.

…ints stop remembering it (#132)

A job that defers its last item's store owed one drain after the item loop, and
the trait provided nowhere to put it: both deferred jobs invented a `pending`
field with a `u32::MAX` sentinel and a `finish()` the *entry point* had to call.
`gemm_ws` has nine entry points and so had nine chances to forget it, and
forgetting it is a whole output tile computed by nobody.

`Job::finish` is that place — empty default, so it costs nothing for a job that
does not defer, and called by both `run` and `run_stealing` after their loops.
It runs after the loop's last `inval` and before the caller's `dealloc_*`, which
is exactly where all thirteen hand-rolled calls already sat, so no launch's
instruction stream moves.

The call sites removed: `gemm_cg2_lcsf`'s `job.finish()`, the nine in
`gemm_ws`, and the three `job.ring.drain()` the `StoreRing` entry points carried
— the same shape of obligation, named by #132 as such.

Also written down in `pipeline.rs`, where #132 asks for it: a
warp-asynchronous item stream is out of scope for this trait, why it is a
decision rather than an omission, and what the decision costs — #90 and #94 put
the item boundary it buys at a fifth to a third of the launch. That argument
lived only in `experiments/src/gemm_ws.rs`, which is being restructured.
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.

Job has no teardown hook, and nine entry points remember the drain by hand

1 participant