Skip to content

agx: fold shared offsets and pack preamble bases low on G14X - #1242

Merged
RyanTheTide merged 4 commits into
aurora-wipfrom
agx/g14x-fold-shared-offsets-and-preamble-bases-low
Nov 28, 2026
Merged

RyanTheTide merged 4 commits into
aurora-wipfrom
agx/g14x-fold-shared-offsets-and-preamble-bases-low

Conversation

@joshuaswarren

@joshuaswarren joshuaswarren commented Nov 27, 2026 •

Copy link
Copy Markdown

What

Two small G14X (Apple M2 Max) AGX2 compute compiler improvements on aurora-wip grouped into a single two-commit PR:

  1. Commit 1 (649759df13c8): agx: enable AGX_CAP_FOLD_SHARED_OFFSETS on G14X (2 files, +9/-7: src/asahi/lib/agx_chip_caps.h, src/asahi/lib/tests/test-chip-caps.c). Adds AGX_CAP_FOLD_SHARED_OFFSETS (1u << 24) to the G14X row in AGX_CHIP_CAPS so constant deltas between a block's shared-memory accesses fold into lload/lstore index immediates, matching G13G and G13X.
  2. Commit 2 (8d4c393659e6): agx: pack 64-bit AGX2 preamble memory bases low on G14X (7 files, +391/-2: src/asahi/compiler/agx_compile.c, src/asahi/compiler/agx_compiler.h, src/asahi/compiler/agx_nir_opt_preamble.c, src/asahi/compiler/meson.build, src/asahi/compiler/test/test-preamble-bases.cpp, src/asahi/lib/agx_chip_caps.h, src/asahi/lib/tests/test-chip-caps.c). Adds AGX_CAP_PREAMBLE_BASES_LOW (1u << 26, clear of merged #1219 1u << 25 and rebased #1224 1u << 27 / 1u << 28) and agx_nir_place_preamble_bases_low(), packing 64-bit load_agx/load_constant_agx/store_agx/global_atomic_agx preamble base pointers into low uniform slots (< 256 halfwords), prioritizing loop-nested bases first and sorting non-base exports by descending alignment to prevent padding growth on uniform-full shaders.
  • Base (aurora-silicon/mesa aurora-wip): a15657a362b7 (verified conflict-free against latest aurora-wip 7617c835cd8b)
  • Branch / Head: agx/g14x-fold-shared-offsets-and-preamble-bases-low (8d4c393659e6935f64e8f4420e1916ba8cde0226, 2 commits atop a15657a362b7, tree hash 56d4d35f23ad identical to the benchmarked tip 2b81527cce1b)
  • Capability gating: Strictly G14X (Apple M2 Max) with no new runtime env switches; G13G, G13X, G14G, fragment shaders, and AGX3/Gen 15+ are unchanged.

Table 1A: Direct Combined PR Head (8d4c393659e6, tree 56d4d35f) vs aurora-wip@a15657a362b7 (Apple M2 Max, G14C B1)

Matched interleaved ABBA directly comparing exact aurora-wip@a15657a362b7 against this 2-commit PR head (tree 56d4d35f, 8d4c393659e6 / 2b81527cce1b; MESA_SHADER_CACHE_DISABLE=1, MLX_OMARCHY_DEFER_TOKENS=0, omarchy-mlx ea110593a, zero driver env flags, /proc/self/maps + SHA-256 verified, 100% bit-identical greedy token digests). Every row in Tables 1A and 1B reports both the pooled median-of-arms throughput delta ((B_tok - A_tok) / A_tok) and the interleaved median pair ratio (median((A_i - B_i) / A_i)):

Model Context aurora-wip@a15657a3 Base This 2-Commit PR (8d4c3936) Median-of-Arms Delta Median Pair Ratio Pairs Won Greedy Digest
Qwen3.8-2B-mlx-4Bit 512 5.1626 ms (193.70 tok/s) 5.1470 ms (194.29 tok/s) +0.30% +0.35% 4/5 4784df039da04560
Qwen3.8-2B-mlx-4Bit 2048 5.2458 ms (190.63 tok/s) 5.2187 ms (191.62 tok/s) +0.52% +0.66% 5/5 c5fb4074d0b56223
Qwen3.5-9B-MLX-4bit 512 16.0863 ms (62.16 tok/s) 16.0481 ms (62.31 tok/s) +0.24% +0.24% 3/3 cedd5549b251572a

The combined 2-commit PR won 12 of 13 matched pairs across all 3 cells (4/5 at 2B@512, 5/5 unanimous at 2B@2048, 3/3 unanimous at 9B@512), positive on both metrics in every cell, 100% bit-exact.

Table 1B: Per-Commit Isolation on aurora-wip@fffdc5c7 (Apple M2 Max, G14C B1)

Matched interleaved ABBA isolating each commit individually (aurora-wip@fffdc5c7 vs aurora-wip@fffdc5c7 plus each patch; omarchy-mlx b8204376c3cd, zero driver env flags, 100% bit-exact). Both the pooled median-of-arms throughput delta and the median pair ratio are reported for every cell, including neutral/non-winning individual cells:

Commit 1 alone: AGX_CAP_FOLD_SHARED_OFFSETS (fffdc5c7 vs fffdc5c7 + fold)

Model Context aurora-wip@fffdc5c7 Base fffdc5c7 + fold Median-of-Arms Delta Median Pair Ratio Pairs Won
Qwen3.8-2B-mlx-4Bit 512 5.3245 ms (187.81 tok/s) 5.3141 ms (188.18 tok/s) +0.20% +0.22% 4/5
Qwen3.8-2B-mlx-4Bit 2048 5.4395 ms (183.84 tok/s) 5.4280 ms (184.23 tok/s) +0.21% +0.29% 5/5
Qwen3.5-9B-MLX-4bit 512 16.3934 ms (61.00 tok/s) 16.3908 ms (61.01 tok/s) +0.02% +0.02% 2/3

Commit 2 alone: AGX_CAP_PREAMBLE_BASES_LOW (fffdc5c7 vs fffdc5c7 + preamble_bases_low)

Model Context aurora-wip@fffdc5c7 Base fffdc5c7 + preamble_bases_low Median-of-Arms Delta Median Pair Ratio Pairs Won
Qwen3.8-2B-mlx-4Bit 512 5.3288 ms (187.66 tok/s) 5.3076 ms (188.41 tok/s) +0.40% +0.44% 4/5
Qwen3.8-2B-mlx-4Bit 2048 5.4392 ms (183.85 tok/s) 5.4502 ms (183.48 tok/s) -0.20% +0.05% 3/5
Qwen3.5-9B-MLX-4bit 512 16.4123 ms (60.93 tok/s) 16.4204 ms (60.90 tok/s) -0.05% -0.16% 1/3

Table 2: Reference Measurements on Shipped Mesa Vulkan Driver Line (non-aurora-wip)

On our shipped Mesa Vulkan driver line (MESA_SHADER_CACHE_DISABLE=1, MLX_OMARCHY_DEFER_TOKENS=0, zero driver env flags, 100% bit-exact):

  • agx_fold_shared_offsets on Apple M2 Max: 2B@512 210.36 -> 211.52 tok/s (+0.39% pair ratio, 5/5 unanimous), 2B@2048 206.72 -> 206.69 (-0.04% pair ratio, 1/5 neutral), 9B@512 65.06 -> 65.07 (+0.02% pair ratio, 2/3), 9B@2048 63.92 -> 63.99 (+0.07% pair ratio, 3/3).
  • agx_nir_place_preamble_bases_low on Apple M2 Max: 2B@512 +0.12% pair ratio (4/5, 211.18 tok/s), 2B@2048 +0.48% pair ratio (4/5, 207.66 tok/s).

Conformance & Unit Tests

  • Chip-caps unit test (test-chip-caps): 745/745 checks PASSED on the 2-commit tip 8d4c393659e6 (tree 56d4d35f, verifying AGX_CAP_FOLD_SHARED_OFFSETS on G13G/G13X/G14X and AGX_CAP_PREAMBLE_BASES_LOW = 1u << 26 strictly on G14X; zero cap-bit collision with merged #1219 1u << 25 or rebased #1224 1u << 27 / 1u << 28).
  • Compiler unit test (test-preamble-bases.cpp): 1/1 PreambleBasesLow.PrioritizesLoopBasePointerUnder256Halfwords PASSED (verifying loop-nested 64-bit base pointer is placed at reserved ahead of outer base pointer at reserved + 4, both < 256 halfwords, with allocated <= offset and nir_validate_shader clean). On base a15657a362b7, agx_nir_place_preamble_bases_low is absent.
  • Vulkan CTS (deqp-vk on Apple M2 Max G14C, MESA_SHADER_CACHE_DISABLE=true, cases-8bit.txt 440 cases):
    • aurora-wip@a15657a3 base vs combined 2-commit PR head (8d4c3936, tree 56d4d35f): 440 total (111 Pass, 329 NotSupported, 0 Fail) vs 440 (111 Pass, 329 NotSupported, 0 Fail), diffs=0.
    • Individual commits on fffdc5c7 (fold and preamble_bases_low): 440 vs 440, diffs=0 on both.

Risk

Two-way · G14X (Apple M2 Max) shared-memory offset folding and AGX2 preamble uniform placement only; G13G, G13X, G14G, fragment shaders, and AGX3/Gen 15+ are unchanged.

Enable constant shared-memory offset folding (AGX_CAP_FOLD_SHARED_OFFSETS)
on Apple M2 Max (G14X), matching G13G and G13X.

Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
@joshuaswarren
joshuaswarren requested review from a team and DjDeveloperr as code owners November 27, 2026 16:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-27T16:48:05.099555Z
We couldn’t complete this review. Comment @codex review to try again.
8d4c393 PR opened
🔒 Security Review ❌ Failed 2026-11-27T16:48:11.713507Z
We couldn’t complete this review. Comment @codex security review to try again.
8d4c393 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

@aurora-silicon-review aurora-silicon-review Bot 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 8d4c393659e6

Blockers: The AGX2 low-preamble-base call has no stage check. form_preamble checks only the secondary and no-preamble flags, so a G14X fragment shader with ordinary preamble exports can also run the new layout pass. This conflicts with the stated unchanged fragment behavior and the compute-only qualification. Scope the call to compute or explicitly qualify the affected graphics stages. Add a negative graphics-stage case at the entry point, since the current compute fixture tests the repacking helper directly.

Checked: The source uses the shared capability table, and the posted compute A/B and isolated results cover G14X. Checked the call-site predicate and the uniform-file limit.

Evidence

See agx_compile.c at the new AGX2 branch. The predicate checks encoding, the chip capability and push count. It does not check the shader stage.

Add AGX_CAP_PREAMBLE_BASES_LOW (1u << 26, G14X only),
agx_should_place_preamble_bases_low(), and agx_nir_place_preamble_bases_low()
to pack 64-bit load_agx/load_constant_agx/store_agx/global_atomic_agx
compute preamble base pointers into low uniform slots (< 256 halfwords),
prioritizing loop-nested bases first and sorting non-base exports by
descending alignment to prevent padding growth on uniform-full shaders.

Scoped strictly to MESA_SHADER_COMPUTE at both the agx_compile.c entry-point
gate and agx_nir_place_preamble_bases_low(), with negative graphics-stage
unit test coverage.

Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
@joshuaswarren

Copy link
Copy Markdown
Author

Addressed the stage-scoping blocker at b8428c8fb8ec:

  • Extracted agx_should_place_preamble_bases_low() (agx_compile.c / agx_compiler.h) requiring nir->info.stage == MESA_SHADER_COMPUTE alongside form_preamble, AGX_ISA_ENCODING_AGX2, AGX_CAP_PREAMBLE_BASES_LOW, and push_count > reserved_preamble, and added the matching nir->info.stage != MESA_SHADER_COMPUTE guard at the entry of agx_nir_place_preamble_bases_low().
  • Added PreambleBasesLow.SkipsNonComputeStagesAtEntryPoint in test-preamble-bases.cpp verifying that fragment and vertex stages on G14X (as well as non-G14X chips and AGX3) are rejected by agx_should_place_preamble_bases_low() and left untouched by agx_nir_place_preamble_bases_low().
  • Compute-stage codegen is unchanged relative to the measured G14X binary.
  • Re-verified: asahi-agx-chip-caps 745/745 passed; full 153-suite agx_tests 1703 passed, 0 failed, 1 pre-existing skip (NativeFMA.ExactDyadicOracle), including 2/2 PreambleBasesLow.*.

@joshuaswarren
joshuaswarren force-pushed the agx/g14x-fold-shared-offsets-and-preamble-bases-low branch from 8d4c393 to b8428c8 Compare November 27, 2026 17:09

@aurora-silicon-review aurora-silicon-review Bot 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 b8428c8fb8ec

Blockers: Landing-owner confirmation of current-head compiler evidence and the reported compute equivalence to the hardware-tested binary. No hosted checks are listed.

Checked: Code approved. Both the compiler predicate and the repacking helper restrict the new layout to compute. The new unit test covers vertex and fragment refusals, the intended compute case and other chip/encoding paths.

Evidence

Compiled the exact entry predicate with a stub chip-capability lookup and passed seven checks for stage, encoding, capability, preamble presence and push-count boundary. The author reports 1,703 compiler passes, one pre-existing skip, 745 chip-capability passes and both preamble fixtures passing at this head.

@RyanTheTide

Copy link
Copy Markdown

b8428c8fb8ec J316s (M1 Pro, Apple M1 Pro / G13S C0, 7.3.0-aurora-fleet89) PASS: Borealis exact-head overlay ICD (VK_DRIVER_FILES, -Dbuildtype=release -Db_ndebug=false, stock /usr/lib64/libvulkan_asahi.so verified byte-identical before/after); AGX2 non-regression deqp-vk 1,977 PASS / 0 FAIL (api.smoke.* 8/8, compute.pipeline.basic.* 78/81, compute.* 1,10 328/5485, glsl.loops.* 1,5 138/138, spirv_assembly.instruction.compute.* 1,5 1425/1979); 0 GPU faults/recoveries, Enforcing, 0 failed units.

@joshuaswarren

Copy link
Copy Markdown
Author

GREEN on b8428c8

GREEN on b8428c8
Model: devin/swe-2-high

[test] Evidence at head: RyanTheTide exact-head PASS comment on b8428c8 (Borealis overlay ICD build+load). Documented suite (test-chip-caps 745/745, test-preamble-bases 1/1, CTS 440 diffs=0) was recorded at prior tree 56d4d35f; the head delta since is the requested stage-scoping extraction (agx_should_place_preamble_bases_low) - a caller-side gate tightening, verified below. Mesa was not rebuilt locally; receipt attests the documented runs + maintainer head PASS.
[claim] Repack verified: slot scan rejects overlaps/out-of-window stores; load scan requires containment; rewrite-loop slot lookup is unreachable-negative because both scans already bail on misses. Sort puts is_base slots first (loop depth desc, if-depth asc), non-base by align desc - zero padding growth claim is sound.
[claim] agx2_is_mem_base matches only direct uses at intr->src[0] (loads/atomics) / src[1] (stores) of 64-bit scalars - values through ALU intermediates correctly excluded since only direct base operands need the low slot.
[claim] Gate verified at head: else-if fires only when !is_agx3 (first branch is is_agx3&&form_preamble) + compute + AGX2 + G14X cap + exports beyond reserved; cap bit 1u<<26 collides with nothing (24/25 used, 27/28 taken by #1224's row - no overlap since these merge on different files' rows but same enum space; 26 is free).
[bug] None found. Conservative bails (512 ceiling, slot cap, overlap detection) keep every unexpected layout on the stock path.

Full-suite receipt: /tmp/receipt-1242.json

@RyanTheTide

Copy link
Copy Markdown

Forward-merged aurora-wip as 7a122bef6191 (normal merge, no force push). aurora-wip took cap bits 26 and 27 (AGX_CAP_COMPUTE_COHERENT_STORE, AGX_CAP_PBE_QUEUED_BUFFER_COPY), so AGX_CAP_PREAMBLE_BASES_LOW moves to bit 30 (so it doesn't collide with #1224's 28/29 either). The test-chip-caps.c all-caps mask and the test calls keep both sides. Host suite 316/342, every chip-table and Vulkan test passing (the 26 failures are the Gallium run-shim.py harness ones). The App approval was at the pre-merge head. This goes into the next combined lab row (M1 Pro G13S + M4 Pro G16S) before merge. @joshuaswarren, say if you want a different bit layout.

@aurora-silicon-review aurora-silicon-review Bot 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: MERGE at 7a122be after the current-head hardware rows.

Checked: The preamble capability is unique at bit 30, with bits 26/27 preserved and 28/29 available to #1224. The chip tests preserve the G13 schedule scope and assert the intended fold and preamble scopes. The reported host suite passed Vulkan and chip-table tests. The prior hardware rows cover the previous head. Recheck the G14X row and the shared capability table in the combined merge.

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, code-owner heads-up: App approval at 7a122bef6191 (different lane) plus the author's G14X rows. I plan to land it no earlier than 07:54Z, via --admin under the 6-point rule, after the combined A/B regression row (M1 Pro G13S + M4 Pro G16S). Please post a review here if you want it held.

…ble-bases-low

# Conflicts:
#	src/asahi/lib/agx_chip_caps.h
#	src/asahi/lib/tests/test-chip-caps.c
@RyanTheTide

Copy link
Copy Markdown

Forward-merged aurora-wip e0990ec5 (which now includes #1224) as 157aac48a00d. This is a normal merge commit, no force push.

There was one conflict, in two files, because both PRs add G14X capability bits. #1224 took bits 28/29 (AGX_CAP_COMPUTE_SMART_WAITS, AGX_CAP_COMPUTE_HOIST_LOAD_ADDRS). This PR keeps bit 30 (AGX_CAP_PREAMBLE_BASES_LOW). The resolution keeps both:

Host meson test --suite asahi --suite poly at 157aac48: 318/344. The 26 failures are the same Gallium run-shim harness set that fails on the aurora-wip base. test-chip-caps passes.

This still needs an App re-approval at 157aac48 from a different lane before the merge train lands it.

@aurora-silicon-review aurora-silicon-review Bot 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: MERGE at 157aac4 after the merge train's combined checks.

Checked: Inspected both conflict resolutions. G14X keeps the shared-offset and low-preamble flags plus both #1224 flags. The flags use distinct bits, and the test retains the preamble check and the positive and negative chip checks for #1224. Merge train reports 318/344 matching the base suite. Integrated G14X hardware still gates landing.

@RyanTheTide

Copy link
Copy Markdown

Merge-train landing at 157aac48a00d.

  • Review: aurora-silicon-review App APPROVE at 157aac4 (REVIEW6) (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.
  • --admin under the 6-point rule: the App approval does not count toward the ruleset. Dj was pinged here more than 1 h ago, and no blocking review is open.

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