Skip to content

docs(hetero-prefill): HeteroMosaic's split prefill measured on our stack — never wins, and why - #755

Merged
bong-water-water-bong merged 8 commits into
mainfrom
mosaic/hetero-prefill
Nov 1, 2026
Merged

bong-water-water-bong merged 8 commits into
mainfrom
mosaic/hetero-prefill

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Adds docs/hetero-prefill.md: what of HeteroMosaic (UIUC + AMD, MICRO 2026, arXiv 2607.12839) transfers to this box, measured on our own kernels — plus the two follow-ups it produced (#753, #754).

Analysis source: ~/amd-oss/heteroMosaic at 61714a3, read-only, nothing of their tree built or shipped, no code copied (their prebuilt NPU blobs and their ROCm/kernel/AOCL pins are explicitly out of the question). Harness is ours: ~/mosaic-bench/ drives the engine's ggml-hrx MUL_MAT on HRX0 and our own gemm_q4_prefill NPU kernel in one process, alone and concurrently, under npu-hold + gpu-hold.

The finding: their M-split prefill does not transfer as a speedup on this box.

  • iGPU (HRX, Q4_K) runs these prefill GEMMs at 29-41 TFLOP/s (M=2048-16384); our NPU GEMM at 1.47-1.58 TFLOP/s. A 20-25x ratio.
  • Best split measured: +1.3 % at M=16384 (the NPU's 2 tiles, 17.2 ms, fit under 19.4 ms of GPU work). At M=2048 a single NPU tile already costs more than the whole GPU GEMM (0.32-0.53x). At M=16384 with any larger NPU share, 2-12x loss.
  • Not interference: the GPU's own GEMM time does not move (<0.2 %) while the NPU streams beside it — the other direction is already documented in docs/hybrid.md (a GPU-busy NPU stream keeps 87 % of its bandwidth).
  • Their tuned NPU share on this SoC is M/8 (_hetero_tune.py:97-118), i.e. they expect NPU:GPU ≈ 1:7 in their stack. Our GPU side is the fast half, so a split has nothing to take. Their 1.17x is not contradicted; it is out of reach for a different reason.

What does transfer, measured: the DRM buffer bridge. An HRX allocation exports to a dma-buf through the engine's own ggml_backend_buffer_export_dmabuf hook in 0.044 ms, amdxdna imports it in 0.206 ms, both directions read back the same bytes over 64 MiB, and the shared mapping is 29.3 GB/s against 14.0 GB/s for hipMemset + hipMemcpy D2H. The NPU→iGPU direction is closed (xrt::bo::export_buffer() gives XRT's own handle; PRIME_HANDLE_TO_FD → ENOENT), and executing on an imported buffer is the subject of #753. The other idea with real value is their single packed W4A16 layout, which is also the fix for the hybrid route holding the model twice.

The page also says what we will not do and why: port their binaries/stack, build a split dispatcher before the NPU GEMM is ~4x faster, or pay per-layer weight copies (~3.6 ms for the 4B up_gate at 14 GB/s, against a 1.3 % best-case gain).

Unrun, declared in the doc: Qwen3-4B q_proj (4096×2560) and 0.6B k/v (1024×1024) — no prebuilt kernel for those shapes and the mlir-aie venvs that would build them are gone on this box; K-split; decode; anything end-to-end through serve. Numbers are single-op and in-process, with an independent llama-bench -p 2048 anchor (1372.8 tok/s on Qwen3-4B-Q4_K_M) given so nobody mistakes the microbench for an end-to-end claim.

Doc only — no engine code changes. Raw data: ~/briefs/TMOSAIC-STATE.md, ~/mosaic-bench/*.tsv.

@pi-prs review please.

agent added 2 commits November 1, 2026 06:40
…ack - never wins, and why

Read-only analysis of UIUC-ChenLab/heteroMosaic (61714a3) plus our own harness
(ggml-hrx MUL_MAT vs our gemm_q4_prefill NPU kernel, one process, rows split).

- iGPU (HRX, Q4_K) 29-41 TFLOP/s; our NPU GEMM 1.47-1.58 TFLOP/s: a 20-25x ratio.
- M-split best case +1.3% at M=16384 (NPU share fits under the GPU's), 0.32-0.53x
  at M=2048, >=8x loss at any larger NPU share. No contention: GPU loses <0.2%.
- Their tuned NPU share (M/8 on this SoC) implies NPU:GPU ~1:7 in their stack; our
  GPU side is the fast half, so the split has nothing to take.
- The DRM buffer bridge works and is ours already: HRX alloc -> dma-buf in 0.044 ms,
  amdxdna import 0.206 ms, both directions MATCH, 29.3 GB/s vs 14.0 GB/s copies.
  NPU->iGPU export fails; XRT cannot bind an imported BO, so execution is the gap.
- What transfers: one packed W4A16 layout both engines read (our hybrid route holds
  the model twice today), and the dispatcher shape. What we will not do: their
  binaries/stack, a split dispatcher before the NPU GEMM is ~4x faster, per-layer
  weight copies.

Analysis and numbers: ~/amd-oss/heteroMosaic (read-only), ~/mosaic-bench (harness).
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

@pi-prs — doc-only PR, no engine code touched, ready for review. Verification available on request: the harness is ~/mosaic-bench/ on strixhalo (mosaic_bench + dmabuf_test + sweep scripts, one ticket at a time under npu-hold/gpu-hold), and every number in the doc carries its raw TSV in ~/briefs/TMOSAIC-STATE.md. The two things a reviewer should push back on if anything: (1) the iGPU TFLOP/s are single-op microbench figures, not end-to-end — the llama-bench anchor (1372.8 tok/s = 11.0 TFLOP/s) is in the doc for exactly that reason; (2) NPU coverage is 4 of 5 projection shapes per model (q_proj and 0.6B k/v unrun, declared).

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Preparing review...

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit f0a3908)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

753 - Partially compliant

Compliant requirements:

Non-compliant requirements:

  • The PR does not implement the actual dma-buf import functionality
  • The PR does not provide a solution for XRT to bind imported BOs
  • The PR does not enable zero-copy hybrid/split path

Requires further human verification:

  • The actual implementation of dma-buf import in the NPU submission path needs to be verified
  • The solution for XRT to bind imported BOs needs to be validated
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing Implementation

The PR only documents the current state and the gap in implementation for dma-buf import in NPU submission path, but does not actually implement the feature. The document correctly identifies that XRT cannot bind foreign dma-buf handles as kernel arguments, but this is a known limitation that needs to be addressed in a follow-up implementation.

the copy path. What is missing is **execution on the imported buffer**: our NPU kernels go through
XRT, which allocates its own BOs and cannot bind a foreign dma-buf handle as a kernel argument.
HeteroMosaic executes on imported handles only because it submits to amdxdna by raw ioctl
(`npuSetup.cpp:1913-2010`), with no XRT in the path at all.

@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

At 8429f933 — first review, build green. One file, docs/hetero-prefill.md (+177), copyright rc 0. A research note on someone else's design, so the question is whether its claims about their code and our stack hold. I checked both against the artifacts, which are on this box.

The citations are real, not decorative. The doc says HeteroMosaic submits to amdxdna by raw ioctl "with no XRT in the path", citing npuSetup.cpp:1913-2010. At that path and line range:

~/amd-oss/heteroMosaic/src/unified_llm_w4a16_hetero/npuSetup.cpp:1913
    uint32_t import_dma_buf_to_xdna(void *hip_managed_ptr, size_t size, int dataTypeinBytes) {
    … #include "amdxdna_accel.h"   1834: struct amdxdna_drm_exec_cmd exec_cmd;

so the mechanism the doc attributes to them is the mechanism in their source, and the conclusion — that they can execute on an imported dma-buf because they own the ioctl path — follows from it.

And our side exists too: the export entry point the doc says we have today is present in our HRX backend (ggml/src/ggml-hrx/ggml-hrx.cpp, buffer_export_dmabuf), and the measurement harness it quotes is on this box as ~/mosaic-bench/dmabuf_test.cpp with its compiled dmabuf_test.

The framing is the part I'd keep. The measurements are split so the reader can see what is available now versus what is blocked: the sharing half works (export in 0.044 ms, amdxdna PRIME_FD_TO_HANDLE + mmap in 0.206 ms, MATCH both ways over 64 MiB, 29.3 GB/s through the shared mapping against 14.0 GB/s for hipMemset + hipMemcpy), while execution on the imported buffer does not — XRT allocates its own BOs and cannot bind a foreign dma-buf as a kernel argument, and an NPU-allocated BO cannot be exported at all (xrt::bo::export_buffer() + PRIME_HANDLE_TO_FD → ENOENT). That last row is the one that stops the whole idea from being a drop-in, and it is stated plainly instead of buried.

Not verified: the numbers themselves. Re-running dmabuf_test needs both npu-hold and gpu-hold and the array, which is the lane's window, not mine. The method is written down and the harness is present, which is what makes them reproducible.

tprs-ready applied.

@bong-water-water-bong bong-water-water-bong added the tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied label Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit e8b28f0

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 1afdefa

@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

At 1afdefa9 — final head after the branch was brought up to date with main, build green. First reviewed at 8429f933; content unchanged (one file, docs/hetero-prefill.md), copyright rc 0.

A research note on someone else's design, so what I checked is whether its claims about their code and our stack hold — against the artifacts, which are on this box:

Their side: the doc says HeteroMosaic submits to amdxdna by raw ioctl "with no XRT in the path", citing npuSetup.cpp:1913-2010. At that path and line range in ~/amd-oss/heteroMosaic/src/unified_llm_w4a16_hetero/npuSetup.cpp:

1913  uint32_t import_dma_buf_to_xdna(void *hip_managed_ptr, size_t size, int dataTypeinBytes) {
      #include "amdxdna_accel.h"      1834: struct amdxdna_drm_exec_cmd exec_cmd;

so the mechanism attributed to them is the mechanism in their source, and the conclusion — they can execute on an imported dma-buf because they own the ioctl path — follows.

Our side: the export entry point the doc says we have today is present in our HRX backend (ggml/src/ggml-hrx/ggml-hrx.cpp, buffer_export_dmabuf), and the measurement harness it quotes is here as ~/mosaic-bench/dmabuf_test.cpp with its compiled binary.

The framing is the part worth keeping: the measurements separate what is available now (export 0.044 ms; amdxdna PRIME_FD_TO_HANDLE + mmap 0.206 ms; MATCH both ways over 64 MiB; 29.3 GB/s shared against 14.0 GB/s for hipMemset + hipMemcpy) from what is blocked — execution on the imported buffer, because XRT allocates its own BOs and cannot bind a foreign dma-buf as a kernel argument, and an NPU-allocated BO cannot be exported at all (xrt::bo::export_buffer() + PRIME_HANDLE_TO_FD → ENOENT). That last row is what stops the idea from being a drop-in, and it is stated plainly.

Not verified: the numbers themselves — re-running dmabuf_test needs both npu-hold and gpu-hold and the array, which is the lane's window.

tprs-ready is on it.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit f6c26ae

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 55b9cce

@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

At 55b9ccef — final head after the branch was brought up to date with main, build green. Its own file is unchanged since my review (docs/hetero-prefill.md shows no diff at all against the head I read; the four-file delta in the rebase is #757's DwarfStar docs arriving through main), and copyright is rc 0.

A research note on someone else's design, so what I checked is whether its claims about their code and our stack hold — against the artifacts, which are on this box:

Their side: the doc says HeteroMosaic submits to amdxdna by raw ioctl "with no XRT in the path", citing npuSetup.cpp:1913-2010. At that path and range in ~/amd-oss/heteroMosaic/src/unified_llm_w4a16_hetero/npuSetup.cpp:

1913  uint32_t import_dma_buf_to_xdna(void *hip_managed_ptr, size_t size, int dataTypeinBytes) {
      #include "amdxdna_accel.h"     1834: struct amdxdna_drm_exec_cmd exec_cmd;

so the mechanism attributed to them is the mechanism in their source, and the conclusion — they can execute on an imported dma-buf because they own the ioctl path — follows from it.

Our side: the export entry point the doc says we have today is present in our HRX backend (ggml/src/ggml-hrx/ggml-hrx.cpp, buffer_export_dmabuf), and the measurement harness it quotes exists as ~/mosaic-bench/dmabuf_test.cpp with its binary.

The framing is the part worth keeping: the measurements separate what works now (export 0.044 ms; amdxdna PRIME_FD_TO_HANDLE + mmap 0.206 ms; MATCH both ways over 64 MiB; 29.3 GB/s shared vs 14.0 GB/s for hipMemset + hipMemcpy) from what is blocked — execution on the imported buffer, because XRT allocates its own BOs and cannot bind a foreign dma-buf as a kernel argument, and an NPU-allocated BO cannot be exported at all (xrt::bo::export_buffer() + PRIME_HANDLE_TO_FD → ENOENT). That last row is what stops the idea being a drop-in, stated plainly.

Not verified: the numbers themselves — re-running dmabuf_test needs both npu-hold and gpu-hold and the array, which is the lane's window.

tprs-ready is on it.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 0df32ba

@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

At 0df32baa — build green, and its own file is untouched since my review (docs/hetero-prefill.md alone, +177, patch-id 8d6fdc6266b6): everything else in the branch's recent history is other PRs landing in main.

A research note on someone else's design, checked against the artifacts rather than the prose:

  • Their side. The doc says HeteroMosaic submits to amdxdna by raw ioctl "with no XRT in the path", citing npuSetup.cpp:1913-2010. At that path and range in ~/amd-oss/heteroMosaic/src/unified_llm_w4a16_hetero/npuSetup.cpp: 1913 uint32_t import_dma_buf_to_xdna(void *hip_managed_ptr, size_t size, int dataTypeinBytes), with #include "amdxdna_accel.h" and 1834: struct amdxdna_drm_exec_cmd exec_cmd — the mechanism attributed to them is the mechanism in their source, so the conclusion follows.
  • Our side. The export entry point the doc says we have today is present in our HRX backend (ggml/src/ggml-hrx/ggml-hrx.cpp, buffer_export_dmabuf), and the harness it quotes exists as ~/mosaic-bench/dmabuf_test.cpp with its binary.

The framing is the part worth keeping: the numbers separate what works now (export 0.044 ms; amdxdna PRIME_FD_TO_HANDLE + mmap 0.206 ms; MATCH both ways over 64 MiB; 29.3 GB/s shared vs 14.0 GB/s for hipMemset + hipMemcpy) from what is blocked — execution on the imported buffer, since XRT allocates its own BOs and cannot bind a foreign dma-buf as a kernel argument, and an NPU-allocated BO cannot be exported at all (xrt::bo::export_buffer() + PRIME_HANDLE_TO_FD → ENOENT). That last row is what stops the idea being a drop-in, stated plainly instead of buried.

Not verified: the numbers themselves — that needs both npu-hold and gpu-hold and the array. Copyright rc 0.

tprs-ready is on it.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit f0a3908

@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

At f0a39088 — clean, build green, and the author patch is byte-identical to the content I reviewed (8d6fdc6266b6, one file, docs/hetero-prefill.md +177), so only main arrived in the rebase.

The note on HeteroMosaic, checked against the artifacts rather than the prose:

  • Their side. The doc says they submit to amdxdna by raw ioctl "with no XRT in the path", citing npuSetup.cpp:1913-2010. At that path and range in ~/amd-oss/heteroMosaic/src/unified_llm_w4a16_hetero/npuSetup.cpp: 1913 uint32_t import_dma_buf_to_xdna(void *hip_managed_ptr, size_t size, int dataTypeinBytes), with #include "amdxdna_accel.h" and 1834: struct amdxdna_drm_exec_cmd exec_cmd — the mechanism attributed to them is the mechanism in their source, so "they can execute on an imported dma-buf because they own the ioctl path" follows.
  • Our side. The export entry point the doc says we have today exists in our HRX backend (ggml/src/ggml-hrx/ggml-hrx.cpp, buffer_export_dmabuf), and the harness it quotes is on this box as ~/mosaic-bench/dmabuf_test.cpp with its binary.

The framing is what makes the page useful: the numbers separate what works now (export 0.044 ms; amdxdna PRIME_FD_TO_HANDLE + mmap 0.206 ms; MATCH both ways over 64 MiB; 29.3 GB/s shared against 14.0 GB/s for hipMemset + hipMemcpy) from what is blocked — execution on the imported buffer, because XRT allocates its own BOs and cannot bind a foreign dma-buf as a kernel argument, and an NPU-allocated BO cannot be exported at all (xrt::bo::export_buffer() + PRIME_HANDLE_TO_FD → ENOENT). The negative result is stated as plainly as the positive one, which is what makes the positive one trustworthy.

Not verified: the numbers themselves — that needs both npu-hold and gpu-hold and the array, which is the lane's window. Method and harness are both written down, so they are reproducible.

tprs-ready is on it.

@bong-water-water-bong
bong-water-water-bong merged commit 533cb10 into main Nov 1, 2026
8 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the mosaic/hetero-prefill branch November 1, 2026 13:21
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Post-merge correction, from the same lane: the numbers this PR merged were measured on one boot (06:00-06:40 AST, before the 11:13 GPU reset). After the reboot + the 12:13 all-clear I re-ran the identical harness and shapes: M<=2048 reproduces within 3 %, but every M=16384 iGPU row is 1.4-3.3x slower (4B up_gate 20.03 -> 65.68 ms, 40.7 -> 12.4 TFLOP-s), with a hard knee between M=2048 and M=4096. Not the library (four libggml-hrx builds agree to 0.5 %), not clocks (2895 MHz, 72-78 C); cause unproven, effect reproducible.

Consequence: the "the M-split never wins" sentence is conditional on the iGPU's state. At this boot's 8:1 ratio the split wins 10-13 % at the balance point (m=14852/14592, not m=M-256). It still does not matter - 59.8 ms of split on the degraded boot vs 20.0 ms of iGPU-only on the healthy one - but the doc should not be quoted as an unconditional ceiling.

Correction PR: #777 (doc-only, adds the re-measurement section, no numbers in the original table removed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review effort 2/5 tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant