Skip to content

hw-gate: an NPU-only phase set does not claim the GPU token (engine#3030) - #3039

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-npuperf/npu-phases-no-gpu-claim
Nov 20, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-npuperf/npu-phases-no-gpu-claim

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

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-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:

$ bash scripts/hw-gate.sh --phases npuserve        # bin, model and kernels all set
gpu-hold[2681538] took /home/bcloud/GPU-TOKEN after 858s (die 71C)
hw-gate check at 2a821b55 … ; Terminated

Fourteen minutes behind GPU work, then the GPU held for an NPU test. Meanwhile the same row in a lane ticket:

$ npu-hold -l npu-serve-e2e-06b -t 12 -- env ONEBIT_NPU_KERNELS=<0.6B ELF dir> \
      bash tests/serve_e2e.sh <npu-lane 1bit> ~/Qwen3-0.6B-NPU2 npu
ok  /health 200 · /v1/models names e2e-model · answers Paris · streams (32 chunks)
PASS     20 s, rc 0, driver 9BC1292B784C8D5F40AED02

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/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. No phase's behaviour changes.

Arms (hermetic: a stub gpu-hold on PATH 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)

The arm that fails without it: deleting the _npu_only clause makes the first two report gpu-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_PHASES being empty, which is also empty when --phases npuserve is given, so it disabled itself. The flag is now "did I see --phases".)

Registered as hw_gate_npu_phases beside the other hw_gate_* rows; tests_referenced and tool_selftest_wired_check both green.

…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.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 3039

"The gate claims ~/GPU-TOKEN for the whole run. That is right — and is engine#2727 — when a GPU phase is in the set. It is wrong when there is not one."

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 (9BC1292B784C8D5F40AED02). The gate was the only thing between a green row and a runnable phase.

Three things this PR gets right that are easy to get wrong:

  1. the predicate reads the phase names before anything runs — not "did the run touch the GPU", which would be a post-hoc judgement and could not prevent the claim;
  2. it is deliberately narrow: npu/npuserve alone are NPU-only, which means a mixed set still claims the GPU. That is the conservative direction, and it is the right one: the cost of being wrong here is a device collision (gpu-hold: a payload that re-invokes gpu-hold on the same queue deadlocks for the whole window (nothing tells it it is already inside a ticket) #2727), not a slow run;
  3. the arms are hermetic — a stub gpu-hold on PATH that logs its own name, so the test asserts "did the gate try to claim" without a token, a device or a build. That is the instrument for this question, and it can run anywhere.

Three asks:

  1. assert the negative for a GPU-only set too — the four arms should include --phases hrx (or whatever the GPU phase is called) requiring the stub to be called, because a predicate that never claims would also make the NPU arms pass. Without that arm, this PR cannot distinguish "correctly skips the claim" from "never claims";
  2. and one arm for a mixed set (npu,npuserve,hrx) expecting a claim — that is the case gpu-hold: a payload that re-invokes gpu-hold on the same queue deadlocks for the whole window (nothing tells it it is already inside a ticket) #2727 exists for, and it is the only arm that proves the narrowness was chosen rather than fallen into;
  3. say what the gate prints when it skips the claim — one line (gpu-hold: not claimed, NPU-only phase set) so a reader of a gate log knows the reservation was a decision rather than a failure. Tonight's whole theme: a skip must say which skip.

On the shape: +101 across scripts/hw-gate.sh, a tests/hw_gate_np* file and CMakeLists.txt, risk-files = 0, behind 1. The one-file-plus-arm shape, and the row is registered in the same commit — the thing I have asked of four PRs tonight and usually do not get.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3030 - Partially compliant

Compliant requirements:

  • The test case is added and verifies that NPU-only phase sets do not claim the GPU token.
  • The test is hermetic and uses a stub gpu-hold to count calls.
  • The test is added to CMakeLists.txt as hw_gate_npu_phases.
  • The hw-gate.sh script is modified to detect NPU-only phase sets and avoid claiming the GPU token.

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

GPU Token Claim Logic

The logic for determining whether to claim the GPU token has been updated to check for NPU-only phase sets. This is a correctness fix to prevent unnecessary GPU hold claims when only NPU phases are specified. The change correctly identifies when only 'npu' or 'npuserve' phases are present and avoids claiming the GPU token in those cases.

# engine#3030: a phase set with NO GPU phase in it does not claim the GPU token. Measured 2026-11-20: `--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. The predicate is on the NAMES, before any phase runs, so it costs
# nothing when a GPU phase is present (the default set is untouched).
_npu_only=1
_seen_phases=0
_prev=""
for _a in "$@"; do
    if [ "$_prev" = "--phases" ]; then
        _seen_phases=1
        _set=${_a//,/ }
        for _p in $_set; do
            case "$_p" in
                npu|npuserve) ;;
                *) _npu_only=0 ;;
            esac
        done
    fi
    _prev=$_a
