Skip to content

hk: keep write-combined command memory on G16G - #1594

Closed
IronsideXXVI wants to merge 1 commit into
aurora-silicon:aurora-wipfrom
IronsideXXVI:j604-hk-g16g-wc-cmd-memory
Closed

IronsideXXVI wants to merge 1 commit into
aurora-silicon:aurora-wipfrom
IronsideXXVI:j604-hk-g16g-wc-cmd-memory

Conversation

@IronsideXXVI

Copy link
Copy Markdown

What: Restore write-combined (WC) command-buffer memory on G16G (M4) in Borealis (hk):

  • src/asahi/vulkan/hk_cmd_pool.h (hk_g17p_cached_cmd_memory()) currently returns agx_chip_is_agx3_single_die(dev->chip) && util_has_cache_ops(), placing G16G on CPU-cached command/root/descriptor memory with explicit cache-clean publishes before submission.
  • Exclude AGX_CHIP_G16G (dev->chip != AGX_CHIP_G16G) in hk_g17p_cached_cmd_memory() so G16G stays on write-combined command memory while keeping CPU-cached command pools enabled on G15, G17P, and single-die M5 (G17G/G17S/G17C).
  • Add test_cached_cmd_memory_chip_policy() in src/asahi/vulkan/tests/test-hk-cmd-pending.c verifying hk_g17p_cached_cmd_memory() across every enum agx_chip value.

Tested:

  • Offline build & full Asahi suite at exact head 1d09f41352a1 on origin/aurora-wip (f4a74912604, gcc 16.1.1, aarch64, -Dbuild-tests=true -Dtools=drm-shim, git merge-tree --write-tree clean 4cbaf8ec1385):
    • libvulkan_asahi.so built cleanly (0 warnings in touched files).
    • hk_cmd_pending (test-hk-cmd-pending.c): PASS (1/1, hk_cmd_pending: ok, including test_cached_cmd_memory_chip_policy()).
    • Full meson test -t 4 --suite asahi: 403 Ok / 0 Fail / 1 Skipped.
  • Live Apple M4 MacBook Pro 14" (J604, G16G / T8132) integrated release ship (mesa-aurora/vulkan-aurora 1.8327, set 9a38001371d141eb, paired with linux-aurora-next 1.1695, 1df3ddcb45f9, boot 433bd8d2): pp512 = 1627.26 tok/s (101.1% vs macOS), tg128 = 98.82 tok/s (iqr 0.09%, trim1 1.07%), RH64 = 246.99 us (100.9%), MLX = 90.66 tok/s, Quake = 1195.0 fps, 0 GPU faults.

Risk: two-way door · G16G (M4) Borealis command-pool memory type only (2 files, +23 / -3 lines, of which +5 / -3 is hk_cmd_pool.h predicate + comment). Every other single-die AGX3 chip (G15*, G17P, G17G/G17S/G17C), multi-die G17D, G18G, and AGX2 are unchanged, and Borealis already supports both WC and CPU-cached command pools cleanly across all upload/publish paths. A plain revert restores CPU-cached command pools on G16G.

Not yet:

  • Standalone exact-head aurora-wip (1d09f41352a1) J604 / M4 hardware A/B (llama-bench pp512/tg128, Vulkan submission latency, gpubench-vk, 0 GPU faults) isolated from other 1.8327 carries.
Offline & unit test details

Scope (j604-hk-g16g-wc-cmd-memory, head 1d09f41352a1 on aurora-wip f4a74912604)

  • src/asahi/vulkan/hk_cmd_pool.h (+5 / -3)
  • src/asahi/vulkan/tests/test-hk-cmd-pending.c (+18)
  • Sign-off: Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
  • git merge-tree --write-tree origin/aurora-wip HEAD: clean (4cbaf8ec1385e9f8927ef708778e17075ca30256).
  • Unit tests: hk_cmd_pending 1/1 OK, meson test --suite asahi 403 Ok / 0 Fail / 1 Skipped.

Exclude AGX_CHIP_G16G from hk_g17p_cached_cmd_memory() so G16G (M4)
uses write-combined command-buffer memory rather than CPU-cached
command pools with explicit cache-clean publishes, while keeping
CPU-cached command memory enabled on G15, G17P, and single-die M5.

Add test_cached_cmd_memory_chip_policy() in test-hk-cmd-pending.c to
verify hk_g17p_cached_cmd_memory() across all agx_chip values.

Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
@IronsideXXVI
IronsideXXVI requested review from a team and DjDeveloperr as code owners December 3, 2026 13:03

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: HOLD at 1d09f41352a1: it takes back a measured G16G gain without a measurement.

Blockers:

  1. src/asahi/vulkan/hk_cmd_pool.h:123: dev->chip != AGX_CHIP_G16G puts G16G alone on write-combined command memory. #1132 moved G16G to cached command memory on purpose, with an A/B on J713 (M4 Air): render.mdi d=4 +5.74 %, render.light d=16 +2.88 %, render.light d=1 +0.42 % wall and 2 % less recording CPU, with slab suballocation, root reuse and push-descriptor elision on top. Undoing that needs an A/B showing which workload it hurts and by how much.
  2. It's a chip gate with no hardware property behind it. If cleaning the cache costs too much on some submit path, that path is the place to fix (hk_cmd_buffer_publish_cached_uploads(): how many lines it cleans, and when), for every chip that uses it.

Checked: no other chip changes; the new policy test fails when the predicate is put back; no overlap with other open PRs.

We put this head in our J773g timing kit (base afbbb02b06f1: llama.cpp Q4_K_M pp512/tg128 and gpubench compute.*). If write-combined memory wins there, the numbers will show which path to fix.

@IronsideXXVI

Copy link
Copy Markdown
Author

Thanks for the review and for adding this head to the J773g timing kit, @DjDeveloperr.

Agreed that taking back #1132's measured G16G gain requires an isolated A/B showing a real regression (and fixing the publish/flush path rather than gating by chip name if one exists). This patch was originally added while diagnosing a J604 tg128 regression that we subsequently traced to a kernel-side G16 idle-decay path rather than Mesa. We will either post an isolated G16G A/B showing a genuine write-combined win and address the underlying path, or close this PR if the isolated A/B shows no G16G benefit.

@DjDeveloperr

Copy link
Copy Markdown

HW: J773g (Apple M4 / G16G B0, 7.3.0-j773g-main3685+, boot d0d3b57e, base aurora-wip 3750a2177184, head 1d09f413, evidence arm in work/mesa1595-timing-tip-j773g-20261203):

  • VERDICT mesa#1594 FAIL: Q4_K_M output differs (base repeats itself True, both arms byte-identical on tokens/544 logit hashes/logits False).
    • test-backend-ops MUL_MAT vs CPU: 126 OK / 0 FAIL / 57 not (q4_K 126, matches base).
    • Q4_K_M timing: pp512 4612.12 vs 4610.00 (-0.05%, A/A 1.66%), tg128 326.35 vs 327.89 (+0.47%, A/A 0.61%).
    • gpubench compute (40 points): 0 slower (small_disp d1 -21.64% vs A/A 1.23%).
    • Kernel lines during run: 0, GPU fault/reset/timeout lines: 0.

@IronsideXXVI

Copy link
Copy Markdown
Author

Thanks for running the isolated J773g A/B, @DjDeveloperr.

With Q4_K_M timing flat (pp512 -0.05%, tg128 +0.47% inside 0.61% A/A noise), #1132 already winning on graphics workloads, and the isolated arm failing Q4_K_M output determinism on J773g, write-combined command memory on G16G should not be restored. Closing this PR (and dropping it from our local J604 carry).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants