Skip to content

A wait on a device has a deadline, and an arm that wedges costs one row - #228

Merged
feitreim merged 16 commits into
mainfrom
watchdog
Aug 7, 2026
Merged

feitreim merged 16 commits into
mainfrom
watchdog

Conversation

@feitreim

@feitreim feitreim commented Aug 7, 2026 •

Copy link
Copy Markdown
Owner

A CUDA wait has no timeout, so a kernel that stops making progress stops the
host with it — and the only thing that ever ended one here was Modal's
timeout=, at B200 rates, for the whole of a ceiling sized for a cold build plus
a sweep. That is how bench --case sol-k was found (#146: 4096x4096x1024
printing nothing for 1200 s), and it is why #226 had to keep that case and
profile out of session --arms: an arm that can wedge takes every row
after it.

This is the deadline that removes the exclusion, plus the timeout audit that
should have accompanied it.

kittens::watchdog — the wait with a clock on it

cuEventQuery answers "has this retired" without blocking, so a wait can be a
loop the host controls. wait records an untimed event behind whatever is queued
on the stream and polls it; past 30 s it prints the row the sweep last announced
and calls abort().

Four decisions, argued in docs/library/watchdog.md:

  • Poll, spinning first. cuEventSynchronize spins under CU_CTX_SCHED_AUTO
    too, so for a launch of a normal length this is the same wait, not an
    addition to it. That is what lets the timed loop in examples/src/bench.rs use
    it: wait_event polls the stop event the clock already records, between
    stop.record and elapsed_ms reading a duration off that same pair. No event
    created, no allocation, the bracket around the launch untouched.
  • Fatal, and abort() not exit(). When it expires the launch is still
    running and the context will not release; a caller that recovered would be
    timing a device still busy with the launch it gave up on. exit runs the
    driver's atexit handler, which wants the wedged context. abort runs none,
    and the kernel dies when the OS reclaims the process. The isolation the design
    needs is a process boundary, which _run always had.
  • 30 s, not measured × 10. The slowest single launch in the tree is the
    16384³ GEMM at ~8 ms and ten times that would fire on a driver hiccup; a
    guarded wait also covers staging copies and the driver's lazy module load,
    which are seconds. So: three orders of magnitude above the work, two below the
    3600 s a wedge used to ride. KITTENS_LAUNCH_BUDGET_MS overrides, and a value
    that is not a positive number is the default rather than the absence of a
    deadline.
  • The label is the announcement. bench.rs::announce prints the row and
    hands the same string to watching, so sol::sweep_k's "the last announced
    row is the one that did not return" stops being something a reader does
    afterwards.

Coverage is the whole tree, and finding out what that meant took two runs.
Three of cuda-core's conveniences synchronize inside themselves —
DeviceBuffer::from_host, ::zeroed and ::to_host_vec — so an unguarded
readback taken after a launch is an unguarded wait, and so is an unguarded
staging call. wait replaces every stream.synchronize(), stage/cleared
replace the two constructors and ReadBack::read_back replaces the readback,
across src/, examples/, experiments/ and device-tests/. Nothing waits on
a device any other way.

The control, and what it cost to make it honest

modal_app.py::wedge_demo is to this what stall is to scripts/modal-run.
experiments/src/wedge.rs, behind an off-by-default wedge feature, queues a
kernel that spins for two minutes against a five-second budget immediately in
front of a row's own launch, on that row's own stream
— everything loaded, everything staged, then a launch
that will not finish. Three arms go through it and the pass condition is the
shape: arm 2 failed, arms 1 and 3 did not. A wedged arm that passed is a
watchdog that did nothing; a green arm that failed is a wedge that took a
neighbour, which is the thing this PR claims cannot happen. Both raise.

The demonstration passes. scripts/modal-run wedge_demo, exit 0:

  wedge: queued; the next wait on this stream is a wait on it

== kittens: the launch watchdog fired ==
  4096x4096x2048 on M256xN256
  did not complete within 5.0 s -- the row deadline of 5.0 s (KITTENS_ROW_BUDGET_MS = 5000 ms).
  the launch is still in flight, so this process ends here rather than reporting
  a device it gave up on.

=== session arm: bench:sol-k: FAILED (exit 1) ===

=== session arm: device-tests ===
...
=== session summary ===
  bench:softmax               ok                                          35.1s
  bench:sol-k                 FAILED (exit 1)                             35.0s
  device-tests                ok                                          75.4s

the wedged arm failed in 35.0 s and `device-tests` ran after it. that is the whole claim.

One row red, the rows after it green, the whole thing in one container. The
banner names the row rather than the exit code because the exit code cannot: the
abort happens in the kernel binary, cargo oxide run reports the signal as
Failed with exit code: None, and subprocess sees cargo's 1. That is measured
and now said where the summary is built.

wedge_demo itself exits 0 because its pass condition is the shape — arm 2
failed, arms 1 and 3 did not — and a wedged arm that passed would be a watchdog
that did nothing. A real session with a failed arm raises, and runs 5 and 6
below are the evidence that raising from these entry points reddens the run.

It took nine runs, and two of them changed the design

The story is in experiments/src/wedge.rs and docs/library/watchdog.md
because every one of them is a fact about this tree:

run change what it found
1 wedge at the top of bench::main host sat in DeviceBuffer::from_host — the staging constructors synchronize too; stage/cleared exist because of this
2 staging guarded stopped ahead of the first guarded wait, with kernels::load the only candidate
3 wedge moved in front of the row's own launch stalled with no way to localize it; the per-step wedge: markers were added
4 a *mut u64 for the spin to store into launch returned immediately
5 KITTENS_WATCHDOG_TRACE added watchdog: waited 0.000 s — the guard reports; the spin is absent
6 clock64 instead of globaltimer identical: a loop with no side effect may be assumed to terminate, and deleted
7 volatile load in the loop condition, PTX printed first .entry wedge, ld.volatile.global.b32, backward bra — the loop is in the PTX, and the host blocked for the spin's whole length. No deadline fired.
8 the same, timed 44 s of real silence against a 5 s budget, and the first trace after the device freed reads 0.000 s
9 the row deadline fires at 5.0 s

Runs 5–6 were the kernel: Semaphore::wait_before spins correctly on the same
nightly because its condition calls mbarrier_try_wait_parity, which touches
memory. A volatile load in the condition fixes it, and the PTX check now runs
before the arms so that is never again something a container discovers.

Runs 7–8 were the guard, and they are why this module has two deadlines.
wait bounds a driver call by recording an event behind it and polling that
event — so it cannot bound a call that never returns. With a spin kernel
resident, the row's own cuLaunchKernelEx blocks: the host sat inside the launch
for the spin's whole life and the guarded wait after it was never reached. No
amount of reasoning had produced that; a device did. So watching now also arms
a sentinel thread with a budget on the row — 10 min by default, coarse
because a row legitimately includes host work (the 16384³ rows check 268 million
outputs on the CPU), and unevadable because no driver call can hold a thread that
is not in the driver.

armed by budget bounds
the launch deadline wait / wait_event 30 s any wait that is reached
the row deadline watching, at the row announcement 600 s the row, wherever the main thread is

Neither subsumes the other, and the demonstration only passes because both exist.

sol-k and profile have arms