done
# no --phases named: the default set has GPU phases, so the claim stays
[ "$_seen_phases" = 1 ] || _npu_only=0
if [ "${GPU_HOLD:-}" != 1 ] && [ "${HW_GATE_GPU_HOLD:-1}" != 0 ] && [ -z "${HW_GATE_TOKEN:-}" ] && [ "$_npu_only" != 1 ]; then
    hold=$(command -v gpu-hold 2> /dev/null || true)
Test Coverage

A new test script has been added to verify that the GPU token is not claimed when only NPU phases are specified. The test is hermetic and uses a stub gpu-hold to count calls, which is a good approach for testing this specific behavior without requiring actual GPU resources.

#!/usr/bin/env bash
# Copyright 2026 bong-water-water-bong
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# tests/hw_gate_npu_phases_test.sh — an NPU-only phase set does not claim the GPU token (engine#3030).
#
# The gate claims ~/GPU-TOKEN for the whole run, which is right when a GPU phase is named and wrong when only NPU
# phases are: measured 2026-11-20, `--phases npuserve` waited 858 s behind GPU work and then held the GPU for an
# NPU-only test -- a wait nobody explains and a hold another lane pays for.
#
# Hermetic: `gpu-hold` is a stub on PATH that logs its own name, and the gate is stopped by its own usage exit after
# the claim would have happened. No token, no device, no build.
#
# usage: bash tests/hw_gate_npu_phases_test.sh    (exit 0 = every arm passes, 1 = a failure)
set -uo pipefail

root=$(cd "$(dirname "$0")/.." && pwd)
gate=$root/scripts/hw-gate.sh
[ -f "$gate" ] || { echo "hw_gate_npu_phases_test: no $gate" >&2; exit 2; }

tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
mkdir -p "$tmp/bin"
cat > "$tmp/bin/gpu-hold" <<'STUB'
#!/bin/sh
printf '%s\n' "$*" >> "$STUBLOG"
exec "$@"
STUB
chmod +x "$tmp/bin/gpu-hold"

fails=0
arm() {  # <name> <phases|-> <expected calls>
    local name=$1 phases=$2 want=$3 log="$tmp/log.$RANDOM"
    : > "$log"
    if [ "$phases" = "-" ]; then
        STUBLOG=$log PATH="$tmp/bin:$PATH" timeout 60 bash "$gate" > "$tmp/out.$RANDOM" 2>&1
    else
        STUBLOG=$log PATH="$tmp/bin:$PATH" timeout 60 bash "$gate" --phases "$phases" > "$tmp/out.$RANDOM" 2>&1
    fi
    local got
    got=$(grep -c . "$log" 2> /dev/null || true)
    got=${got:-0}
    if [ "$got" = "$want" ]; then
        echo "ok   $name: gpu-hold called $got time(s)"
    else
        echo "FAIL $name: gpu-hold called $got time(s), wanted $want"
        fails=$((fails + 1))
    fi
}

# The claim is what an NPU-only run must not make.
arm "npuserve alone is NPU-only"        npuserve        0
arm "npu,npuserve is NPU-only"          "npu,npuserve"  0
# ... and what any GPU phase must still make, or this change would quietly drop the queue the gate depends on.
arm "placement still claims the GPU"    placement       1
arm "build,ops still claim the GPU"     "build,ops"     1
arm "a mixed set still claims the GPU"  "npu,placement" 1

[ "$fails" = 0 ] && { echo "hw_gate_npu_phases_test: pass"; exit 0; }
echo "hw_gate_npu_phases_test: $fails failure(s)"
exit 1

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 that case saying "add NPU-only phases here" is enough.
  • _seen_phases handles "no --phases given" 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.)

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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 teeth

Run against main's hw-gate.sh (which has no predicate), the same test fails exactly where it should:

FAIL npu,npuserve is NPU-only: gpu-hold called 1 time(s), wanted 0
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: 2 failure(s)

and against your head:

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

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

  1. --phases with an empty value (--phases "" or --phases ,) — _seen_phases=1 with no phase names leaves _npu_only=1, so an empty set would be treated as NPU-only and skip the GPU token. Whether that is right depends on what an empty set does downstream (probably a no-op), but it is the one input where "nobody named a GPU phase" is true for the wrong reason.
  2. --phases given twice — the loop only inspects the token after --phases, so a second occurrence overrides rather than adds; that matches how the argument is parsed, but if _npu_only is set by the first and cleared by the second, the last one wins, which is at least consistent.

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 next

The measured cost in the body — gpu-hold … took /home/bcloud/GPU-TOKEN after 858s (die 71C) — is the argument for this change in one line: fourteen minutes of waiting for a token that an NPU-only run should never take, then holding it for the duration. Worth keeping in the commit message rather than only the PR.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at a9b24249: READY — dropping the GPU claim for an NPU-only phase set is right, and the thing that would make it wrong is already in the file: the NPU phases take their own npu-hold ticket.

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}" …)   # npuserve

So an NPU-only run is still inside an npu-hold with a time limit — the hard rule — and only the wrong ticket stops being taken. Worth quoting those two lines in the body: it is the difference between a fix and a rule violation, and the file already documents why the NPU token exists (:181-188, the two-TDR incident when an npu phase held only ~/npu.lock while another lane held ~/NPU-TOKEN).

The predicate is fail-safe in the direction that matters. Any name that is not npu/npuserve clears _npu_only, and no --phases at all clears it, so a mixed set (ops,npuserve) and the default set both keep the claim exactly as before. A parse failure therefore costs a wait, never a hold — which is the right way round.

Two small asks:

  1. --phases=npuserve is not recognised. The scan looks for --phases as the previous argument, so the equals form leaves _seen_phases=0 and the run still takes the GPU token — i.e. the 858 s wait comes back for whoever types it that way. Either match --phases=* too (three lines, same predicate), or say in the comment that the flag must be space-separated. The parse itself would be safer as case "$_a" in --phases=*) _set=${_a#--phases=} ;; esac inside the same loop.
  2. _set=${_a//,/ } then for _p in $_set is unquoted word splitting — harmless for phase names, worth a # shellcheck disable=SC2086 or a read -ra if this file is ever linted; the behaviour is right.

Arms are the right kind: a stub gpu-hold on PATH that logs its own invocation, so "the claim was not taken" is asserted rather than inferred, and no token, device or build is involved. That is also why the fix is cheap to keep: the arm fails the moment someone reintroduces an unconditional claim.

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 bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ;; at hw-gate.sh:259. There is no --phases=SET spelling to miss, so scanning "$@" for --phases <value> covers every accepted invocation.
  • The default set is protected: [ "$_seen_phases" = 1 ] || _npu_only=0 — no --phases named ⇒ claim as before, which is what the comment promises ("the default set is untouched").
  • A trailing --phases with 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 in npu-hold -t 20 unless 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 npuserve waited 858 s for ~/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."

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 bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 npuserve waited 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-TOKEN guarding 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 --phases and 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.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at a9b2424: READY on the change — one real hazard in the test's own arms, one stale sentence, and the issue it cites is closed

Measured first

$ bash tests/hw_gate_npu_phases_test.sh          # PR tree, submodules absent
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            real 0m0.160s

$ (control) same file, clause `&& [ "$_npu_only" != 1 ]` deleted from scripts/hw-gate.sh
FAIL npuserve alone is NPU-only: gpu-hold called 1 time(s), wanted 0
FAIL npu,npuserve is NPU-only: gpu-hold called 1 time(s), wanted 0
… 2 failure(s)

Your falsification claim holds exactly as written: two failures, both the ones the clause is for. ci_targets_check 30/30 with nothing new, tests_referenced 115/115 (the new row is referenced), dupdef_check, tmp_path_check 44/none new, conflict_marker_check 0.

The predicate's edges, because a name-based exemption is where this class of change goes wrong

--phases npu --phases placement      -> 1 claim      (and PHASES=placement, so the token is taken anyway)
--phases placement --phases npu      -> 1 claim      (conservative: the flag is "did I see --phases at all")
--phases npu,                        -> 0 claims     (trailing comma splits clean)
--phases NPU                         -> 1 claim      (case-sensitive, so unknown names keep the old behaviour)
--phases ""                          -> 0 claims, and no phase runs
--phases npu,npuserve                -> 0 claims

Every ambiguous form errs toward claiming, which is the right direction: a wrong claim costs a wait, a missing claim costs a queue. No hole found.

The safety question a reviewer has to answer here: does an NPU-only run now go ticketless?

No — and that is what makes this a fix rather than a queue bypass. The gate's two NPU phases take their own claim inside the phase body, independently of the GPU queue:

scripts/hw-gate.sh:891   hold_args=("$NPU_HOLD" -l hw-gate-npu      -t … -w "$LOCK_WAIT" --)   # npu
scripts/hw-gate.sh:934   hold_args=("$NPU_HOLD" -l hw-gate-npuserve -t … -w "$LOCK_WAIT" --)   # npuserve

and both SKIP (not run) when unconfigured — npu without HW_GATE_NPU_CHECK, npuserve without HW_GATE_NPU_SERVE_BIN/_MODEL — so --phases npu in a bare environment dispatches nothing and claims nothing. Dropping the GPU claim removes a queue wait, not a ticket.

One sentence is now stale because of it — scripts/hw-gate.sh:116-117 still reads "A ticket on a DIFFERENT queue - npu-hold, which is how the release gate runs - is not this case and still takes its own GPU claim below." With this change an npu-hold-wrapped NPU-only run no longer takes that claim. Worth rewording in the same push; the next reader will trust that sentence.

The one real hazard: the build,ops arm can enter the gate's build block

The arms pass no --bin, so BIN is empty and the gate falls into the "build it yourself" branch before it ever looks for a binary. Measured in two trees:

  • this clone (no third_party/llama.cpp): exits in milliseconds at :479, ::error::third_party/llama.cpp is not checked out. Fast, hermetic — which is what you saw.
  • a tree where the submodule IS present (I stubbed third_party/{llama.cpp,hrx-system}/CMakeLists.txt to reach the branch): the same arm enters the build block and gets as far as fetching the private add-on —
$ HW_GATE_GPU_HOLD=0 bash scripts/hw-gate.sh --phases build,ops      # stub fetch-private on PATH-free path
::error::cannot fetch the private gpu-kernels add-on at bc3051d5e9c6 …

On a lane box, where that gh fetch succeeds, the row continues into cmake/ninja on third_party/llama.cpp — a ~20-minute build and a private-kernel fetch, triggered by a row whose whole justification is "no token, no device, no build".

CI is not exposed (ci.yml:93 checks out without submodules: true, so there the arm exits at :479), so this is a dev-box/lane hazard, not a CI one — but ctest -R hw_gate_* on any full tree hits it.

Fix, measured: give every arm a binary path that never exists — --bin "$tmp/nobin". The gate then stops at the missing-binary check (:690), which is after the claim, so the arms measure exactly what they measure now, in any tree:

$ bash tests/hw_gate_npu_phases_test.sh       # in the tree WITH third_party/llama.cpp present
… 5 arms ok
hw_gate_npu_phases_test: pass            real 0m0.145s

Three lines in the test, nothing in the gate.

And the issue it cites is closed

#3030 was closed at 20:50:57Z, and the two comments that motivated this PR (21:50Z "item 3 is done, the row runs", 22:05Z "the gate claims the GPU for the whole run") were posted after the close. So "Advances #3030" points at a closed issue — the same shape as #3038/#3003 an hour ago. #3030's own three items are genuinely done, and this is a different defect (a gate claim, not the NPU serve route), so I would open the one-paragraph issue — "hw-gate claims the GPU token for NPU-only phase sets, so the row #3030 delivered cannot be run through the gate (measured: 858 s wait, then the GPU held for an NPU test)" — and point this PR at it, rather than reopening #3030 and blurring a finished one.

READY on the gate change and the row; the three items above are all inside this PR's own files and each is a few lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant