Skip to content

docs: zero-copy on the serving paths — every copy left, priced, with the one dma-buf rule (refs #698) - #1271

Merged
bong-water-water-bong merged 2 commits into
mainfrom
1bit/zero-copy-audit
Nov 6, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
1bit/zero-copy-audit

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Target 4 of engine#698 asks for the audit "so the owner can see what is left". It existed only in
~/briefs/TZEROCOPY-STATE.md — a lane's state file, not where the next agent looks. This PR puts it in the tree:
docs/zero-copy.md, the map, the four targets' status, and the audit table with a reason per row. Refs #698
(targets 2 and 3 are still open — see the comment on the issue).

What the page carries

  • Target 1 (shipped, opt-in ONEBIT_KV_SHARE=1), priced against the route it replaces:

    same box, same model file route shared region
    27B hybrid, 307 / 4 096 / 16 384 prompt tokens 28.82 / 61.82 / 198.53 ms 0.048-0.258 ms, 0 bytes, flat in prompt length
    30B-A3B, same three lengths 8.22 / 68.29 / 242.86 ms same

    256 cells in 0.048 ms, 768 in 0.107, 2 048 in 0.25 — cells bookkeeping, not bytes. Greedy text identical to
    --device hrx on every arm was the gate; no tolerance is involved.

  • The audit (docs/zero-copy.md, "The audit"): ten rows, each with bytes/token, ms/token and why it stays.
    The two conclusions are written as decisions rather than leftovers:

    • rows 1-4 (A stage 50 ms, readback 9 ms) are ~1.5 % of a measured 1 330 ms token, so target 2's honest
      ceiling is a few percent. The lever that pays is the 128-row pad (the shipping container registers 0
      kernel roles at M=16) and the 368 launches — NPU-runtime work, not a transport fix.
    • row 6 (GDN recurrent state, 604 MB/token of host read+write, part of a 190 ms "host-inside-layers"
      row) is the biggest single cost and no memory recipe removes it: it is arithmetic, and only moving the
      recurrence into a kernel changes the number.
  • The one rule the dma-buf issues turned up, so it is not rediscovered: sharing works both ways
    (29.3 GB/s through the shared mapping against 14.0 GB/s copy-then-read; capture in 0.044 ms, import 0.206 ms),
    NPU execution on an imported range is byte-identical when the packet addresses the exporter's mapping, and
    it fails Populate ranges failed, ret -14 when the address comes from mmap of the import through amdxdna,
    because that invalidates the mapping and the client-wide population step then refaults it through HMM.

Notes

  • Docs only: README.md gains the one-line index entry, docs/hybrid.md points at the price page next to the
    route it describes, and docs/zero-copy.md is new with the full Apache notice (tools/copyright.py --check
    clean). No code, so no build or device gate applies; every relative link and every quoted repo path in the new
    page was checked to resolve.
  • Nothing is claimed that was not measured here: the ONNX EP row is marked not measured per-call, and target 3
    says so in the status table.
  • No device was used. Kernel internals are not in the page: target 2's and row 6's fixes live in the private
    trees, and the page says that rather than linking into them.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

#1271 ready for review at c2516c60aac50738602ff98555b35ce637ebdb6d — MERGEABLE, docs only, 3 files, +159/−0: docs/zero-copy.md (new, full Apache notice), the README.md index line, and two lines in docs/hybrid.md pointing at the price page next to the route it describes. No code, so no build or device gate applies; tools/copyright.py --check clean, every relative link and every quoted repo path checked to resolve. Refs #698 (target 4 — targets 2 and 3 are still open, listed in the issue comment).

…serving paths, priced

engine#698's target 4 asks for the audit "so the owner can see what is left"; it existed only in a lane
state file, which is not where an agent looks next. This page is that audit plus the status of the four
targets, and it carries the one rule the two dma-buf issues turned up (address the exporter's mapping; an
mmap of the import through amdxdna invalidates it and the next submit EFAULTs).

Every number is one this lane measured on Strix Halo and each names its source: the file route at
28.8/61.8/198.5 ms (27B hybrid) and 8.2/68.3/242.9 ms (30B-A3B) against 0.048-0.258 ms for the shared
region, the NPU runtime's A stage 50 ms and readback 9 ms inside a 1 330 ms token, the lm head 180 ms, and
the 604 MB/token GDN sweep that no memory recipe removes. Two conclusions are written as decisions: the
host-side copies are ~1.5 % of that token, so target 2's honest ceiling is a few percent and the lever is
the M=128 pad and the launch count; and row 6 is host arithmetic, not a copy.

No code changes. Refs #698 (target 4), and it is where #812's and #753's preconditions now live engine-side.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Corrected handoff sha (one amend after I checked the page's arithmetic): #1271 ready for review at bc5dc8c7d2ce226c4f6643094039148e3dcd3a68 — MERGEABLE, docs only, 3 files, +159/−0. Same content; the two edits were a double-counted sum in the "~59 ms" line (rows 2 and 4 are inside rows 1 and 3, so they do not add) and one bit of jargon in the LM-head row.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

698 - Partially compliant

Compliant requirements:

  • Target 4 audit table is created and placed in docs/zero-copy.md
  • The audit table includes measurements taken on the hardware (Strix Halo)
  • The documentation is updated in the same PR as the behavior it describes

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing Hardware Measurements for Target 3

The documentation mentions that Target 3 (ONNX EP IO binding onto BO memory) is priced but not measured per-call on this box. While it's noted that ORT IO binding exists and is unused, the lack of actual measurement makes it difficult to assess the true cost of this target. The PR should either include measurements or clarify why they were not taken.

## Target 3 — the ONNX execution provider's boundary

The EP reads and writes `OrtKernelContext` in place inside its own host nodes, and copies at the node boundary
(`DT_CopyTensors`, `onnx/ep/onebit_ep.cpp:206`): per fused QDQ GEMM node, an `M x K` f32 input and an `M x N`
f32 output — 20 KB + 0.6 MB per node for a 0.6B decode step at M=1. ORT's IO binding would let inputs and
outputs live in BO-backed `OrtValue`s and remove the boundary copies entirely; it exists in the ORT version
this tree builds against and nothing calls it. Not measured per-call on this box: the numbers above are the
bytes, and the per-call cost is what target 3 owes.
Incomplete NPU Provider Implementation

The documentation states that the NPU is not yet the provider that writes the shared region, which is a key requirement for fully realizing Target 1. This limitation means that the full benefits of the zero-copy KV handoff are not yet available, and the implementation is incomplete. This should be clearly communicated.

What is **not** proven: the NPU is not yet the provider that writes that region (the provider in the gate
above prefills with the CPU). That needs an NPU-side K/V writer — kernel work in the private tree, tracked in
engine#753, which is parked until that writer exists.

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.

1 participant