Skip to content

agx: enable AGX_CAP_MOD3_REG_BANK_RA on M5 - #1111

Merged
DjDeveloperr merged 1 commit into
aurora-wipfrom
satchlj/m5-mod3-reg-bank-ra
Nov 26, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-wipfrom
satchlj/m5-mod3-reg-bank-ra

Conversation

@satchlj

@satchlj satchlj commented Nov 26, 2026

Copy link
Copy Markdown
Member

What: Enable AGX_CAP_MOD3_REG_BANK_RA in AGX_CAPS_M5 (G17G, G17S, G17C) so the AGX register allocator tie-breaks co-read GPR pairs across the three 32-bit register banks ((reg / 2) % 3) and coalesces single-use loop RMW accumulator chains on non-preamble M5 shaders, matching G17P.

Tested: Mac Studio M5 Max (J775c, G17C B1, 40-core GPU) at 0151657d581b: native aarch64 GCC 16.1.1 (-Dbuildtype=release -Db_ndebug=false -Dbuild-tests=true -Dtools=drm-shim) MALLOC_PERTURB_=42 meson test -C build --suite asahi 322/322 pass (0 fail); 3-round interleaved same-machine A/B vs 8c74e92d5162 improves Llama 2 7B Q4_0 pp512 by +2.08% (2,154.27 -> 2,199.05 t/s), pp2048 by +2.03% (2,059.95 -> 2,101.70 t/s), vkpeak int32-vec4 by +0.38% (8,240.81 -> 8,272.06 GIOPS), and fp16-vec4 by +0.32% (32,039.81 -> 32,142.77 GFLOPS) with no regressions on gpubench-vk; live Vulkan CTS A/B (MESA_SHADER_CACHE_DISABLE=1) 3,914/4,885 pass (0 fail, 971 NotSupported, identical to baseline), 0 GPU faults, 0 failed systemd units.

Risk: two-way door · M5 Macs (G17G, G17S, G17C) (a plain revert removes the capability bit from AGX_CAPS_M5; G13, G14, G15, G16, G17P, and G18G are unchanged).

Not yet: Live M5 (G17G) and M5 Pro (G17S) hardware A/B and CTS runs (all three M5 parts share AGX_ISA_ENCODING_AGX3C and AGX_CAPS_M5).

Details
  1. Capability table (src/asahi/lib/agx_chip_caps.h):
    • Add AGX_CAP_MOD3_REG_BANK_RA to AGX_CAPS_M5 (G17G, G17S, G17C) and update the capability comment.
    • Non-M5 chips (G13, G14, G15, G16, G18G) stay off; G17P is unchanged.
  2. Unit tests (src/asahi/lib/tests/test-chip-caps.c, src/asahi/compiler/test/test-g17p-mod3-ra.cpp):
    • Update test_mod3_reg_bank_ra() to expect G17P, G17G, G17S, and G17C.
    • Keep negative gating coverage in G17PMod3RA.NonG17PAndPreambleGating across G18G (AGX3D), G16G (AGX3B), G17P preambles, and G17C preambles, and add G17PMod3RA.M5ResolvesMod3Conflicts confirming all three M5 chips resolve the loop to zero mod-3 conflicts without spilling.
Evidence

Configuration and driver identities

  • Hardware: Mac Studio M5 Max (J775c, G17C B1, 40-core GPU), Linux 7.3.0 aarch64
  • Compiler: GCC 16.1.1 (-Dbuildtype=release -Db_ndebug=false -Dbuild-tests=true -Dtools=drm-shim -Dgallium-drivers=asahi -Dvulkan-drivers=asahi)
  • Arm A (baseline aurora-wip): 8c74e92d5162df704d1c79bef528806ef43923d7 (libvulkan_asahi.so SHA-256 673283188b5ea3fecec15f0b8b03a6c2f52e76e3275db28f5dc33055731fde7e)
  • Arm B (head satchlj/m5-mod3-reg-bank-ra): 0151657d581b12614b87119fd0d6157813f677bb (libvulkan_asahi.so SHA-256 a5d37075ad583c3adb058c4b9495a407326409493e61b6f70fd01b7a3494c83d)
  • Unit tests at 0151657d581b: MALLOC_PERTURB_=42 meson test -C build --suite asahi -> 322/322 OK (0 fail)

Same-machine 3-round interleaved A/B (MESA_SHADER_CACHE_DISABLE=1)

