Skip to content

agx: skip coherent loads in agx3_merge_m5_word_loads - #1609

Merged
DjDeveloperr merged 1 commit into
aurora-silicon:aurora-wipfrom
AxxzyWasTaken:pr/agx3-merge-word-loads
Dec 4, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-silicon:aurora-wipfrom
AxxzyWasTaken:pr/agx3-merge-word-loads

Conversation

@AxxzyWasTaken

@AxxzyWasTaken AxxzyWasTaken commented Dec 3, 2026 •

Copy link
Copy Markdown

What: Skip I->coherent (which also carries SPIR-V volatile via nir_is_coherent()) in agx3_m5_word_load(), so agx3_merge_m5_word_loads() never combines volatile/coherent scalar 32-bit device loads on AGX3C fragment shaders (or any future stage using the helper).
Tested: Host assertions-enabled build (-Db_ndebug=false) at ed35ca8519f: agx_tests 2010 pass / 1 skip (including new AGX3VisionOpts.MergeWordLoadsSkipsCoherent).
Risk: two-way door · M5 (AGX3C fragment shaders).
Not yet: M5 (AGX3C) hardware CTS row at ed35ca8519f (we only have an M4 Max / AGX3B here).

Details
  • agx3_ordered_load_candidate() already rejects I->coherent, while agx3_m5_word_load() did not.
  • Because nir_is_coherent() sets coherent for SPIR-V volatile accesses, agx3_merge_m5_word_loads() could combine adjacent volatile 32-bit fragment loads on AGX3C, violating SPIR-V volatile semantics.
  • Drops the earlier AGX3B fragment/compute widening and span_scale parameter after review showed 0 non-volatile CTS changes across 15,641 cases, 0/84 RW compute hits on G16G, and only noise-level (−0.47 %) delta on G17P mg_restrict.
  • Exposes agx3_merge_m5_word_loads() in agx_compiler.h for unit testing and adds AGX3VisionOpts.MergeWordLoadsSkipsCoherent.
Evidence
  • ninja -C build src/asahi/compiler/agx_tests && ./build/src/asahi/compiler/agx_tests: 2010 pass, 1 skip, 0 fail at ed35ca8519f.
  • AGX3VisionOpts.MergeWordLoadsSkipsCoherent: verifies coherent consecutive loads stay separate while non-coherent consecutive loads on AGX3C fragment still merge.

@AxxzyWasTaken
AxxzyWasTaken requested review from a team and DjDeveloperr as code owners December 3, 2026 19:18

@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.

Checked at fa6a810 merged on aurora-wip 80c8e76 (merges clean).

What I ran:

  • agx_tests: AGX3VisionOpts.MergeWordLoadsAGX3B passes. The whole binary is 2,010 pass / 1 skip, and meson test --suite asahi is 410 OK / 0 fail / 1 skip (x86, debugoptimized, assertions on).
  • A wide drm-shim compile slice, base vs this PR: 15,641 Vulkan CTS cases (compute, ssbo, robustness, glsl), each run with the real kernel feature word of our G15S, G16G and G17P Macs. No refused shaders in either arm on any of the three, and no case changed status. Code changed in 3 cases on G15S and G16G and in none on G17P. All three are robustness2 volatile storage-buffer fragment tests (132 B and 256 B smaller in total). No compute shader in the slice changed.