ARMS gains profile (as _profile_arm, so a session and the entry point issue
the same commands, ARMS' standing rule), and the exclusion note is gone.
bench:sol-k needed no new entry — bench:<case> already reached it — only the
policy to change.

What batching them is worth. bench:sol-k measured 106.2 s and 112.6 s
in two three-arm sessions, sitting behind another experiments/ arm. Run alone
it would additionally pay an image pull, a container start and a cold dependency
compile — the three things #226 decomposed a session's saving into, at 97 s over
two avoided containers on its own three-arm measurement, and 60-72 s of cargo
cold against 28.6 s warm behind a same-crate arm. So each sol-k invocation
that rides a session instead of its own container is worth roughly 50 GPU-seconds
of B200
, and the same again for profile, on top of the exclusion's real cost:
until now the answer to "take these two beside the others" was no.

session no longer throws the rest of the run away when an arm fails: _session
runs the arms after a failure, prints a summary with each arm's outcome and
elapsed, and the caller decides what a failure means (which is how wedge_demo
can require exactly one). The session is still red. The new rule is narrower and
worth keeping: an arm may fail, and may not take the container with it.

Timeouts, at ~3x a measured baseline

The convention oxide-train#131 wrote down for the twin repo, mirrored here: a
timeout is three times a measurement with the measurement in the comment beside
it, and an entry point whose work its arguments choose stays open-ended and
says so.

entry point measured timeout=
build 291.8 s warm, 470.8 s worst (#226) 900 3.1x warm
regcount 183-184 s (CI.md) 900 4.9x
upstream_ptx clean clone plus ptxas; unmeasured 900 rides CHECKING
device_tests 83.5 s (#226) 300 3.6x, down from 1200
examples two binaries, both gates; unmeasured 1200 open-ended
bench, session, the named sweeps the argument chooses the work 3600 open-ended
wedge_demo three arms, one killed in seconds 1200 open-ended
doctor one driver query 300 open-ended
stall a nap of a length its caller picks 300 a bound on its argument

device_tests is the one that moved: it shared RUNNING with examples at
fourteen times its own measurement. A ceiling is not a bill, so the only thing a
loose one costs is a wedge riding longer — which is also why they are no longer
the first line of defence.

Not planned, and the more important half: the cache volume was serving a stale build

The first build of this branch went red on a doctest in the new module —
against a libkittens.rlib that had no such module. cargo clippy --features host --all-targets had finished in 1.05 s having compiled nothing, and the
cargo test after it ran 127 unit tests: the count from before the two new
ones existed. With the volume emptied, the same tree built and ran 129.

clippy --features host unit tests it then ran
volume warm, before this PR 1.05 s, compiled nothing 127
volume emptied 13.5 s 129
volume warm, with _freshen 4.4 s 129

Cargo's freshness check for a path crate is mtime against the fingerprint, and
Modal's mounts do not hand the container mtimes newer than artifacts already on
the volume. Neither cargo nor the volume is wrong; the pairing is. The tell was
rustdoc, the one step that reads the sources unconditionally
— without a
doctest in the new module that run would have been green on a tree it had not
built.

_freshen touches every .rs, .toml and .lock under the project once per
container, before the first command. Measured on this tree, step time:

steps
volume empty (cold) 384.3 s
volume warm, _freshen 295.2 s

So the volume still buys 89 s a run and #226's headline survives — its saving
was in the dependency tree all along, exactly as it argued, and none of it lives
under PROJECT_DIR. What did not survive is the guarantee: any "identical
output" comparison taken across a warm volume before this fix was potentially
comparing two runs of the same artifacts.

Verification

  • scripts/modal-run build — green, 129 unit tests (127 before this PR, plus
    the two in watchdog) and 94 doctests. Run three times: warm-and-stale (red,
    the finding above), volume-emptied (green, 384.3 s of steps) and
    warm-with-_freshen (green, 295.2 s).
  • scripts/modal-run wedge_demo — green, the summary above. Nine runs in
    total; every guarded path ran clean throughout: bench:softmax's whole table,
    sol-k's 22-row ladder with its cuBLASLt column, device-tests 57/57.
    _session reported per-arm outcome and elapsed every time, and wedge_demo
    raised on the wrong shape in runs 5, 6 and 8 — which is both the check and the
    session's own red path doing their jobs.
  • scripts/modal-run regcount — green through _freshen, all four crates
    recompiled, occupancy-step gate green, and the jump-table finding above.
  • scripts/fmt --check clean; cargo clippy --all-targets on all four
    manifests shows the same 64 warnings as origin/main and no new categories,
    locally against the cuda_cudart redist.

One thing the stale-cache fix turned up, and it is not mine to close

regcount, run through _freshen so all four crates demonstrably recompiled in
the container, reports:

  jump tables — `brx` in the PTX text, per entry function.
    zero everywhere: none of the 319 entry functions carry one.
    That is the census this report arms into a gate on — see modal_app.py.

Zero. #227's codegen table records "jump-table census: identical set,
identical counts (+ the new probe)" across the change that merged as b589b8a, and
the in-tree day-one census records 55 of 318 at its parent. 319 is 318 plus
shared_drain_quad, so the entry set is the one that comparison was about —
only the counts differ, and they differ by all of them.

The direction is the intended one: #227 made both drains dispatch on
access_width_bytes with a wildcard, which is three cases, and LLVM branches at
three. So the fresh build says the fix removed every table in the tree rather
than none, and #227 concluded the opposite from a comparison taken across exactly
the warm-volume window _freshen was written for. That is a finding about the
measurement, not a defect in the fix — and it is the concrete instance of the
suspicion the stale-build section raises.

It also means the census's own arming condition is now met ("it arms into a
gate when the shipped set reads zero"). Deliberately not acted on here: one fresh
measurement of a report is not a gate, and arming one belongs with whoever
re-takes the before/after on two verified-fresh builds. The number and the
argument are written into modal_app.py's census comment so the next person
starts from them.

feitreim added 16 commits August 7, 2026 01:28
`kittens::watchdog` polls the event behind a launch instead of blocking on it,
so a kernel that stops making progress ends the process in 30 s naming the row
the sweep last announced. Every host wait in the three kernel crates goes
through it. `session` now runs the arms after a failed one and summarizes, so
`bench --case sol-k` and `profile` -- barred from `ARMS` because a hanging
launch takes every row after it -- have arms. `wedge_demo` is the control.

Timeouts are re-derived from measured baselines with the baseline in a comment;
`device_tests` moves 1200 -> 300 against its measured 83.5 s.
@feitreim
feitreim merged commit 09beda9 into main Aug 7, 2026
4 of 6 checks passed
feitreim added a commit that referenced this pull request Aug 7, 2026
…is a gate (#225) (#229)

* The jump tables were #219's after all, and the census that missed it is a gate (#225)

Three readings of `regcount`'s jump-table census, each from a build that
`_freshen` (#228) forced and whose four crates are seen to recompile in the
container log, same image and same pinned nightly:

    3ae07a8   #218, before the access ladder        0 of 309
    bda3329   after #219, before #227              55 of 318   (9 shipped)
    09beda9   main, after #227                      0 of 319

#219 introduced every `brx` in this tree and #227 removed every one of them,
which is the consumer's bisect exactly. #227 reported the opposite -- 51 already
present at 3ae07a8, identical counts across its own fix -- from a comparison
taken across the warm cache volume #228 later found serving stale builds. Both
numbers are superseded. 3ae07a8 has no `AccessWidth` to match on at all, so
zero is the only count that tree can produce.

Half of #225's "necessary but not sufficient" survives and half does not. No GPU
entry point mounts the cache volume (#226), so #227's B200 runs at then-main
really were runs of the 55-table tree and those modules really did load.
`shared_drain_quad` is the half that goes: it was added on the fix branch, after
the fix had put both drains back on a three-case dispatch, so it has never
carried a table and it is inside main's 0 of 319. Its doc said it demonstrated a
JIT taking four of them; it demonstrated nothing of the kind, and now says so.

So the census arms on the condition it set for itself. A kernel in the shipped
set -- `examples/` plus `GATED_KERNELS` -- carrying a `brx` fails the run;
probes are printed and do not, the way the local-memory depot's are. The table
stays as the diagnostic.

Watched in both directions: green at this branch (0 of 319) and red at bda3329's
sources under the same armed `modal_app.py`, naming the nine shipped kernels.

* The access ladder's note carries the in-tree numbers, not only the consumer's
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.

1 participant