Skip to content

borealis: scale packed compute static-work budget with GPU core count - #1179

Merged
RyanTheTide merged 3 commits into
aurora-silicon:aurora-wipfrom
oreater:pr/borealis-pack-work-budget-cores
Nov 28, 2026
Merged

RyanTheTide merged 3 commits into
aurora-silicon:aurora-wipfrom
oreater:pr/borealis-pack-work-budget-cores

Conversation

@oreater

@oreater oreater commented Nov 27, 2026

Copy link
Copy Markdown

What: Scale the per-packet compute submit-packing static-work budget (HK_PACK_MAX_STATIC_WORK, 2^35 thread-instructions calibrated for ~16–20 core GPUs) linearly with agx_get_num_cores() from 1x at <= 20 cores up to 4x at >= 80 cores (1.6x at 32, 2x at 40, 4x at 80), so wider GPUs maintain the same wall-clock packet budget without prematurely splitting compute graphs or rejecting post-fusion runs.

Tested: J716c Apple M5 Max at eec2d72eca0: 334/334 Clang debug CI tests (--suite asahi --suite poly) PASS, 48-CB high-work compute graph cuts CDM firmware commands 48 -> 24 (runs=0 -> 24) and wall-clock time -17.3% (1.290 -> 1.066 ms, 1.21x) with exact counter readback, 159/160 Vulkan CTS PASS (0 fail, 0 diffs), 0 kernel errors.

Risk: two-way door · Macs with > 20 GPU cores — A plain revert restores the fixed 2^35 static-work cap; Macs with <= 20 GPU cores get the exact 1x (2^35) budget unchanged. HK_PACK_MAX_DISPATCHES, HK_PACK_MAX_THREADS, per-packet attachment caps, and synchronization rules are untouched.

Not yet: Hardware-tested on 40-core J716c Apple M5 Max; wider 60–80 core (Ultra) parts get up to 4x proportional scaling without per-chip tables.

Details and verification evidence

Summary

  • src/asahi/vulkan/hk_pack.h, hk_pack.c:
    • Add hk_pack_max_static_work_for_cores() and hk_pack_max_static_work() scaling (HK_PACK_MAX_STATIC_WORK / 4u) * CLAMP(cores, 20u, 80u) / 5u via agx_get_num_cores().
    • Add max_static_work to struct hk_pack_limits (defaulting to HK_PACK_MAX_STATIC_WORK when 0) and use it in hk_pack_within_bounds() and hk_pack_plan().
    • Add *_limit() variants of hk_pack_account_dispatch_work_eff(), hk_pack_account_dispatch_work(), and hk_pack_fusion_fits_run().
  • src/asahi/vulkan/hk_cmd_dispatch.c, hk_queue.c:
    • Pass hk_pack_max_static_work(dev) into dispatch work accounting, hk_pack_limits.max_static_work, and submit-time fusion re-accounting.
  • src/asahi/vulkan/tests/test-hk-pack.c:
    • Unit-test core scaling (10/16/20/32/40/80/160 cores), scaled bounded-loop work accounting, scaled post-fusion budget checks, and run packing of two 24G-work members (splits on 20-core 1x, packs on 40-core 2x).

Build & Artifacts

  • Host: J716c Apple M5 Max (G17C B1, 40 GPU cores), Fedora Remix 44, kernel 7.3.0-40.j716c19.fc44.aurora.aarch64
  • Base (origin/aurora-wip 41fe336dffa): libvulkan_asahi.so SHA-256 0ea0ee4efd3bb78ef2eab7770e5d2bf9dacd59a4cd4f8809729941acff43e476
  • Head (eec2d72eca0): libvulkan_asahi.so SHA-256 801962892fc776590c6004202b8e93af31ccebacb2ee7a6df6ca2c7b3de9c005

Verification

  • CI-matching Clang 22.1.8 debugoptimized (--suite asahi --suite poly, Gallium + Vulkan + drm-shim, assertions enabled): 334/334 PASS, 0 FAIL.
  • Live M5 Max A/B (strict 3-round ABBA = 6 runs per arm, MESA_SHADER_CACHE_DISABLE=1, 48-CB compute graph × 40 iters, exact output counter 1920 on every run):
Workload (48-CB ~20B-work/CB graph) Base median Head median Delta
CDM packed runs / commands (HK_PACK_CDM_TRACE=1) 0 runs (48 cmds) 24 runs (24 cmds) -50% cmds
Wall-clock time per submit 1.2897 ms 1.0664 ms -17.3% (1.21x)
  • Vulkan CTS (deqp-vk, base vs head, MESA_SHADER_CACHE_DISABLE=1):
    • 160-case slice across dEQP-VK.compute.pipeline.basic.* + dEQP-VK.api.command_buffers.*: 159/160 PASS, 0 FAIL, 1 NotSupported (0 status diffs vs base).
  • Host health: SELinux=Enforcing, 0 DRM/asahi/GPU kernel errors.

HK_PACK_MAX_STATIC_WORK (2^35 thread-instructions) was calibrated for
~16-20 core GPUs (~18 ms at M4 ALU rate), which artificially splits
multi-CB compute graphs and rejects post-fusion runs on wider GPUs.

- Add hk_pack_max_static_work_for_cores() / hk_pack_max_static_work()
  scaling linearly from 1x at <=20 cores to 4x at >=80 cores via
  agx_get_num_cores() (1.6x at 32, 2x at 40, 4x at 80).
- Add max_static_work to struct hk_pack_limits and *_limit() variants
  of hk_pack_account_dispatch_work{,_eff}() and hk_pack_fusion_fits_run(),
  keeping existing defaults unchanged when max_static_work == 0.
- Wire the core-scaled limit through hk_cmd_dispatch.c and hk_queue.c
  and cover core scaling, bounded-loop accounting, fusion re-accounting,
  and run planning in test-hk-pack.

Signed-off-by: oreater <145754695+oreater@users.noreply.github.com>
@oreater
oreater requested review from a team and DjDeveloperr as code owners November 27, 2026 00:16
@RyanTheTide

RyanTheTide commented Nov 27, 2026 •

Copy link
Copy Markdown

This branch no longer merges into current aurora-wip (d2e883ab2e3): git merge-tree reports conflicts in src/asahi/vulkan/hk_pack.c and src/asahi/vulkan/tests/test-hk-pack.c. Could you merge aurora-wip into the branch (a normal merge, no rebase or force push) and re-run the asahi + poly suites at the new head? I will review the content once it merges cleanly. Several open queue/pack PRs touch the same file, so resolving against the tip as it is now will save a second round.

@RyanTheTide RyanTheTide 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: FINISH, then merge at eec2d72eca08f

Blockers: none

Checked: Read the whole diff (hk_pack.c/.h, hk_queue.c, hk_cmd_dispatch.c, the tests). The budget comes from agx_get_num_cores(), the sum of the core masks the kernel reports, so it is a hardware property and not a chip table. That satisfies the no-gates rule. The arithmetic is exact at the end points: (2^35 / 4) * clamp(cores, 20, 80) / 5 gives exactly 2^35 for 20 cores or fewer, so every Mac at or below 20 cores (M1/M2/M3/M4 base and Pro parts, A18 Pro, all current lab Macs) keeps the current budget bit for bit. It cannot overflow (max 2^37). Record time and pack time use the same value: dispatch_grid_shader() calls hk_pack_max_static_work(dev) when it sets pack_loops/pack_static_work, and hk_pack_runs() passes the same value in limits.max_static_work to hk_pack_plan() and to the fusion check. The old entry points keep 2^35 for callers and tests that pass no limit, and in a merged tree no non-test code calls the unscaled variants. The new tests check exact values and the 24G+24G split-versus-pack case, so they cannot pass without the change.

To finish:

  1. Merge aurora-wip into the branch. In hk_pack.c hk_pack_within_bounds(), keep wip's (!cs->pack_loops || m->obs_ns <= HK_PACK_MAX_OBS_NS) line from #1186 next to max_work. In test-hk-pack.c, put your budget tests inside the block where w, nw, nl and runs are declared, before wip's new obs-retire block. A scratch merge done that way passes the local gate (see Evidence).
  2. Rows owed at the merged head: the change only does anything on GPUs with more than 20 cores, and the J716c is the only such Mac we have, so the M5 Max row at the merged head is the feature row. Add one 20-core-or-fewer regression Mac to show nothing changed there. Max and Ultra parts of the M1/M2 generations would get 1.6x to 3.8x larger packets. On those GPUs a compute command blocks other clients' compute for its whole length, so a packet that takes as long in wall-clock time also stalls the compositor that long. That matches what the scaling intends, but it is untested. Please say so under "Not yet".