Before this can merge:

  1. Volatile loads. In this backend coherent is also set for volatile accesses (nir_is_coherent()), and SPIR-V says a volatile access can't be combined with another. On AGX3B the pass now merges them in fragment shaders. Those three robustness2 volatile fragment tests are the only changes the slice shows. Please skip I->coherent loads in every stage, not just compute. That also stops it on AGX3C fragment, which has the same problem today.

  2. A measured gain. The −0.47 % median on one shader is inside the run-to-run noise you measured yourself, so it doesn't show a gain yet. For a perf change we need a gain above noise on a real workload; we aim for ≥5 %, or first a throwaway hack that shows the ceiling is worth chasing.
    This change also turns the pass on for AGX3B compute. The pass kept compute out on purpose: a vector load needs an aligned register range, which can push a shader past an occupancy step. The CTS slice has no compute shader that this pass changes, so it can't show that risk either way. In the three fragment changes, register counts moved both ways (on G16G one shader went from 40 to 56 halves, another from 30 to 26). Next to the gain, please post the thread counts (base vs head) for a big compute set, such as the ggml-vulkan or GB6 compute pipelines.

  3. The 8 in span_scale. It's a tuning number with no stated reason. Please say which merges need more than the current 2 * (count + 1) span (for example, how many of the four in mg_restrict). If they don't need it, keep the current span and drop the parameter.

Small: the PR title says fragment, but the commit also enables compute.

Once it's updated, we'll run the wide CTS slice on an AGX3B Mac at the new head before merging.

@github-actions github-actions Bot added area:compiler Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Merge readiness at ed35ca85: not ready yet

Check Detail
CI at head ok no CI for this change (the hardware row is the gate)
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes no requested by DjDeveloperr
Hardware row at head ok in the PR body at ed35ca85
Conflicts ok none
PR text ok Risk: two-way · M5 (AGX3C fragment shaders).

Areas: area:compiler

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

In this backend, I->coherent also covers SPIR-V volatile accesses
(via nir_is_coherent()), and SPIR-V forbids combining volatile loads
with another load.

Skip I->coherent in agx3_m5_word_load() so coherent/volatile scalar
word loads are never merged on AGX3C fragment shaders (or any future
stage using the helper), matching agx3_ordered_load_candidate().

Expose agx3_merge_m5_word_loads() for unit testing and add
AGX3VisionOpts.MergeWordLoadsSkipsCoherent.

Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
@AxxzyWasTaken
AxxzyWasTaken force-pushed the pr/agx3-merge-word-loads branch from fa6a810 to ed35ca8 Compare December 3, 2026 21:10
@AxxzyWasTaken AxxzyWasTaken changed the title agx: enable consecutive word-load merging on AGX3B fragment and compute agx: skip coherent loads in agx3_merge_m5_word_loads Dec 3, 2026
@AxxzyWasTaken

Copy link
Copy Markdown
Author

Thanks for the thorough review and CTS slice.

Agree on all three points: across your 15,641 CTS cases, 0 non-volatile shaders changed, 0/84 RW compute shaders changed on G16G, and our single-shader G17P mg_restrict A/B (−0.47 %) did not clear noise.

I've narrowed this PR at ed35ca8519f strictly to the real correctness bug your slice caught:

  • Skip I->coherent inside agx3_m5_word_load() (matching agx3_ordered_load_candidate()), preventing SPIR-V volatile/coherent loads from being merged on AGX3C fragment shaders.
  • Dropped the AGX3B fragment/compute enablement and the span_scale parameter.
  • Replaced the unit test with AGX3VisionOpts.MergeWordLoadsSkipsCoherent (host assertions-enabled agx_tests: 2010 pass, 1 skip).

Note: since this now targets AGX3C (M5) only, I don't have an M5 here to run the hardware CTS row.

@github-actions github-actions Bot added blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot) labels Dec 3, 2026

@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.

Checked again at ed35ca8, merged onto aurora-wip 23f7c86 (clean merge).

This is now only the volatile fix. agx3_m5_word_load() skips coherent loads, which in this backend also means SPIR-V volatile, so the pass never merges them. The rest of the diff is the export for the unit test and the test itself. The pass still runs only on AGX3C fragment shaders, so M3, M4 and Neo code doesn't change. The title and body match the commit.

What I ran (x86 debugoptimized build, assertions on):

  • The new test MergeWordLoadsSkipsCoherent fails if I take the !I->coherent check back out (the two coherent loads become one load with mask 0x3), and passes at this head. agx_tests: 2,013 pass, 1 skip. meson test --suite asahi: 410 OK, 0 fail, 1 skip.
  • drm-shim compile slice, aurora-wip vs this PR, each Mac's own feature word:
    • The 15,641-case wide list on G15S, G16G, G17P and G17S: no refused shaders on either side and no case changed result. Code changes only on G17S, in 3 cases, all robustness2 volatile fragment tests.
    • A quarter of the robustness2 fragment storage-buffer cases (576 volatile, 576 nonvolatile): 158 cases change code on G17S, every one of them volatile; none of the nonvolatile ones change. In each, the merged load is split back into two, so those shaders are about 1.6 % larger with no change in thread count.
    • ggml-vulkan (1,099 compute shaders) and GTA V (685 compute, 5,885 graphics pipelines) on G17S: no change at all.
  • I ran this first on cea627b and again after aurora-wip moved to 23f7c86. The result is the same: the merge is clean, the tests pass, and the changed cases give the same picture (154 changed, all volatile, 0 refused).

Approving. Before merge it still needs the J714s (M5 Pro) CTS row at this head. The kit is sealed. It runs the volatile fragment storage-buffer cases first, then their nonvolatile counterparts and the wide list.

@DjDeveloperr

Copy link
Copy Markdown

J714s Exact-Head Hardware Receipt (ed35ca8519f8)

  • Host / Kernel: Apple MacBook Pro (14-inch, M5 Pro, 2026) [apple,j714s apple,t6050 apple,arm-platform], stock 7.3.0-m5-pr67 (boot_id=cb13c0b7-f565-40bb-8d58-8d8b2966ac9e, DRIRC_CONFIGDIR=/usr/share/drirc.d, features=0x00003d3e7cfe7c07).
  • PR head: ed35ca8519f8967a99237ff5a4046aaeb805cd27
  • Arm A (base aurora-wip 23f7c8697dbc8be4454a8cf1deb6b379bfb4aa1a): tree 8e4289ef5493869bd41ae60b49b12859a5b61e8a, lib sha256 a4673636d563dfb0fb51271014c3e18fd5b347cbcdd28e084e8ba6b7ed6c0793
  • Arm B (head merge ead45c8c47b0c9184dac4db687d9d2297e37d472): tree 4e95beebf499700fe976a567c58a3d8e76cd0125, lib sha256 09aeaa28da3d6eb4b5548a0ad2ffe7b42f63d21c7b8d52e53ce7ab744764736f
  • Driver proof (/proc/pid/maps): {'ok': 214, 'unseen': 8}
Suite Base (23f7c8697dbc) Head (ed35ca8519f8 merge) Diffs Refused
Focus (rt list, 2,305 cases) 1,857 Pass / 448 NS / 0 Fail 1,857 Pass / 448 NS / 0 Fail 0 0
Extra (2,304 cases) 1,856 Pass / 448 NS / 0 Fail 1,856 Pass / 448 NS / 0 Fail 0 0
Wide (15,641 cases) 8,351 Pass / 7,278 NS / 12 Fail 8,351 Pass / 7,278 NS / 12 Fail 0 0
Total (20,239 cases/arm, 111/111 chunks, 270s wall) 12,056 Pass / 8,171 NS / 12 Fail / 0 Warn / 0 Crash 12,056 Pass / 8,171 NS / 12 Fail / 0 Warn / 0 Crash 0 0
  • New fails / refusals on head: 0 (12 cooperative_matrix.khr_r floate4m3 cases fail identically on both base and head).
  • GPU fault / reset / timeout lines in kernel log: 0

J714s ed35ca8519f8 VERDICT PASS (20,239 cases/arm, 0 differ, 0 new fails, 0 refused, 0 GPU fault lines).

@DjDeveloperr
DjDeveloperr merged commit 405c0a0 into aurora-silicon:aurora-wip Dec 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:compiler Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) changes-requested A reviewer requested changes (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants