Repository navigation
npu: execute on an imported dma-buf -- the engine's arm, and the claim it settles (engine#753) - #2037
Conversation
…m it settles (engine#753) The issue says zero-copy execution cannot work because XRT cannot bind a foreign dma-buf as a kernel argument. That is no longer true in this tree: npu/npu_rt_api.h declares `ext::bo(const device&, int dma_buf_fd, size_t, void* host)`, the private runtime imports the fd with DRM PRIME and pins those pages, and npu-kernels#39 already runs kernels with one. What was missing was any arm *in this tree*: the shim test covered `ext::bo(dev, size)` only, and the fd constructor appeared solely in a link-coverage function that is never called. Two changes: - `tests/npu_rt_shim_test.cpp`: the fd constructor joins the link-coverage surface, so a runtime library that lacks it now fails to LINK rather than at the first hybrid call site. - `tests/npu_dmabuf_import_test.cpp`: the executing arm. A dma-buf with no GPU in the path (a sealed memfd handed to /dev/udmabuf), imported with the EXPORTER'S mapping, then **bound as kernel argument 0 and run**. Measured under one npu-hold ticket (queue waited 440 s at a 70 C die, command 1 s): ok a dma-buf exists with no GPU in the path (udmabuf over a sealed memfd) ok ext::bo(dev, fd, size, host) accepts it ok the imported BO is the dma-buf's size ok map() IS the exporter's mapping (a second mapping puts the BO on the driver's invalid list and the next submit HMM-faults) ok a write through the exporter's mapping is visible through the imported BO (one buffer, not a copy) ok host = nullptr constructs (so the trap is at SUBMIT, not at construction) (no throw) ok and it is a SECOND mapping, not the exporter's -- the state npu_rt.cpp says the next submit faults on ok the imported BO is accepted as kernel argument 0 (no throw) ok and the run with it completes (COMPLETED) all npu dmabuf-import checks passed The last two lines are the claim: an imported buffer is not merely mappable, it is submit-able -- the binding is where the issue said execution failed. One correction that only the device run could produce: my first version asserted that `host = nullptr` *throws*, because the header's comment reads as if the driver's own mapping is refused at construction. It constructs fine and hands back a second mapping; the documented fault (amdxdna_insert_pages -> amdxdna_mark_mapp_invalid, then an HMM fault on the next submit) is at submit time. The arm now asserts the observable precursor and deliberately does not court the wedge to watch the fault -- a test that wedges the array to observe a documented failure is a bad trade. Skips (77) without a kernel ELF, so a box with none registers a skip rather than a red row. Refs engine#753
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at c404ea4
"Its premise needed correcting first" is the strongest thing a PR can open with, and the correction is specific: "XRT can bind a foreign dma-buf in this tree. The issue was right when it was filed; two days of merged work made it stale, and the difference deci[des …]"
An issue whose premise has expired is more dangerous than one that is wrong, because the work built on it inherits a false constraint — here, "this cannot work" would have justified a copy that the engine no longer needs. Checking the premise against the current tree before writing the arm is the step that saved the work.
So what lands is the engine's arm plus the claim it settles — Closes #753 with a demonstration rather than an argument, on a dma-buf the engine did not allocate. That is the shape needed for #1750's neighbour and for the NPU split questions: a claim about what the runtime can do, settled by doing it.
One ask: state the XRT version and the driver/plugin that make the foreign bind work, because "XRT can bind a foreign dma-buf" is a property with a floor — the next person on an older stack will read this as unconditional, and the failure they see (a silent copy or an error) will not point at the version.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
Closes #753, and its premise needed correcting first: XRT can bind a foreign dma-buf in this tree. The issue was right when it was filed; two days of merged work made it stale, and the difference decides what was actually missing.
Where the claim stands now
npu/npu_rt_api.h:106-115—ext::bo(const device&, int dma_buf_fd, size_t, void* host = nullptr), mechanism in the commentnpu_rt_api.cpp:101→ rawDRM_IOCTL_PRIME_FD_TO_HANDLE+GET_BO_INFOkvwrite-region:ext::bo cache(dev, region.fd, region.bytes, region.map), then sub-windows passed to a kernelnpu-holdalone, and again by the semantic gateWhat was missing was nothing in the engine that calls it:
git grepovermainfinds no BO built from an fd, and the shim test coveredext::bo(dev, size_t)only — the fd constructor appeared solely insideuses(), a link-coverage function that is never called.What this adds
tests/npu_rt_shim_test.cpp: the fd constructor joins the link-coverage surface, so a runtime lacking it fails to link rather than at the first hybrid call site.tests/npu_dmabuf_import_test.cpp: the executing arm — a dma-buf with no GPU in the path (sealed memfd →/dev/udmabuf), imported with the exporter's mapping, then bound as kernel argument 0 and run.Measured under one
npu-holdticketQueue waited 440 s at a 70 C die; the command itself took 1 s; the ticket was released on exit.
The last two lines are the claim: an imported buffer is not merely mappable, it is submit-able — binding is exactly where the issue said execution failed.
One correction only the device run could produce
My first version asserted
host = nullptrthrows, because the header's comment ("nullptr asks for the driver's own mapping, which the driver then marks invalid") reads as if that is refused at construction. It does not throw: it constructs and hands back a second mapping, which is the state that makes the next submit HMM-fault (amdxdna_insert_pages→admxdna_mark_mapp_invalid). The arm now asserts that observable precursor and deliberately does not court the wedge to watch the documented fault — wedging the array to observe a known failure is a bad trade. The header comment could say "at the next submit" explicitly; that is a one-line follow-up rather than part of this PR.Not run / not claimed