Skip to content

hw-gate: a GPU step takes no ~/npu.lock, so the gate runs through an NPU serve (engine#682) - #716

Merged
bong-water-water-bong merged 2 commits into
mainfrom
1bit/682-hw-gate-no-npu-lock
Nov 1, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
1bit/682-hw-gate-no-npu-lock

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Closes engine#682. Every GPU step was wrapped in flock ~/npu.lock, so with an NPU serve up the gate queued
behind it — flock is not first-come-first-served, waits ran 10–60 minutes, and c16's gate was cut three times by
its own 20-minute hold
while it waited for a lock it never needed.

The premise for taking that lock is gone, and it was measured before this diff:

engine#673 (item 5 of #612) measurement
FCLK hazard does not reproduce — 160/160 byte-exact, zero GPU reset/MODE2/timeout lines, fabric clock demonstrably changing level during NPU runs
NPU stream with the GPU busy ~87 % of its bandwidth kept — 7.40 GB/s against 8.2–8.5 idle; 10.5–10.9 ms → 12.0 ms per launch, 7.40 to two decimals in both passes
fleet rule that followed an NPU run takes the NPU device lock and nothing else

What changes

  • gpu() takes no ~/npu.lock. The step still runs inside the GPU token claim, still waits for coder-llm
    to be idle, still runs under scripts/mem-guard.sh + ~/lb/thermal-run.sh (cool-down and memory pre-check
    intact: a 76 from the pre-check still retries, up to HW_GATE_MEM_RETRIES).
  • The NPU phase still takes it (unchanged line) — an NPU dispatch must not overlap another NPU dispatch. It is
    now the only place in the gate that holds the lock, and LOCK/LOCK_WAIT exist for it.
  • rc 75 is no longer produced by a GPU step: the three callers that treated 75 || 76 alike (ops,
    fa-decode-q8, the model loop) now treat 76 only, and their detail line says "could not run: the memory
    pre-check refused it (rc 76)" instead of "lock or memory". The dead $LOCK still held after … note is gone.
  • Summaries/wording: the timing split is waiting (heat, memory) vs running the step, and the ops row says
    step ${held}s instead of held the lock ${held}s.
  • docs/hw-gate.md: the Lock. bullet becomes No NPU lock. with the docs(hybrid): NPU and GPU run at the same time, measured — no hazard, ~13 % stream cost (engine#612 item 5) #673 numbers; the "waiting for ~/npu.lock
    costs more than the gate" paragraph is retold since that wait is now only the NPU phase's; Lock fairness under
    Not covered is scoped to the NPU.
  • .github/workflows/hw-gate.yml: two comment lines that described the lock and the timeout budget.

Test

tests/hw_gate_test.py (ctest name hw_gate_judges, the existing host-side judge test) grows one invariant that
reads scripts/hw-gate.sh: gpu() must contain no flock, and the NPU phase must still take the lock — a
flock creeping back into the GPU path is exactly this regression, and it would be silent.

Verified on this box:

bash -n scripts/hw-gate.sh                 -> OK
shellcheck -S warning scripts/hw-gate.sh   -> clean
python3 tests/hw_gate_test.py              -> hw_gate_test: PASS
  negative control: put the flock line back -> FAIL: gpu() must not take ~/npu.lock (engine#682) …
python3 -c 'yaml.safe_load(...)'           -> yaml OK

No GPU or NPU claim was taken for this PR. The on-device proof is the next gate run (c19 candidate): its summary
should show waiting only for heat/memory and no NPU-lock line, and it must be able to run while an NPU serve is up
— which is the point of the issue and the thing the next gate will demonstrate. If the next gate shows any new
amdgpu ring timeout, the gate already reports it per step and this PR is the first suspect.

…NPU serve (engine#682)

Every GPU step was wrapped in `flock ~/npu.lock`, so with an NPU serve up the gate queued behind it: flock
is not first-come-first-served, waits ran 10-60 minutes, and c16's gate was cut three times by its own
20-minute hold while it waited. The premise for taking the lock is gone - engine#673 measured NPU and GPU
running concurrently with no FCLK hazard and ~87 % of the NPU stream's bandwidth kept while the GPU is busy
(7.40 GB/s against 8.2-8.5 idle, 10.5-10.9 ms -> 12.0 ms per launch, 160/160 byte-exact, zero resets), and
the fleet rule that came out of it is that an NPU run takes the NPU device lock and nothing else.

So gpu() no longer takes it. The NPU phase still does, because an NPU dispatch must not overlap another NPU
dispatch, and the GPU token, the cool-down, mem-guard and coder-llm idling are untouched. rc 75 (flock's
lock-timeout code) is no longer produced by a GPU step, so the three callers that treated 75 and 76 alike
now treat 76 only (the memory pre-check's refusal), and the summary says "running the step" instead of
"holding ~/npu.lock".

tests/hw_gate_test.py grows a script invariant that reads scripts/hw-gate.sh: gpu() must not contain flock,
the NPU phase must. Verified both ways - it FAILs with the old line put back.

Measured on this box: bash -n, shellcheck -S warning (clean), tests/hw_gate_test.py PASS. No GPU or NPU claim
was taken; the on-device proof is the next gate run (c19), where the gate should no longer wait for the NPU
lock line in its summary.
@bong-water-water-bong bong-water-water-bong added the tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied label Nov 1, 2026

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

Verified at 24bfbd5c, shell side and test side.

The change does what it says. One flock remains in scripts/hw-gate.sh, at line 585 — the NPU phase (sh -c "$HW_GATE_NPU_CHECK" under flock -w "$LOCK_WAIT" -E 75), which is exactly where it should be. gpu() no longer takes it: the flock … "$LOCK" "$0" --cool … line is now plain "$0" --cool …, and the GPU token claim (take_token) still wraps the step, so GPU steps cannot overlap each other.

rc 75 is gone from the GPU path and only exists at the NPU phase (-E 75 at 585, handled at 592). Removing 75 || 76 from the ops, fa-decode-q8 and model-loop callers is therefore consistent, not a dropped case: no GPU step can return 75 any more. grep -n "75" finds only the NPU line, the HW_GATE_LOCK_WAIT default and the 75 °C cool target.

Static checks, run here:

bash -n scripts/hw-gate.sh                 -> OK
shellcheck -S warning scripts/hw-gate.sh   -> clean (rc 0)

The new invariant test bites. python3 tests/hw_gate_test.py → PASS. Then, because a test that cannot fail is worthless, I injected the regression it exists to catch, twice:

  • added flock "$LOCK" true inside gpu() → FAIL: gpu() must not take ~/npu.lock (engine#682): the GPU step path holds no lock, exit code 1;
  • removed the NPU phase's flock → FAIL: the NPU phase must still hold ~/npu.lock: an NPU dispatch must not overlap another, exit 1.

Both directions fail loudly, so a flock creeping back into the GPU path — or being dropped from the NPU phase — is caught by CI rather than silently.

CI at this head: build, CodeQL, Analyze ×4 completed success.

The premise is on the record and I am not re-measuring it: engine#673 (closed) is "NPU and GPU run at the same time, measured — no hazard, ~13 % stream cost", which matches the body's 10.5-10.9 ms → 12.0 ms and 160/160 byte-exact. What the fleet should know, and what the docs do not spell out, is the trade-off this accepts: while a gate runs its 6-13 minutes of GPU time, a concurrent NPU serve pays that ~13 % per launch. That is a deliberate policy choice, previously enforced by the lock, and it now rests on #673's measurement — worth one line in docs/hw-gate.md if anyone later asks why a serve slowed down during a gate. Not a blocker: the numbers are measured, and the lock's original purpose (FCLK hazard) was shown not to reproduce.

Docs and the workflow comments are consistent with the code, including the honest rewording of "waiting for ~/np.lock costs more than the gate" into the past tense, and Lock fairness under Not covered narrowed to the NPU.

tprs-ready applied.

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

At adad9386 (rebased onto 4968bb29 after #687 merged). The author patch is unchanged — patch-id 9e4ede8ece89 at both the head I verified and this one, so the whole of my earlier review still applies: one flock left at scripts/hw-gate.sh:585 (the NPU phase), none in gpu(), rc 75 only at the NPU phase, bash -n clean, shellcheck -S warning clean, and the new invariant test fails loudly in both directions (I injected a flock into gpu() and removed the NPU phase's — each produced its own FAIL and exit 1).

tprs-ready stands. The one thing I asked to be recorded still stands: while a gate runs its 6-13 minutes of GPU time, a concurrent NPU serve pays ~13 % per launch (engine#673), and docs/hw-gate.md does not say so.

@bong-water-water-bong
bong-water-water-bong merged commit cd83e12 into main Nov 1, 2026
8 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/682-hw-gate-no-npu-lock branch November 1, 2026 02:29
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

682 - Partially compliant

Compliant requirements:

  • The hw-gate.sh script no longer takes flock ~/npu.lock before every GPU step
  • The NPU phase still takes the lock
  • GPU steps no longer wait for the NPU lock
  • rc=75 only applies to the NPU phase now
  • The gate completes GPU phases without waiting for the NPU lock

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

Lock Acquisition Change

The change removes the flock acquisition for the NPU lock from GPU steps, which was causing the gate to wait for extended periods when an NPU serve was running. This is a correct fix for the described issue, but it's important to ensure that the memory and thermal checks still provide sufficient protection for concurrent GPU/NPU execution.

"$0" --cool --mem "${GPU_MODEL:--}" "$ROOT/scripts/mem-guard.sh" "$MEM_FLOOR" "$THERMAL" "$@"
Error Code Handling

The change modifies how error codes are handled in GPU steps, specifically removing the handling of rc=75 (lock timeout) and only treating rc=76 (memory pre-check failure) as a retryable failure. This is correct according to the ticket, but it's important to verify that this change doesn't introduce any unexpected behavior in error reporting or retry logic.

elif [ $rc = 76 ]; then
  result ops FAIL $(( $(date +%s) - t0 )) "could not run: the memory pre-check refused it (rc 76)"

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

Labels

Review effort 3/5 tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant