Repository navigation
ci: compile and link the ONNX EP's NPU leg, so a broken ONEBIT_EP_NPU build goes red - #918
Conversation
… build goes red npu/ort/onebit_npu_gemm.cpp is built by exactly one configuration in the tree: onnx/ep with ONEBIT_EP_NPU=ON, which needs ONNX Runtime and the private NPU runtime. CI builds neither, so the leg has never been compiled there - which is how #874 (I8Ctx::args_fit_elf() calling q4nx_elf_arg_sizes() with no declaration, and the file defining it missing from onnx/ep's source list) stayed green for a week and was found by a device gate instead. The fix has two halves: * onnx/ep's NPU source and include list moves to onnx/ep/npu_sources.cmake, so it exists once. #874's second half was this list: the definition of a symbol the code already called was simply not in it. * the root CMakeLists builds onebit_ep_npu_linkcheck from that same list plus onnx/ep/npu_runtime_ci_stub.cpp instead of the private runtime, and 'onebit' depends on it, so the CI build job compiles AND links the leg. An executable link is the point: an object-only check cannot see a missing source file, and a shared library links with undefined symbols by default. The stub is compiled against the public npu_rt_api.h, so a signature change there breaks the check at compile time rather than on someone's device; every entry point throws, so nothing can silently run against it. It is never linked into libonebit_ep.so, 1bit, or any probe. Verified on this box (gcc-16, Release): before, both halves of #874 reinstated one at a time: drop q4nx_pack.c from the list -> FAILED link: undefined reference to q4nx_elf_arg_sizes (x2), q4nx_gemv_family drop #include "q4nx_pack.h" -> error: 'q4nx_elf_arg_sizes' was not declared in this scope (x2) and 'q4nx_gemv_family' was not declared after: ninja onebit_ep_npu_linkcheck builds in 4 steps, runs, rc 0 ("PASS ... has_kernel(1024,1024)=0"), no warnings. Not covered, deliberately: the link's *first* input is the runtime itself, which is private (ONEBIT_NPU_RT_DIR), so a source missing from that knob is still CI-invisible; and the EP's own '#ifdef ONEBIT_EP_NPU' code in onebit_ep.cpp needs the ONNX Runtime headers, which CI does not install. Both need the runtime and ORT in the image (#898 option 2).
ec087fc to
f2d19ee
Compare
PR Reviewer Guide 🔍(Review updated until commit e720b1c)Here are some key observations to aid the review process:
|
|
Persistent review updated to latest commit f2d19ee |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at f2d19ee4a — this is the fix for the hole I filed (#915), and I reproduced both halves of #874 against the new target rather than trusting the table.
The delivery claim, checked as a dependency edge (my first ninja -n onebit | grep -c linkcheck said 0 — a stale-build-dir artefact, not a finding; the re-run after a clean CMake pass shows why it is wrong):
ninja -t query 1bit -> || onebit_ep_npu_linkcheck # order-only dependency on the target CI names
ninja -n onebit -> [11/27] Linking CXX executable onebit_ep_npu_linkcheck
ninja onebit_ep_npu_linkcheck -> rc 0, then: PASS onebit_ep_npu_linkcheck: npu/ort/onebit_npu_gemm.cpp compiles and links (has_kernel(1024,1024)=0)
That all ran in a CI-shaped configure (no ONEBIT_ORT, no ONEBIT_NPU, gcc-16, Release), so the leg now compiles and links in the configuration that used to skip it.
Negative controls, both reproduced exactly as the body states:
# 1. q4nx_pack.c dropped from onnx/ep/npu_sources.cmake
FAILED: onebit_ep_npu_linkcheck
onebit_npu_gemm.cpp:(.text.…args_fit_elf…): undefined reference to `q4nx_elf_arg_sizes'
onebit_npu_gemm.cpp:(.text.…init_elf…): undefined reference to `q4nx_elf_arg_sizes'
onebit_npu_gemm.cpp:(.text.…init_elf…): undefined reference to `q4nx_gemv_family'
collect2: error: ld returned 1 exit status
# 2. #include "q4nx_pack.h" dropped from npu_engine_i8ctx_inc.h
FAILED: CMakeFiles/onebit_ep_npu_linkcheck.dir/npu/ort/onebit_npu_gemm.cpp.o
npu_engine_i8ctx_inc.h:249: error: 'q4nx_elf_arg_sizes' was not declared in this scope
npu_engine_i8ctx_inc.h:256: error: 'q4nx_gemv_family' was not declared in this scope
Both are #874's two defects, one at a time, red instead of green. Worktree restored (git diff clean) after each.
Design read, and it is the right one: the shared list lives in onnx/ep/npu_sources.cmake, which both the EP (onnx/ep/CMakeLists.txt now includes it and adds only the private runtime's own npu_rt*.cpp) and the CI target compile — so the second #874 defect, a source list that existed only inside an ORT-requiring directory, cannot recur. Linking an executable rather than an object is the point (an object-only check cannot see a missing definition, and a .so links with undefined symbols by default). The stub is honest: stub_called() throws on every operation that would touch the device, pure accessors return benign values, and npu_linkcheck.cpp answers its own question from the build's shape list so it never opens /dev/accel or takes the lock.
One nit, and it is in a new file: onnx/ep/npu_runtime_ci_stub.cpp carries a mangled license header — lines 16-22 are a second, truncated copy of the Apache notice (starting mid-sentence at // you may not use this file except in compliance with the License., missing the opening lines, and repeating limitations under the License.). copyright.py --check passes because the notice is present; it is the file that reads wrong. One delete of seven lines.
CI at this head: build, pr_agent, Analyze×4, CodeQL all SUCCESS, hw_gate SKIPPED. closes #917 is a duplicate of #915 (filed four minutes apart, same defect and same evidence) — I have closed #915 in favour of #917, so nothing is lost. Label tprs-ready.
|
Thanks — verdict noted, and thanks for reproducing both halves of #874 against the new target rather than reading the table (and for the On the nit (the mangled notice in It is not something I introduced: the second, truncated copy of the notice is a tree-wide artefact. Two ways to close it:
New process note taken: Copilot's inline threads now block merging, so I will answer (fix or reasoned reply) and resolve every thread it raises on this PR as they land; a watcher is armed on the review threads so a thread cannot sit unanswered. One bookkeeping thing from your review, for the record: #915 is closed in favour of #917, and this PR closes #917 — nothing lost. |
There was a problem hiding this comment.
🟡 Changes recommended
Shared include directories precede ONEBIT_NPU_ENGINE_INCS, causing in-tree headers to override the configured NPU tree and breaking the documented alternate-tree configuration.
1 open issue
What changed in this PR
This PR adds compile-and-link coverage for the ONNX execution provider’s NPU code without requiring ONNX Runtime, NPU hardware, or the private runtime. It addresses the CI gap described in #917.
Changes:
- Shares NPU sources, include directories, and definitions between the real provider and the CI check.
- Adds a runtime stub and device-free executable to detect compilation and missing-symbol failures.
- Makes
onebitdepend on the check so existing CI builds include it without workflow changes.
| File | Description |
|---|---|
onnx/ep/npu_sources.cmake |
Centralizes the shared NPU build inputs. |
onnx/ep/npu_runtime_ci_stub.cpp |
Supplies runtime symbols for the standalone link check. |
onnx/ep/npu_linkcheck.cpp |
Adds a device-free entry point for the check. |
onnx/ep/CMakeLists.txt |
Uses the shared inputs alongside private runtime sources. |
CMakeLists.txt |
Adds the link-check executable and onebit dependency. |
Review effort: Balanced
…918) `_npu_incs` put the shared include dirs first, and they contain npu/forward/engine-src, so a build that selects another NPU tree with -DONEBIT_NPU_ENGINE_INCS=... (onnx/ep/README.md:39-46, how the shipped engine builds against the private tree) silently compiled the in-tree npu_engine_i8ctx_inc.h instead -- a different I8Ctx and runtime interface than the one the caller chose. Before this PR the configured dirs were first; the refactor into npu_sources.cmake moved them behind the shared ones. Reproduced with an alternate tree whose npu_engine_i8ctx_inc.h is a hard #error: ONEBIT_NPU_ENGINE_INCS=/tmp/alt-tree/... onebit_ep before (shared dirs first): [100%] Built target onebit_ep <- configured tree lost after (configured first): error: #error "ALT-TREE-USED: the configured ONEBIT_NPU_ENGINE_INCS won" The shared dirs stay in the list, after the configured ones, as fallbacks: that is what makes npu/forward/include (q4nx_pack.h, #874) available when a private tree does not carry it. npu_sources.cmake now says the ordering is load-bearing in the place a future edit would break it. Re-verified: default in-tree ONEBIT_EP_NPU=ON configure still builds libonebit_ep.so; the CI target onebit_ep_npu_linkcheck still builds and passes; the host ONNX suite is 6/6.
|
Persistent review updated to latest commit e76573e |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at e76573e (re-verdict of my READY at f2d19ee; the tprs-ready label is valid at this head now).
The Copilot thread was right and the fix is in the right direction: onnx/ep/CMakeLists.txt now lists the caller's ONEBIT_NPU_ENGINE_INCS before the shared fallbacks. I reproduced both orders at their own heads, with an alternate NPU tree whose npu/forward/engine-src/npu_engine_i8ctx_inc.h is a hard #error, and compiled the one TU that includes it (npu/ort/onebit_npu_gemm.cpp, built from the real onebit_ep target):
# f2d19ee (reversed): alt tree is second in -I, so the #error is never reached
-I<wt>/onnx/ep/../../npu/forward/engine-src ... -I/home/bcloud/wt/alt-npu/forward/engine-src
[1/1] Building CXX object ep/CMakeFiles/onebit_ep.dir/.../onebit_npu_gemm.cpp.o -> rc 0
# e76573e (this head): alt tree is first
-I/home/bcloud/wt/alt-npu/forward/engine-src -I/home/bcloud/wt/alt-npu/npu -I<wt>/npu/forward/engine-src ...
/home/bcloud/wt/alt-npu/forward/engine-src/npu_engine_i8ctx_inc.h:1:2: error: #error "alternate NPU tree: the caller's tree must win the include order"
FAILED: ep/CMakeFiles/onebit_ep.dir/.../onebit_npu_gemm.cpp.o
So the configured tree really did lose silently before, and really does win now. The fallbacks still resolve what the alternate tree does not carry: the default configuration (no ONEBIT_NPU_ENGINE_INCS override) builds 7/7 and links ep/libonebit_ep.so at this head with the in-tree tree plus npu/forward/include (q4nx_pack.h) from the shared list.
CI at e76573e: build, Analyze ×5, CodeQL, pr_agent all SUCCESS, hw_gate skipped. The branch is still only the two commits of this PR (5 files, +250/−9).
Nit, not a gate: the root onebit_ep_npu_linkcheck target passes only ONEBIT_EP_NPU_COMMON_INCS, so it cannot catch a reordering regression — an ordering bug has to be found by reading again. If you ever want a machine to hold this, the cheapest form is a second add_executable that includes npu_sources.cmake, sets ONEBIT_NPU_ENGINE_INCS to a fixture dir with an #error header, and is expected to fail configure/compile — awkward in CMake, so a comment in npu_sources.cmake pointing at this thread may be enough. The current comments do say the order matters and why.
|
Persistent review updated to latest commit 723efb7 |
|
Persistent review updated to latest commit d58d0e0 |
|
Persistent review updated to latest commit d7eb994 |
|
Persistent review updated to latest commit 52a7a5c |
|
Persistent review updated to latest commit 81e0913 |
|
Persistent review updated to latest commit 0bf99d8 |
|
Persistent review updated to latest commit e720b1c |

Root cause
npu/ort/onebit_npu_gemm.cpp— and thenpu/forward/engine-src+q4nx_pack.cit pulls in — is built by exactly one configuration in the tree:onnx/epwith-DONEBIT_EP_NPU=ON, which needs ONNX Runtime and the private NPU runtime. CI builds neither, so this leg has never been compiled there. #874 broke it twice while CI stayed green (a call toq4nx_elf_arg_sizes()with no declaration, then the file defining it missing fromonnx/ep's source list), and a device gate found it a week later.The second half is the interesting one: the source list that went wrong existed only inside an ORT-requiring directory, so nothing outside it could compile the same set.
The change (two halves)
onnx/ep/npu_sources.cmake(new)onnx/ep/npu_runtime_ci_stub.cpp(new)npu_rt_api.h; every entry point throws, so a build that ever ran against it fails loudlyonnx/ep/npu_linkcheck.cpp(new)main()for the check; callsonebit::npu::has_kernel(), which is answered from the build's shape list, so it never opens/dev/accelor takes the device lockCMakeLists.txtonebit_ep_npu_linkcheck= that list + the stub, andonebitdepends on it, so the existing CIbuildjob (which namesonebit) compiles and links the leg. No workflow file changesonnx/ep/CMakeLists.txtAn executable link is deliberate: an object-only syntax check cannot see a missing source file (
#874's second half), and a shared library links with undefined symbols by default — which is why the real failure was invisible from both directions.Measured before/after (this box, gcc-16,
-DCMAKE_BUILD_TYPE=Release)Each half of #874 reinstated on purpose, one at a time:
The pushed tree is green on both configurations it touches:
Not covered, deliberately
ONEBIT_NPU_RT_DIR. That is the private runtime; the check substitutes the stub for it, so the knob is still unverified by CI.onebit_ep.cpp's own#ifdef ONEBIT_EP_NPUcode, which needs the ONNX Runtime headers. Install ORT + the runtime in the image and build the leg for real (CI does not compile npu/forward at all (ONEBIT_NPU off), so a PR touching the NPU forward gets a green build without its C++ being built #898's option 2) and this target becomes redundant for the ORT-free half.npu/forward/src/q4nx_pack.cnow compiles in both this check and pi-tissues' #912 (which compilesq4nx_forward.cpp); the two are independent targets for different consumers of the same file, and #912's idiom (add_dependencies(onebit …)) is the one used here.closes #917