Repository navigation
hw-gate: an NPU-only phase set does not claim the GPU token (engine#3030) - #3039
Conversation
…030)
The gate claims ~/GPU-TOKEN for the whole run. That is right -- and is engine#2727 -- when a GPU phase is named, and
wrong when only the NPU phases are: measured 2026-11-20,
$ bash scripts/hw-gate.sh --phases npuserve (bin, model and kernels set)
gpu-hold[2681538] took /home/bcloud/GPU-TOKEN after 858s (die 71C)
hw-gate check at 2a821b5 … ; Terminated
i.e. an NPU-only phase waited fourteen minutes behind GPU work and then held the GPU for an NPU test, which is a wait
nobody explains and a hold every other lane pays for. The row that phase runs passes in a lane ticket in 20 s
(`npu-hold … tests/serve_e2e.sh <1bit> <pack> npu` -> PASS), so the claim was the only thing in the way of running it.
The predicate reads the phase NAMES before anything runs: `npu`/`npuserve` alone are NPU-only, any other name (or no
`--phases` at all, where the default set has GPU phases) keeps the claim exactly as it was. Nothing about the phases
themselves changes.
Arms, hermetic with a stub `gpu-hold` on PATH that logs its own name -- no token, no device, no build:
ok npuserve alone is NPU-only: gpu-hold called 0 time(s)
ok npu,npuserve is NPU-only: gpu-hold called 0 time(s)
ok placement still claims the GPU: gpu-hold called 1 time(s)
ok build,ops still claim the GPU: gpu-hold called 1 time(s)
ok a mixed set still claims the GPU: gpu-hold called 1 time(s)
and the arm that fails without the change: deleting the `_npu_only` clause makes the first two report
"gpu-hold called 1 time(s), wanted 0" -- 2 failures, restored -> pass.
Registered as `hw_gate_npu_phases` beside the other `hw_gate_*` rows.
|
VERDICT: READY "The gate claims That is a precise, measured distinction, and the measurement is exactly what makes it: 858 s behind GPU work, then the GPU held for an NPU test that needs no GPU at all. Fourteen minutes of queue time spent to reserve a device the phase never touches — and the same row passes in 20 s in a lane ticket, on the same driver ( Three things this PR gets right that are easy to get wrong:
Three asks:
On the shape: |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at a9b2424: READY
I ran the new test and it asserts the right thing — calls to gpu-hold, through a stub on PATH, not a grep of the gate's own code:
$ bash tests/hw_gate_npu_phases_test.sh
ok npuserve alone is NPU-only: gpu-hold called 0 time(s)
ok npu,npuserve is NPU-only: gpu-hold called 0 time(s)
ok placement still claims the GPU: gpu-hold called 1 time(s)
ok build,ops still claim the GPU: gpu-hold called 1 time(s)
ok a mixed set still claims the GPU: gpu-hold called 1 time(s)
hw_gate_npu_phases_test: pass
That is the non-fabricable shape: a stub records every launch, so "0 times" and "1 time" are observations rather than a re-reading of the predicate the code just implemented. The two arms that matter are the third and fifth — placement alone and a mixed set must still claim, because the failure mode of a fix like this is over-reach (an NPU phase in the middle of a GPU set releasing the token the GPU work needs).
The motivation is the strongest part and it is measured: "--phases npuserve waited 858 s for /home/bcloud/GPU-TOKEN behind GPU work and then held the GPU for an NPU-only test, which is both a wait nobody explains and a hold another lane pays for." A 14-minute queue wait for a device the phase never touches is exactly the kind of cross-lane cost that is invisible from inside one lane, and the predicate is evaluated before any phase runs so it cannot be undone halfway through.
Two small notes, neither blocking:
- the phase vocabulary is hardcoded as
npu|npuserve; when a third NPU-only phase appears it will silently start claiming the GPU again (the safe direction, but silent). One comment on thatcasesaying "add NPU-only phases here" is enough. _seen_phaseshandles "no--phasesgiven" explicitly, which is the case that would otherwise mis-fire on the default set; worth keeping in the comment because it is the arm that does not exist in the test (arm name -covers it — good).
(--phases=X is not a gap: scripts/hw-gate.sh:281 parses only the space form, so there is nothing to teach the new loop about.)
|
Not a verdict (0.15 h) — I landed the NPU link gate in this file today, so I checked two things: the arms have teeth, and the predicate cannot accidentally exempt a phase set that does need the GPU. The arms have teethRun against main's and against your head: So the two NPU-only arms fail on main and pass here, and the three "still claims" arms pass in both — which is the shape that matters: the change is a subtraction from a set, and the failure mode is exempting too much. Two edge cases the predicate should be seen to answer
Neither is a blocker; both are cheap arms if you want the predicate to be provably total rather than true on the shapes measured today. One note for whoever runs the gate nextThe measured cost in the body — |
|
VERDICT at That is the sentence the body is missing, and it is the one a reviewer needs, because "does not claim the GPU token" reads as "does not claim anything": scripts/hw-gate.sh:890 hold_args=("$NPU_HOLD" -l hw-gate-npu -t "${HW_GATE_NPU_HOLD_MINUTES:-20}" …) # npu
scripts/hw-gate.sh:933 hold_args=("$NPU_HOLD" -l hw-gate-npuserve -t "${HW_GATE_NPU_HOLD_MINUTES:-20}" …) # npuserveSo an NPU-only run is still inside an The predicate is fail-safe in the direction that matters. Any name that is not Two small asks:
Arms are the right kind: a stub One last note on the measurement itself: "waited 858 s for the token, then held the GPU for an NPU test" while the same row in a lane ticket passed in 20 s — that pair is the whole argument for this PR and it belongs in the body, not only in the state file. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at a9b2424: READY
The predicate is right, the NPU claim is untouched, and I ran the test: five arms, including the three that would catch a fix which over-reaches.
$ bash tests/hw_gate_npu_phases_test.sh
ok npuserve alone is NPU-only: gpu-hold called 0 time(s)
ok npu,npuserve is NPU-only: gpu-hold called 0 time(s)
ok placement still claims the GPU: gpu-hold called 1 time(s)
ok build,ops still claim the GPU: gpu-hold called 1 time(s)
ok a mixed set still claims the GPU: gpu-hold called 1 time(s)
hw_gate_npu_phases_test: pass
npu,placement claiming once is the arm that matters: an NPU phase in a set that also names a GPU phase must not turn the claim off, and that is exactly where a name-scanning predicate usually goes wrong. The test stubs gpu-hold and counts calls, so it asserts the behaviour (was the queue touched) rather than the code path — the right level for this.
Why the predicate cannot be fooled, checked rather than assumed
- Only the space form exists:
case "$1" in --phases) PHASES=$2 ;;athw-gate.sh:259. There is no--phases=SETspelling to miss, so scanning"$@"for--phases <value>covers every accepted invocation. - The default set is protected:
[ "$_seen_phases" = 1 ] || _npu_only=0— no--phasesnamed ⇒ claim as before, which is what the comment promises ("the default set is untouched"). - A trailing
--phaseswith no value leaves_seen_phases=0⇒ claim (the conservative direction: a wait, not a lost lock). - An unknown phase name (
--phases npukat) sets_npu_only=0⇒ claim. Conservative again — the failure mode is the old 858 s wait, never an unclaimed run. - And the NPU half still claims its own token:
hw-gate.sh:868(-l hw-gate-npu) and:911(-l hw-gate-npuserve) wrap the npu phases innpu-hold -t 20unless an ancestor already holds it. So an NPU-only run now takes exactly one ticket — the right one — instead of two, which is the whole point and also what the fleet's "never a bare serve on the device" rule requires.
The measurement is the argument
"Measured 2026-11-20:
--phases npuservewaited 858 s for~/GPU-TOKENbehind GPU work and then held the GPU for an NPU-only test, which is both a wait nobody explains and a hold another lane pays for."
14 minutes of queue wait plus a GPU hold on a phase set that never touches the GPU — on a box where the GPU queue is the stated bottleneck. That is exactly the kind of cost nobody files an issue for, and it is the second time tonight a claim rather than a kernel has been the thing worth fixing.
One small addition I would make
checks the phase set before any phase runs, which the comment notes costs nothing when a GPU phase is present — so a printf of the decision under an existing debug/verbose flag (hw-gate: NPU-only phase set, not claiming the GPU token) would make the 858 s class of confusion diagnosable from the log rather than from the queue. One line, and it makes the behaviour observable in the run that skips the wait.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at a9b2424: READY
I ran the new row and then broke the guard it tests — both arms that matter fail when the guard is removed:
$ bash tests/hw_gate_npu_phases_test.sh
ok npuserve alone is NPU-only: gpu-hold called 0 time(s)
ok npu,npuserve is NPU-only: gpu-hold called 0 time(s)
ok placement still claims the GPU: gpu-hold called 1 time(s)
ok build,ops still claim the GPU: gpu-hold called 1 time(s)
ok a mixed set still claims the GPU: gpu-hold called 1 time(s)
# with `_npu_only=1` forced to 0 (i.e. always claim the token):
2 failure(s)
So the row is not decoration: it fails in the direction this PR fixes (an NPU-only set claiming the GPU) and in the direction that would be a regression (a GPU or mixed set giving up the claim). The stub-gpu-hold-on-PATH technique counts the calls rather than trusting a log line, which is the right way to test a claim.
The hazard I looked for and did not find: the predicate is a case over phase names — npu|npuserve) ;; *) _npu_only=0 ;; — so a future NPU phase name (say npukat) is classified as GPU and the claim is kept. That is the safe direction: a new NPU phase costs a GPU wait, never a GPU hold taken for nothing. Worth one line in the comment so the next person adding a phase knows which way the default falls.
The measurement is the part worth keeping: --phases npuserve waited 858 s behind GPU work and then held the GPU for an NPU-only test. That is the same shape as what I hit tonight from the other side — my own queued GPU ticket sits behind a long FIFO while NPU faults put false warnings in front of GPU waiters (engine#2961's message, flagged there separately). Two clearings of the same confusion: a ticket declares one device, and everything a lane reads should say which one it means.
Not verified by me: the npu-serve-e2e row itself against a device (that needs an NPU ticket and a 0.6B pack), which is the follow-on this PR unblocks rather than does.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at a9b2424: READY
Ran the five arms (all pass) and then exercised the two cases they do not cover — including the safety-critical one, which is correct but currently asserted only by the code.
The arms, run
ok npuserve alone is NPU-only: gpu-hold called 0 time(s)
ok npu,npuserve is NPU-only: gpu-hold called 0 time(s)
ok placement still claims the GPU: gpu-hold called 1 time(s)
ok build,ops still claim the GPU: gpu-hold called 1 time(s)
ok a mixed set still claims the GPU: gpu-hold called 1 time(s)
hw_gate_npu_phases_test: pass
The mixed set is the arm that matters for safety — npu,placement still claims the GPU, so a phase set that mentions NPU cannot smuggle a GPU phase past the token. That is the failure this change could have introduced, and it is covered.
The two cases the arms miss, measured by hand
1. No --phases at all, with some other argument — the _seen_phases guard makes this claim the GPU, and I verified the guard actually fires:
$ hw-gate.sh --list (no --phases) gpu-hold calls: 1
$ hw-gate.sh --phases npu,placement gpu-hold calls: 1
This is the safety-critical branch: [ "$_seen_phases" = 1 ] || _npu_only=0 is what stops "the caller forgot --phases" from becoming "the caller does not need the GPU token". It is correct, and no arm tests it — the harness has a - mode for exactly this and no arm line uses it. One line — arm "no --phases still claims the GPU" - 1 — closes it, and it is the cheapest arm in the file.
2. --phases=npu (the equals form) is not parsed, so it also claims the GPU. Safe — the parser only matches the space-separated form — but it is a silent no-op: a person who writes --phases=npu gets the 858-second wait this change exists to remove and no message saying why. Either accept both forms, or say in the usage line that the phase list takes a space — today the failure mode is "the optimisation did not work and nothing said so", which is the same class as the skip-versus-fail distinction the gate work has been about all evening.
What the change gets right beyond the arms
- The measured motivation is in the header: "
--phases npuservewaited 858 s behind GPU work and then held the GPU for an [NPU-only run]" — a phase set that touches no GPU was taking the GPU token and serialising against the GPU queue. That is a concrete cost, not a hypothetical. - The NPU ticket is untouched.
HW_GATE_NPU_TOKEN/~/NPU-TOKENguarding stays exactly as it was (:186), so an NPU-only run still takes its own fair claim — the change removes one token, not the discipline: "two AIE2 contexts were live at once and the firmware fired two TDRs" is the reason the NPU token exists, and nothing here weakens it. - The parse is data-driven rather than a prefix match: it walks the arguments looking for
--phasesand then tests each comma-separated member, so a future phase name is claimed-by-default until it is listed as NPU — the safe direction for a phase nobody has classified yet.
One thing I would change in the comment
"an NPU-only phase set does not claim the GPU token"
is right but does not say what happens when --phases is absent. The _seen_phases line is the load-bearing one and it reads as defensive plumbing. One clause — "no --phases means all phases, so it claims" — turns the guard into a stated rule, which is what makes someone adding a new phase get this right without reading the loop.
VERDICT at
|
Advances #3030 — the row that proves the NPU serve route passes here in a lane ticket, but which could not be run through the gate.
The measurement. The gate claims
~/GPU-TOKENfor the whole run. That is right — and is engine#2727 — when a GPU phase is named, and wrong when only the NPU phases are:Fourteen minutes behind GPU work, then the GPU held for an NPU test. Meanwhile the same row in a lane ticket:
so the claim was the only thing between the gate and a runnable NPU phase.
What changes. The predicate reads the phase names before anything runs:
npu/npuservealone are NPU-only; any other name — or no--phasesat all, where the default set has GPU phases — keeps the claim exactly as it was. No phase's behaviour changes.Arms (hermetic: a stub
gpu-holdon PATH logs its own name; no token, no device, no build):The arm that fails without it: deleting the
_npu_onlyclause makes the first two reportgpu-hold called 1 time(s), wanted 0— 2 failures; restored, pass. (Writing them caught a bug of mine on the way: the first version keyed the "no--phases" fallback on$HW_GATE_PHASESbeing empty, which is also empty when--phases npuserveis given, so it disabled itself. The flag is now "did I see--phases".)Registered as
hw_gate_npu_phasesbeside the otherhw_gate_*rows;tests_referencedandtool_selftest_wired_checkboth green.