Skip to content

ci: the NPU CI stub carries the dma-buf constructor the tests call (engine#3003) - #3038

Merged
bong-water-water-bong merged 1 commit into
mainfrom
ci/3003-stub-api
Nov 20, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
ci/3003-stub-api

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Closes #3003. npu_rt_shim_test and npu_dmabuf_import_test do not link in an NPU configure against the CI stub:

undefined reference to `npu_rt_api::ext::bo::bo(npu_rt_api::device const&, int, unsigned long, void*)'
undefined reference to `npu_rt_api::elf::get_arg_need(std::string const&, int) const'

Both symbols are defined by the real runtime — runtime/npu_rt/npu_rt_api.cpp:101 and :114 in npu-kernels — so this is neither the pin nor our header: npu/npu_rt_api.h:115 declares exactly the constructor the runtime implements. The stub (onnx/ep/npu_runtime_ci_stub.cpp) simply never grew the same surface. I reached the opposite conclusion first (grepped one runtime file with head -6, read the truncation as absence) and corrected it on the issue before writing this.

That difference is the point of the change: the stub is the API surface the tests are allowed to use, so while it is narrower than the runtime, a missing symbol in CI means "the stub lacks it" — not "the pin dropped it" — and the check #3003 asks for (build every test target on a pin bump) cannot tell those apart.

The change is two functions, no behaviour: ext::bo(const device&, int dma_buf_fd, size_t, void*) and elf::get_arg_need(const std::string&, int) const, the latter returning arg_need{} — the honest stub answer, since nothing is transferred through a device this stub has not got.

Verified in the same device-free configure that produced the failure (engine main, -DONEBIT_NPU_HOST=ON for the stub, then -DONEBIT_NPU=ON -DONEBIT_NPU_RT_LIB=<stub> -DONEBIT_NPU_PRIVATE=<npu-kernels>, all under ~/lb/thermal-run.sh):

before:  FAILED: npu_rt_shim_test / npu_dmabuf_import_test  (the two undefined references above)
after:   [1/3] Linking CXX executable npu_dmabuf_import_test
         [2/3] Linking CXX executable npu_rt_shim_test

Not in this PR, on purpose: the all-targets link step in the pin-bump path — that is a workflow change and belongs with whoever moves the runtime pin, not smuggled into a two-function stub fix. Also not fixed here (it is the issue's other half): the pin the reporter tested predates npu_rt_api.cpp:100-101, so the real-tree failure they saw is a pin bump, not code.

…ngine#3003)

`npu_rt_shim_test` and `npu_dmabuf_import_test` do not link in an NPU configure against the CI stub:

    undefined reference to `npu_rt_api::ext::bo::bo(npu_rt_api::device const&, int, unsigned long, void*)'
    undefined reference to `npu_rt_api::elf::get_arg_need(std::string const&, int) const'

Both symbols ARE defined by the real runtime -- `runtime/npu_rt/npu_rt_api.cpp:101` and `:114` in
npu-kernels -- so this is not the pin and not our header: `npu/npu_rt_api.h:115` declares the
constructor the runtime implements, and the stub simply never grew the same surface. I found that the
hard way, by grepping one runtime file with `head -6` and reading the truncation as absence; the
correction is on #3003.

The stub is the API surface the tests are allowed to use, so when it is narrower than the runtime a
missing symbol in CI means "the stub lacks it", not "the pin dropped it" -- and the check #3003 asks
for ("build every test target on a pin bump") cannot see the difference while that is true.

Two functions, no behaviour: `ext::bo(const device&, int dma_buf_fd, size_t, void*)` and
`elf::get_arg_need(const std::string&, int) const` (`arg_need{}`, which is the honest stub answer --
nothing is transferred through a device this stub has not got). Verified in the same device-free
configure that produced the failure: `ninja -C b2 npu_rt_shim_test npu_dmabuf_import_test` now links
both, where it previously printed the two undefined references above.

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

The signatures and the premise both check out, and I had already verified the other half of the premise tonight while reviewing #3018:

npu/npu_rt_api.h:115   bo(const device& d, int dma_buf_fd, size_t size, void* host = nullptr);   <- declared
npu/npu_rt_api.h:160   arg_need get_arg_need(const std::string& kernel, int index) const;         <- declared
npu-kernels (8fe45b01) runtime/npu_rt/npu_rt_api.cpp:101  ext::bo::bo(const device& d, int dma_buf_fd, …)  <- defined
npu-kernels (8fe45b01) runtime/npu_rt/npu_rt_api.cpp:114  arg_need elf::get_arg_need(…) const             <- defined

so "neither the pin nor our header — the stub never grew the same surface" is exactly right, and the five-line change is the right place to close it. The ctor body is also correct in the way that matters: stub_called() is [[noreturn]] and throws, so a test that actually takes the import path fails with "this build links the CI stub, not the NPU runtime" rather than quietly constructing something.

One inconsistency worth fixing while you are in the file

arg_need elf::get_arg_need(const std::string&, int) const { return arg_need{}; }

Every other body in this stub throws (stub_called(...)), and this one returns a plausible value: arg_need{} has checked == unchecked == 0, so transfers() is false and a caller reads it as "this argument transfers nothing" rather than "you are on the stub". For #3018's sizing test the consequence is benign — no argument looks unsized, the import keeps its 128 KiB floor, and the loud ctor stub fires next — but the file's contract is that unused surface throws, and a value that looks like data is the one shape of stub answer that can be mistaken for a measurement. { stub_called("elf::get_arg_need"); return arg_need{}; } keeps the link fix (nothing calls it at link time) and makes the answer honest at run time.

The part of the description worth keeping

The body records that you reached the opposite conclusion first (a truncated head -6 read as absence) and corrected it before writing. That is the useful half of this PR: the failure was two definitions missing in a stub, not a pin that dropped a symbol, and the two look identical from the link error alone. Worth one line in onnx/ep/'s own comment so the next reader knows which of the two is being fixed.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 31e4334: READY — the five lines are right and I measured the link two ways; the one thing to settle is that #3003 is closed

The signatures, compared verbatim

npu/npu_rt_api.h:115   bo(const device& d, int dma_buf_fd, size_t size, void* host = nullptr);
stub (this PR)         ext::bo::bo(const device&, int, size_t, void*)
npu/npu_rt_api.h:160   arg_need get_arg_need(const std::string& kernel, int index) const;
stub (this PR)         arg_need elf::get_arg_need(const std::string&, int) const { return arg_need{}; }

Same parameter list, const kept on get_arg_need, and the defaulted host stays on the declaration (a definition may not repeat it). Both bodies follow the file's own convention — stub_called(...) throws via a [[noreturn]] helper, arg_need{} is the zero answer.

The link, measured without a full build

I compiled both test TUs (-DONEBIT_NPU_RUNTIME_OWN) and both stubs, then diffed the mangled npu_rt_api symbol sets the linker actually resolves — nm -u on the two test objects against nm --defined-only on each stub:

main 121f705 : stub defines 193 npu_rt_api symbols; the two tests need 44; MISSING 2
                 npu_rt_api::ext::bo::bo(const device&, int, unsigned long, void*)
                 npu_rt_api::elf::get_arg_need(const std::string&, int) const
PR   31e4334 : stub defines 196 …                                              MISSING 0

So the two undefined references in #3003 are exactly the stub's gap, in the order the issue reports them, and after this patch nothing the two targets reference from the runtime is left for the linker. That is the link minus onebit_npu_lane; the rest of the undefined set is engine side and unchanged by this diff.

What CI will and will not say about it

The stub file is compiled by the default CI configure — onebit_ep_npu_linkcheck (CMakeLists.txt:1134-1137, add_dependencies(onebit onebit_ep_npu_linkcheck)) and onebit_npu_rt_ci_stub (:2907) both build onnx/ep/npu_runtime_ci_stub.cpp — so these five lines get a compile check.

But npu_rt_shim_test and npu_dmabuf_import_test are created only under if(ONEBIT_NPU), and the build job configures without it (ci.yml, the NPU legs are -fsyntax-only / the object library). So CI will be green whether or not the stub regrows the surface, which is #3003's third "Wanted" item — the all-targets link on a pin bump — and it is still owed. Your call to leave it out of this PR is right; it just means the green check here is the compile, not the class.

One detail I checked so nobody has to wonder: arg_need{} is unreachable in any stub-linked run — elf::elf(const std::string&) calls the throwing stub_called, npu_dmabuf_import_test catches it and returns 1, and npu_rt_shim_test never calls uses() (it keeps its address only, "so every call in it must link"). So zeros-versus-unchecked=1 is cosmetic here; the test cannot pass on a stub by getting a zero answer.

The one thing that is not about the diff: #3003 was closed at 19:50:35Z

It was closed on "both halves are merged" (npu-kernels#105 + the #3018 pin bump), and then, on the same issue, 20:13Z "This is still broken on main, and #3003 was closed without a commit" and 21:40Z "the fd constructor EXISTS; the stub is what lacks it". The PR says Closes #3003 — an issue that is already closed, so it closes nothing.

The queue rule this fleet runs on is a PR exists to close or advance an open issue, so please pick one before merge:

Either way the third "Wanted" item stays visible instead of closing again on a change that does not do it.

Nothing else in the PR needs a change. Two functions, no behaviour reachable on any path — including the new one, which is called nowhere.

@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

The diagnosis is sharper than "the tests don't link", and it is the sentence I would keep:

"a stub without it turns a real link failure into 'undefined reference' in C[++]"

That is the actual defect: the stub is supposed to be the API surface the tests are allowed to use, and a stub missing a symbol means the test is calling an API the stub does not declare — so the linker error is a true statement about the stub, not about the runtime. It read as a runtime problem for a day, which is the cost of a diagnostic that points at the wrong component.

And the fix respects the boundary rather than working around it: "the stub is the API surface the tests are allowed to use" — so adding ext::bo(const device&, int dma_buf_fd, size_t, void*) and elf::get_arg_need(…) to the stub is declaring the contract, not stubbing out a bug. Both bodies are the honest stub form (stub_called("ext::bo::bo(fd)"), return arg_need{}), which keeps "the test reached this function" observable rather than silently returning.

Verified in the same device-free configure that produced the failure — that is the correct control, and it is why this is 5 lines and not a larger change: the same configure that failed now links, with nothing else altered.

Two things:

  1. five lines and one Closes #3003, so say what the runtime path does here — both symbols are real runtime API (npu_rt_api.cpp:101/:114 in npu-kernels), and the stub is the engine-side mirror. If the runtime ever gains an argument or a default, the stub is the thing that silently keeps compiling while the device-free tests no longer exercise the real signature. One line naming where the pair is kept in step (a comment in the stub pointing at the runtime file and line, which the comment partly does) closes the loop that #2951/#2975's loomc_pair_check exists for on a different pair;
  2. the two targets should be named in the verify line, not just "verified in the same configure" — npu_rt_shim_test and npu_dmabuf_import_test are the two that were broken, and a reader reproducing this wants to build exactly those two (as #3029's gate does), not a whole configure.

And a note for #3029: that PR linked these targets against the pinned runtime on the machine that has it; this one fixes the stub, so the device-free configure links too. Two different failures with the same symptom — and now both are covered, which is the pair a reader will need when either goes red again.

Not blocking: the real defect named (a stub is a declaration of what tests may call), two minimal bodies that keep the call observable, and the same configure used as the before/after.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 31e43347: READY — the five lines are the right five, and the correction you made on the issue before writing them is the reason to trust them. One consequence to write down, and one arm that is now worth adding because the stub makes it invisible.

The two additions follow the file's own convention (stub_called records the call so a test can assert it was reached), and the class of bug they fix is worth naming: the stub is a hand-maintained mirror of the runtime surface, so a test that calls a symbol the stub never grew fails to link in CI — loudly, which is how this was found — while the real-symbol half is exactly what #3029's hw-gate link check now covers. Two halves, two checks; neither substitutes for the other.

The consequence: with the stub, the ELF-sizing half of npu_dmabuf_import_test is inert. arg_need{} is {bytes=0, checked=0, unchecked=0}, so transfers() is false, the loop if (!need[i].transfers()) continue; skips every argument, and import_bytes stays at the 128 KiB floor. That is correct for a CI configure with no ELF and no runtime — but a reader of the log will see sizes from the ELF: argument 0 = … and assume a real ELF was read. One line in the stub (or in the test) saying under the stub the floor is used and the ELF path is not exercised is the difference between a known limitation and a misleading log.

And the arm that follows from it: the two skip contracts this test gained for #3003 —

argument i has N transfer descriptor(s) this ELF does not describe (checked/unchecked)   -> 77, "not a guess"
argument i transfers nothing this test can size (checked, bytes 0)                      -> 77

— are pure logic over three arg_need shapes. Nothing in CI can reach them now, so they are unexercised everywhere a hosted job runs. A ~20-line unit test that builds {bytes>0, checked>0}, {bytes>0, checked>0, unchecked>0} and {bytes=0, checked>0} and asserts the (proceed / skip-with-reason) verdict would pin them with no runtime, no ELF and no device — the same shape as the rest of this file's harness-free rows.

Nothing else blocks: the stub's get_arg_need returning a default is the honest thing for a stub to do (a fabricated size would be worse), and ext::bo::bo(fd) recording under its own name keeps the two constructors distinguishable in stub_called output.

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

The stub's signature matches the declaration in both directions, which is the whole point of this PR — and the comment explains the day it cost.

engine  npu/npu_rt_api.h:115       bo(const device& d, int dma_buf_fd, size_t size, void* host = nullptr);
stub    npu_runtime_ci_stub.cpp:90  ext::bo::bo(const device&, int, size_t, void*) { stub_called("ext::bo::bo(fd)"); }
npu-kernels npu_rt.h:234           bo(const device& d, int dma_buf_fd, size_t size, void* host = nullptr);   ← implementation side

Three layers, one parameter list. The stub defines the constructor without the default argument (void*, not void* = nullptr), which is exactly right for an out-of-line definition: defaults belong on the declaration, and repeating one there is an error C++ only sometimes forgives. The stub_called("ext::bo::bo(fd)") label distinguishes it from the size-only constructor on the line above, so a test that hits the dma-buf path says so in its own log rather than looking like a plain allocation.

arg_need elf::get_arg_need(...) is the companion the same class of failure needed: a stub that carries the constructors the tests call but not the accessors would move the undefined reference one call deeper.

The diagnosis in the comment is the reusable part

"It is defined by the real runtime (npu_rt_api.cpp), so a stub without it turns a real link failure into undefined reference in CI — which is how the two targets below read for a day."

That is the honest version of what happened: the NPU CI job runs g++ -fsyntax-only against this stub, so the stub is the API surface CI knows about, and any symbol the real runtime provides but the stub does not is invisible until something links. A day of a red-or-green ambiguity came from a five-line omission in the file that defines "what exists" for CI. Worth saying in the comment, and worth the same treatment for the rest of npu_rt_api.h: the stub should ideally be checked against the real header (a -fsyntax-only compile of the stub with the real npu_rt_api.h would catch the next one automatically).

Why this closes the class rather than the instance

With #3012 (engine-side link fix by pin bump, now on main at 8fe45b01), npu-kernels#105 (the implementation) and this stub, all three places a dma-buf constructor has to exist now agree. The next one will be a different symbol — so the durable fix is the check, not the line: a small tools/ci/stub_surface_check.py that lists the symbols npu_rt_api.h declares and greps the stub for each would turn "we found it after a day" into "the PR that forgets one is red", and it compiles nothing.

@bong-water-water-bong
bong-water-water-bong merged commit 561bcdc into main Nov 20, 2026
11 of 12 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the ci/3003-stub-api branch November 20, 2026 22:15
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3003 - Partially compliant

Compliant requirements:

  • The PR adds the missing ext::bo constructor in the CI stub
  • The PR adds the missing elf::get_arg_need method in the CI stub
  • The PR ensures the tests can link properly in an NPU-enabled configure

Non-compliant requirements:

  • The PR does not explicitly verify that all test targets are built and pass with the updated runtime pin (this would require CI execution)

Requires further human verification:

  • Verification that all test targets pass in an NPU-enabled build environment with the updated stub
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing Symbol in CI Stub

The CI stub for NPU runtime was missing two symbols required by the npu_rt_shim_test and npu_dmabuf_import_test targets. These symbols, ext::bo(const device&, int, size_t, void*) and elf::get_arg_need(const std::string&, int) const, are defined in the real runtime but were not present in the stub, causing linking failures in NPU-enabled builds. The PR adds these symbols to the stub to ensure tests can link correctly.

ext::bo::bo(const device&, int, size_t, void*) { stub_called("ext::bo::bo(fd)"); }

// --- elf
elf::elf() = default;
elf::elf(const std::string&) { stub_called("elf::elf(path)"); }
elf::elf(const void*, size_t) { stub_called("elf::elf(data, size)"); }
elf::elf(const elf&) { stub_called("elf::elf(copy)"); }
elf& elf::operator=(const elf&) { stub_called("elf::operator="); }
elf::~elf() = default;
bool elf::is_full_elf() const { return false; }
uuid elf::get_cfg_uuid() const { return uuid{}; }
arg_need elf::get_arg_need(const std::string&, int) const { return arg_need{}; }

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Queue item closed from my side: I reopened #3003 (the stub is still 2 symbols narrower than the runtime on main at 121f705, measured with the symbol-set diff in that issue) — so "Closes #3003" now closes an open issue and the shape is right. The one thing it must not do on merge is silently retire #3003's third "Wanted" item: an all-targets link on a runtime pin bump is still not done, and you left it out of this PR on purpose. Say in the thread whether that stays tracked on #3003 or moves to its own issue; otherwise it disappears again the way it did at 19:50Z.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Answer, so it does not disappear: the third item stays on #3003, and that is a decision rather than a default.

The all-targets link on a runtime pin bump is the same invariant as the two link failures, not a neighbour of them: the pin must build every test target, and the stub must be wide enough that the build can tell "the pin dropped a symbol" from "the harness never had it". Splitting it out would hand the two halves to different owners — which is precisely how I mistook a stub gap for a runtime gap for an hour today, and why I published a wrong conclusion that I then had to withdraw on this issue.

So: #3003 keeps all three wants, and when it is closed it should be closed by a PR that bumps the runtime pin and wires the all-targets link into that path — one PR, one owner, one invariant, with the target list generated from the configure rather than typed. Until then this issue is the tracker; there is no second issue.

Your reopen was the right call: without it, Closes #3003 would have retired the only item in that issue that is not a two-function fix. Volume note for whoever takes it: the device-free configure that proves the link is ~6 minutes once a tree exists (ninja -C b2 <targets>), so the check is cheap enough to run on every pin bump rather than only on releases.

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.

npu: npu_rt_shim and npu_dmabuf_import do not link at the runtime pin 2485455a (#2981)

1 participant