llama.cpp master 8af68d48 (Llama 2 7B Q4_0, llama-bench -ngl 99 -t 6 -b 2048 -ub 512 -ctk f16 -ctv f16 -fa 1 -r 3 with DRIRC_CONFIGDIR=src/asahi/vulkan), vkpeak (vkpeak-20260527), and gpubench-vk (--depths 1,8 --warmup-ms 200 --runs 3 --run-ms 500 --timestamps on):

Benchmark / Metric Baseline 8c74e92d5162 (3 rounds; median) Head 0151657d581b (3 rounds; median) Delta
llama-bench pp512 (t/s) 2,154.12 / 2,154.27 / 2,154.86 (2,154.27) 2,199.14 / 2,199.05 / 2,198.86 (2,199.05) +2.08%
llama-bench pp2048 (t/s) 2,060.56 / 2,059.95 / 2,059.92 (2,059.95) 2,101.70 / 2,101.75 / 2,100.84 (2,101.70) +2.03%
llama-bench pp512+tg128 (t/s) 384.35 / 383.79 / 383.24 (383.79) 385.39 / 385.21 / 383.86 (385.21) +0.37%
llama-bench tg128 (t/s) 99.68 / 99.93 / 99.40 (99.68) 99.75 / 99.18 / 99.43 (99.43) -0.25% (BW-bound)
llama-bench tg128 @ d2048 (t/s) 71.57 / 71.70 / 71.58 (71.58) 71.93 / 71.66 / 71.62 (71.66) +0.11%
vkpeak fp16-vec4 (GFLOPS) 32,039.81 / 32,037.82 / 32,040.27 (32,039.81) 32,142.77 / 32,139.73 / 32,145.77 (32,142.77) +0.32%
vkpeak int32-vec4 (GIOPS) 8,241.08 / 8,240.81 / 8,239.78 (8,240.81) 8,272.06 / 8,271.78 / 8,272.78 (8,272.06) +0.38%
vkpeak fp32-scalar (GFLOPS) 16,524.47 / 16,528.14 / 16,528.39 (16,528.14) 16,521.34 / 16,521.31 / 16,526.02 (16,521.34) -0.04%
vkpeak fp32-vec4 (GFLOPS) 16,532.20 / 16,532.36 / 16,533.27 (16,532.36) 16,533.54 / 16,527.64 / 16,533.89 (16,533.54) +0.01%
vkpeak fp16-scalar (GFLOPS) 32,355.06 / 32,347.44 / 32,346.84 (32,347.44) 32,355.05 / 32,316.83 / 32,349.51 (32,349.51) +0.01%
vkpeak fp16-matrix (GFLOPS) 62,786.07 / 62,786.18 / 63,029.47 (62,786.18) 62,785.30 / 62,788.34 / 62,781.04 (62,785.30) -0.00%
gpubench-vk compute.heavy d=8 (µs/submit) 135.612 / 135.428 / 135.501 (135.501) 135.465 / 135.465 / 135.722 (135.465) -0.03%
gpubench-vk render.heavy d=8 (µs/submit) 63.654 / 63.678 / 63.686 (63.678) 63.727 / 63.670 / 63.727 (63.727) +0.08%

Live Vulkan CTS A/B (vulkan-cts-1.4.7.1, MESA_SHADER_CACHE_DISABLE=1)

Group                                     Baseline (8c74e92d5162)    Head (0151657d581b)
dEQP-VK.api.smoke.*                       8/8 PASS, 0 FAIL           8/8 PASS, 0 FAIL
dEQP-VK.glsl.loops.*                      624/624 PASS, 0 FAIL       624/624 PASS, 0 FAIL
dEQP-VK.compute.pipeline.basic.*          80/81 PASS, 0 FAIL, 1 NS   80/81 PASS, 0 FAIL, 1 NS
dEQP-VK.compute.pipeline.builtin_var.*    11/11 PASS, 0 FAIL         11/11 PASS, 0 FAIL
dEQP-VK.ssbo.layout.single_basic_array.*  351/351 PASS, 0 FAIL       351/351 PASS, 0 FAIL
dEQP-VK.subgroups.arithmetic.compute.*    1608/2130 PASS, 0 FAIL, 522 NS   1608/2130 PASS, 0 FAIL, 522 NS
dEQP-VK.subgroups.shuffle.compute.*       1232/1680 PASS, 0 FAIL, 448 NS   1232/1680 PASS, 0 FAIL, 448 NS
Total                                     3914/4885 PASS, 0 FAIL, 971 NS   3914/4885 PASS, 0 FAIL, 971 NS

Kernel GPU/MMU fault delta: 0
Failed systemd units: 0 (before and after)

Add AGX_CAP_MOD3_REG_BANK_RA to AGX_CAPS_M5 (G17G, G17S, G17C) so the
AGX register allocator tie-breaks co-read GPR pairs across the three
32-bit register banks ((reg / 2) % 3) and coalesces single-use loop RMW
accumulator chains on non-preamble M5 shaders, matching G17P.

Non-M5 chips (G15, G16, G18G, AGX2) remain unchanged. Update
test-chip-caps.c and test-g17p-mod3-ra.cpp to cover M5 enablement while
preserving negative gating checks for G16G, G18G, and preambles.

Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj
satchlj requested review from a team and DjDeveloperr as code owners November 26, 2026 01:03

@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 at 0151657d: MERGE. Non-author review; no blockers.

Checked:

  • This turns on one existing capability bit in AGX_CAPS_M5, and the RA paths already key on that bit, not on chip IDs, so the change adds no gate. G13/G14/G15/G16/G18G/AGX2 stay off. The chip-caps test now asserts the exact set {G17P, G17G, G17S, G17C}.
  • The gating test still covers the off cases. G18G/AGX3D replaces the old G17G case, and a new G17C preamble case checks that preambles stay untouched on M5. The new M5ResolvesMod3Conflicts case runs RA for all three M5 chips and checks 0 bank conflicts and 0 scratch.
  • J775c evidence: asahi suite 322/322, the CTS sample identical to baseline (0 fail), 0 GPU faults, and the Llama pp512/pp2048 gains of about 2% are outside the noise of a 3-round interleaved A/B.
  • The parent is on aurora-wip, and the PR is mergeable.

Non-blocking:

  • No hosted checks ran on this branch. Please let CI run once before merge.
  • G17G and G17S rows are still owed, as the PR lists. All three share the encoding and the capability set, so the J775c row is good evidence for them.

@DjDeveloperr
DjDeveloperr merged commit d143d45 into aurora-wip Nov 26, 2026
oreater added a commit to oreater/mesa that referenced this pull request Nov 26, 2026
…k runs in mod-3 RA

Four issues in the mod-3 bank-conflict RA tie-breaking pass (aurora-silicon#997/aurora-silicon#1111)
regressed inner-loop code generation on multi-block convolution and GEMM
kernels on M5 (G17C):

1. loop_phi_targets was only populated inside block->loop_header, leaving
   it NULL in multi-block loop bodies. Bank-conflict detours stole enclosing
   loop-header phi targets and emitted multi-register cyclic mov1 copies on
   every iteration. Propagate each loop header's phi targets across the full
   loop range (header .. loop_last) and keep non-phi allocations off
   enclosing loop-header phi targets ahead of bank-conflict detours.
2. rmw_web only matched single-use loop-header phis globally (missing every
   loop accumulator also read after loop exit) and looked up phi_web[root].reg
   (which stays pinned to the pre-header source register when the pre-header
   stays live across the loop). It also kicked accumulators out whenever
   g17p_coread_bank_cost() was non-zero. Track the loop-header phi
   instruction directly (rmw_phi) for back-edge sources and RMW chains using
   in-loop use counts so loop-carried accumulators stay in place.
3. Mod-3 tie-breaking against a loop-invariant operand clustered consecutive
   independent 3-source FMA accumulators into back-to-back same-bank runs
   (e.g. bank 1,1,1 / 2,2,2 / 0,0,0), serializing pipelined bank ports on
   G17/M5. Add anti-bank edges between consecutive independent 3-source ALU
   destinations/accumulators (propagated to loop pre-header inits).
4. Keep low-weight outside-loop prologue conflicts (best_cost < 8) within
   the existing high-water mark so prologues do not inflate GPR footprint.

Add GTest regression coverage in test-g17p-mod3-ra for multi-block loops,
live-across pre-header phi sources, and adjacent 3-source FFMA accumulator
streams.

Signed-off-by: oreater <145754695+oreater@users.noreply.github.com>
@RyanTheTide
RyanTheTide deleted the satchlj/m5-mod3-reg-bank-ra branch November 27, 2026 13:21
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.

3 participants