Non-blocking: the comment says the 2^35 budget was "calibrated for ~16-20 core GPUs (~18 ms at M4 ALU rate)", but 2^35 thread-instructions on a 10-core M4 is about 17 ms, and on a 20-core part about half that. Worth rewording so nobody later reads 18 ms as the bound on a 20-core part.

Landing order: this conflicts with #1180 in tests/test-hk-pack.c only (both append tests in the same place). Either order works; the second one keeps both blocks.

Evidence
  • Local x86 drm-shim gate (stands in for CI; docker aurora/hk6356-mesa-x86-tests:local, clang release with asserts, meson test --suite asahi --suite poly):
    • base aurora-wip fa8970cda14f: 336 OK / 0 FAIL
    • scratch merge of eec2d72eca08f into fa8970cda14f, resolved as above: 336 OK / 0 FAIL; hk_pack log shows PASS work budget stays 1x for <=20 cores, PASS work budget scales cleanly on 32/40/80+ cores, PASS 24G + 24G splits under 20-core 1x budget, PASS 24G + 24G packs under 40-core 2x budget.

@RyanTheTide

Copy link
Copy Markdown

The 24 h window on the merge request from 11-27 04:20Z has passed, so per our PR fast-track policy I forward-merged aurora-wip (18d3cdc3692d) into this branch as 8b49b941bf21. It's a normal merge commit, with no rebase or force push.

Conflicts, kept both sides:

  • src/asahi/vulkan/hk_pack.c hk_pack_within_bounds(): uses your core-scaled max_work and keeps aurora-wip's observed-duration bound (!cs->pack_loops || m->obs_ns <= HK_PACK_MAX_OBS_NS, borealis: budget repeated looping compute packs by observed duration #1186).
  • src/asahi/vulkan/tests/test-hk-pack.c: your core-count budget cases and aurora-wip's observed-duration cases both run.

Host check at 8b49b941bf21 (x86 clang, release + asserts, drm-shim): every Vulkan test passes, including hk_pack. The suite shows 313/339 overall. The 26 failures are all Gallium run-shim.py tests that this harness fails without your change too.

Before merge it goes into the next combined lab regression row (M1 Pro G13S + M4 G16G). If you'd rather resolve it differently, push on top and I'll re-run.

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, code-owner heads-up: this PR has an aurora-silicon-review App approval at 8b49b941bf21 from a different lane plus the author's exact-head hardware row. I plan to land it no earlier than 06:29Z, after a combined A/B regression row on two lab GPU families (M1 Pro G13S + M4 G16G). The App approval doesn't count toward the ruleset, so that merge uses --admin under the 6-point rule. Please post a review here if you want it held.

@RyanTheTide

Copy link
Copy Markdown

Second forward merge, 95df5c2e9266. #1254 (query-reset packing) landed on aurora-wip and changed hk_pack.c. The conflict was hk_pack_within_bounds() and the run-extension check: #1254 replaced cs->pack_threads / cs->pack_static_work with m_threads / m_work (query-reset aware), and your core-scaled max_work budget is kept on both. Host suite 316/342, every Vulkan test passing (the 26 failures are the same Gallium run-shim.py harness ones). The packing file changed since the combined row, so this head goes into the next combined row before merge.

@RyanTheTide

Copy link
Copy Markdown

Merge-train landing at 95df5c2e9266.

  • Review: RyanTheTide review-lane APPROVE (no blockers) at eec2d72; the later commits are my two aurora-wip forward merges (host suite green) (non-author).
  • Feature row: the author's exact-head hardware row on this PR.
  • Regression: combined A/B overlay of aurora-wip plus this PR and the other queued PRs, user space, default kernel command line. M1 Pro (G13S, fleet89): 0 status changes. M4 Pro (G16S, fleet89): 0 regressions. The only flips there are a few synchronization multi_queue timeouts under 4-job load, flipping in both directions. Every flipped case passes alone on both arms, and the base arm shows the same flake. Each Mac ran 26,595 dEQP-VK + 8,153 dEQP-GLES cases, with 0 GPU firmware crashes, Enforcing, 0 failed units. Evidence traces/gpu/20261128-mergetrain-mesa.

Revert: git revert -m 1 <merge commit> on aurora-wip. A regression gets reverted first and fixed after.

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