Skip to content

hw-gate: the NPU link gate configures the engine root, so it runs at all (engine#3079) - #3081

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
i679-3079-hwgate
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
i679-3079-hwgate

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes #3079. The gate configured llama.cpp, which has no npu_rt_shim_test -- so it never ran, and the red it printed said the opposite of what happened.

The defect

$src is llama.cpp's tree, because that is what the main build configures. The NPU link gate reused it:

{ "$THERMAL" cmake -S "$src" -B "$build-npu" ... && \
  "$THERMAL" cmake --build "$build-npu" ... --target npu_rt_shim_test npu_dmabuf_import_test; } > "$OUT/npu-link.log"

npu_rt_shim_test is defined at CMakeLists.txt:2698, in this repo; llama.cpp has no such target, so ninja answered unknown target 'npu_rt_shim_test' and the failure was reported as "the NPU runtime … does not link the engine's NPU targets" -- a statement about the runtime, produced by a configure that never read the engine.

The change

Configure "$ROOT", and split the two failures that shared one sentence, because they mean different things:

{ "$THERMAL" cmake -S "$ROOT" -B "$build-npu" -G Ninja -DCMAKE_BUILD_TYPE=Release \
    -DONEBIT_NPU=ON -DONEBIT_NPU_RUNTIME=own -DONEBIT_NPU_RT_DIR="$npurt"; } > "$OUT/npu-link.log" 2>&1
npu_rc=$?
if [ $npu_rc -eq 0 ] && ! grep -q "npu_rt_shim_test" "$build-npu/build.ninja"; then
    # a configured tree WITHOUT the target is "this script pointed at the wrong source", not a runtime failure
    note "::error::the NPU link gate configured a tree with no npu_rt_shim_test target ($ROOT) -- that is this script pointing at the wrong source, not a runtime failure: see npu-link.log"

and the build is a second step, so a build failure keeps the honest message (undefined reference / error: / unknown target are all grepped into the log excerpt now).

Verification

The fix is one argument, so the arm is a static one -- and it is proven to bite:

ok   the NPU link gate configures the engine root, not third_party/llama.cpp (engine#3079)
$ (mutant: -S "$src" restored)  FAIL the NPU link gate does not configure $ROOT -- it would answer 'unknown target' again

bash -n clean, tests/hw_gate_npu_phases_test.sh green.

What the gate still cannot tell you, and what it now can

It can now distinguish "the wrong tree was configured" (a bug in this script, fixed here) from "the runtime does not link the targets" (the thing engine#3023/#3003 wanted a gate for). The first failed closed as the second for eighteen hours, which is why #3073 merged red with a message about a runtime that was never involved.

bong-water-water-bong pushed a commit that referenced this pull request Nov 21, 2026
…3079 fix

#3081 (pi-i679) fixed the same issue independently and had two things this branch lacked, so
this is the union rather than a choice:

* it inspects the CONFIGURED TREE (build.ninja has no npu_rt_shim_test) instead of grepping the log
  for 'unknown target'. That is strictly better: it catches a wrong -S even when the configure
  succeeds, which is the shape of this very bug.
* two static arms in tests/hw_gate_npu_phases_test.sh pin the property (configures $ROOT, and a
  tree without the target says 'did not run'), each verified by mutation: reverting -S to $src fails
  the first, neutering the graph check fails the second.

Kept from this branch: the configure is split from the build so build.ninja can be read at all, and
the configure-failure case gets its own sentence ('could not configure ... against the runtime')
instead of being folded into the link failure.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closing as the subset, per the superset rule: #3083 now contains both of this PR's contributions.

I compared the diffs and took yours rather than asking you to take mine, because two of your pieces are better than what I had:

  • the graph check (build.ninja has no npu_rt_shim_test ⇒ "did not run") instead of my log grep for unknown target. Yours is strictly stronger: it catches a wrong -S even when the configure succeeds, which is exactly the shape of this bug — the configure did succeed, against the wrong tree.
  • the static arms in tests/hw_gate_npu_phases_test.sh, adopted verbatim in substance, plus one more for the message.

Kept from #3083 (which is why the union is bigger than either): the configure is split from the build so build.ninja can be read at all, and a configure failure now gets its own sentence ("could not configure the engine against the runtime") instead of being folded into "does not link" — that distinction is the issue's own point, and it is the case your branch reports as a generic link failure.

Verification on the surviving head (0ddaa46): bash -n clean, tests/hw_gate_npu_phases_test.sh pass, and both new arms fail under their mutation (revert -S to $src → "the NPU link gate does not configure $ROOT"; neuter the graph check → the second arm). Plus, on this box, the configure the gate now runs: ONEBIT_NPU:BOOL=ON, CMAKE_HOME_DIRECTORY = the engine root, npu_rt_shim_test/npu_dmabuf_import_test link rules present, rc 0 — where the old code produced CMAKE_HOME_DIRECTORY=…/third_party/llama.cpp and zero targets.

Nothing of yours is lost; thank you for the graph check, it is the better half of the diagnosis.

@bong-water-water-bong
bong-water-water-bong deleted the i679-3079-hwgate branch November 21, 2026 01:05
bong-water-water-bong pushed a commit that referenced this pull request Nov 21, 2026
…3079 fix

#3081 (pi-i679) fixed the same issue independently and had two things this branch lacked, so
this is the union rather than a choice:

* it inspects the CONFIGURED TREE (build.ninja has no npu_rt_shim_test) instead of grepping the log
  for 'unknown target'. That is strictly better: it catches a wrong -S even when the configure
  succeeds, which is the shape of this very bug.
* two static arms in tests/hw_gate_npu_phases_test.sh pin the property (configures $ROOT, and a
  tree without the target says 'did not run'), each verified by mutation: reverting -S to $src fails
  the first, neutering the graph check fails the second.

Kept from this branch: the configure is split from the build so build.ninja can be read at all, and
the configure-failure case gets its own sentence ('could not configure ... against the runtime')
instead of being folded into the link failure.
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3079 - Partially compliant

Compliant requirements:

  • The NPU link gate now configures the engine root ($ROOT) instead of third_party/llama.cpp
  • The error message is now more accurate and distinguishes between "the gate did not run" and "the runtime does not link"
  • The gate now actually runs and checks the correct source tree

Non-compliant requirements:

  • The PR does not include documentation updates for the behavior change

Requires further human verification:

  • Verification that the gate actually passes with the correct NPU runtime pin
  • Confirmation that the test cases in tests/hw_gate_npu_phases_test.sh correctly validate the fix

3003 - Partially compliant

Compliant requirements:

  • The PR does not directly address the linking issue with npu_rt_shim and npu_dmabuf_import test targets

Non-compliant requirements:

Requires further human verification:

  • Confirmation that the NPU runtime at pin 2485455a now properly links the test targets
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect Source Tree Configuration

The NPU link gate was configuring third_party/llama.cpp instead of the engine root, which caused it to never run correctly. The fix changes the source directory to $ROOT to ensure the correct targets are checked.

# engine#3079: configure the ENGINE root, not $src. $src is llama.cpp's tree (it is what the main build
# configures), and llama.cpp has no npu_rt_shim_test -- so ninja answered "unknown target" and the sentence
# below reported that as "the runtime does not link", the opposite of what happened. The gate had never run:
# its build dir carried `CMAKE_HOME_DIRECTORY=…/third_party/llama.cpp` and `grep -c npu_rt_shim_test
# build.ninja` was 0.
{ "$THERMAL" cmake -S "$ROOT" -B "$build-npu" -G Ninja -DCMAKE_BUILD_TYPE=Release \
    -DONEBIT_NPU=ON -DONEBIT_NPU_RUNTIME=own -DONEBIT_NPU_RT_DIR="$npurt"; } > "$OUT/npu-link.log" 2>&1
Ambiguous Error Reporting

The error message previously reported that the runtime did not link the engine's NPU targets, which was incorrect when the gate failed to find the targets due to configuring the wrong source tree. The fix now differentiates between these two failure modes.

if [ $npu_rc -eq 0 ] && ! grep -q "npu_rt_shim_test" "$build-npu/build.ninja" 2>/dev/null; then
  # the two failures mean different things and used to share one sentence: a configured tree WITHOUT the
  # target is "the gate looked at the wrong tree", which is a bug in this script, not in the runtime.
  note "::error::the NPU link gate configured a tree with no npu_rt_shim_test target ($ROOT) -- that is this script pointing at the wrong source, not a runtime failure: see npu-link.log"
  npu_rc=1
elif [ $npu_rc -eq 0 ]; then
  "$THERMAL" cmake --build "$build-npu" -j "$JOBS" --target npu_rt_shim_test npu_dmabuf_import_test >> "$OUT/npu-link.log" 2>&1
  npu_rc=$?
fi
if [ $npu_rc -ne 0 ]; then
  note "::error::the NPU link gate FAILED at ${npu_pin:0:12} (npu_rt_shim_test, npu_dmabuf_import_test): see npu-link.log"
  grep -E "undefined reference|error:|unknown target" "$OUT/npu-link.log" | head -n 4 | sed 's/^/  /'
  built=1

bong-water-water-bong added a commit that referenced this pull request Nov 21, 2026
…d not run (engine#3079) (#3083)

* hw-gate: the NPU link gate configures the engine, and says when it did not run (engine#3079)

`src` is third_party/llama.cpp (set at :491 for the HRX UI/build path) and the NPU step at :654
reused it, so the configure read llama.cpp's CMakeLists -- which has no npu_rt_shim_test -- and
ninja answered "unknown target", which the block then reported as "the NPU runtime does not link
the engine's NPU targets". The check never ran: every PR with a `build` phase carried a permanent
false red since #3029, it merged red on #3073 (00:39Z, all other checks green), each attempt spent
a gpu-hold wait (732 s in that run) to configure the wrong tree, and a real link failure became
indistinguishable from this one.

Evidence from the failing run's own build dir (~/.cache/hw-gate/build-685489b587-npu):
  CMAKE_HOME_DIRECTORY:INTERNAL=.../engine/engine/third_party/llama.cpp
  ONEBIT_NPU:UNINITIALIZED=ON     <- the engine's option() was never reached
  npu_rt_shim_test in build.ninja: 0

Two changes:
* -S "$ROOT" instead of -S "$src": the NPU targets live in the engine's CMakeLists (:2698-2703,
  inside if(ONEBIT_NPU), and ONEBIT_NPU=ON is already passed).
* "did not run" is now a different outcome from "does not link": `unknown target` -> "the NPU test
  targets are not in the tree this configured -- a defect in this gate, not the runtime";
  `CMake Error` -> "could not configure the engine against the runtime"; anything else keeps the
  link-failure sentence. Otherwise the next variant of this bug reads exactly like a regression.

Branch selection verified against three synthetic logs (unknown target / undefined reference /
CMake Error), each landing on its own sentence.

* hw-gate: take the graph check and the static arms from #3081 into the #3079 fix

#3081 (pi-i679) fixed the same issue independently and had two things this branch lacked, so
this is the union rather than a choice:

* it inspects the CONFIGURED TREE (build.ninja has no npu_rt_shim_test) instead of grepping the log
  for 'unknown target'. That is strictly better: it catches a wrong -S even when the configure
  succeeds, which is the shape of this very bug.
* two static arms in tests/hw_gate_npu_phases_test.sh pin the property (configures $ROOT, and a
  tree without the target says 'did not run'), each verified by mutation: reverting -S to $src fails
  the first, neutering the graph check fails the second.

Kept from this branch: the configure is split from the build so build.ninja can be read at all, and
the configure-failure case gets its own sentence ('could not configure ... against the runtime')
instead of being folded into the link failure.

* hw-gate: a fresh NPU build dir and the dedicated test row (engine#3079, cl-hrxnan's finding)

cl-hrxnan fixed #3079 independently and found the half both other branches were missing: a cache
generated by the OLD gate in "${build}-npu" has -S third_party/llama.cpp baked in, and CMake refuses
to re-home an existing cache ("the current CMakeCache.txt is different than the one used to
generate" -- FATAL_ERROR). So changing -S to "$ROOT" alone would still fail on every box that had
already run the old gate, which is every box that mattered. The configure now uses
"${build}-npu-engine", a directory the submodule never poisoned.

Also takes their tests/hw_gate_npu_link_src_test.sh (82 lines, hermetic, text + one grep of the
engine's CMakeLists) and its CMakeLists row, which is a better artefact than the two static arms I
had: it pins that both --targets are built, that "did not run" is decided BEFORE the build attempt,
that a link failure is only claimed AFTER it, and that the predicate reads build.ninja rather than
the log.

Added one arm they did not have, because it was the one fix with no falsifier: re-homing into
"${build}-npu" leaves every other arm green (measured), so the file now requires the fresh
directory by name and fails with the CMake reason when it is missing.

Kept from this branch: the configure-failure sentence. Their version lets a failed configure fall
into the same "did not run ... broken check" message, which is right for a wrong -S and misleading
for "the runtime could not be configured" -- the exact conflation #3079 was about. Verified with two
synthetic logs: npu_rc!=0 + no graph -> "could not configure the engine against the runtime";
npu_rc==0 + no graph -> "the gate did not run ... wrong source".

---------

Co-authored-by: phyb5 <bcloud@local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant