Skip to content

agx3: optimize byte LUT selects, nested read-only loops, direct-body LICM, and AGX3C uniform atomics - #1060

Merged
RyanTheTide merged 1 commit into
aurora-wipfrom
perf/agx3-feature-matching-opts
Nov 25, 2026
Merged

RyanTheTide merged 1 commit into
aurora-wipfrom
perf/agx3-feature-matching-opts

Conversation

@DjDeveloperr

Copy link
Copy Markdown

What: Generic AGX3 compute compiler optimizations for byte-LUT select trees, exact-bound nested read-only loops, uniform loop unswitching, multi-block guard-chain coalescing, straight-line store-to-load forwarding, occupancy-safe direct-body LICM, cross-loop immediate sinking, and AGX3C compute uniform-address atomic aggregation. Cuts Geekbench 6.7.1 Vulkan Feature Matching GPU busy time on J714s (M5 Pro / G17S B1) by -0.727 ms (-8.85%, 8.219 ms -> 7.492 ms) with zero regressions on all 7 other workloads.
Tested: J714s M5 Pro (G17S B1, kernel 7.3.0-m5-cdirect15) at 7a33ee1fb90: release & assert (-Db_ndebug=false) builds + meson test --suite asahi 206/206 PASS on both; Clang -Werror 8/8 touched files clean; private ABBA Geekbench 6.7.1 Vulkan (-8.85% Feature Matching, 0 regressions on all 7 other workloads); targeted Vulkan & Zink GLES31 CTS 10,713 Pass, 0 diffs vs baseline, 0 failures, 0 GPU faults.
Risk: two-way door · M3, M4, M5, Neo (shared AGX3 compiler passes in Borealis and Asahi; no model or board gating).
Not yet: Hardware re-verification on Neo (G17P) and M4 (G16); all passes are capability/encoding-driven across AGX3B/AGX3C and covered by compiler unit tests.

Details
  1. Byte-LUT select-tree packing (agx_nir_opt_pack_byte_lut_select.c, agx_nir_algebraic.py): Detects loop-invariant 8..16-entry byte select trees indexed by a provably bounded index inside a loop, packs the bytes into ceil(N/4) 32-bit words via 16-bit half pairs in the preheader, replaces the 15-select tree with 1..3 word selects plus a dynamic byte extract, and bypasses redundant u2u8/u2u16 -> u2u32 round-trips. Also adds depth-2 bcsel condition-dominance algebraic simplifications.
  2. Exact-bound nested read-only loop specialization, uniform loop unswitching, and read-only loop load hoisting (agx_nir_unroll_runtime_loops.c):
    • specialize_exact_nested() specializes a read-only outer loop whose inner counted loop has an outer-invariant runtime bound matching factor (e.g. 8), folds pre-existing constant-derived bound predicates (such as 0 < bound) inside the fast arm, and marks the cloned fallback inner loop partially_unrolled = true so the cold fallback path does not inflate whole-shader register pressure.
    • unswitch_uniform_ifs() hoists loop-invariant uniform two-arm ifs out of enclosing loops (rematerializing pure invariant conditions when computed inside the loop body).
    • agx_nir_hoist_readonly_loop_loads() hoists loop-invariant non-volatile/non-coherent global loads out of read-only loops (directly for unconditional header loads, guarded by if (!init_exit) for single-top-exit bodies, excluding ACCESS_BUFFER_BINDING_AGX from the 16-dword payload cap).
  3. Multi-block guard-chain coalescing & straight-line/arm-prefix store-to-load forwarding (agx_nir_opt_guard_chains.c, agx_nir_opt_guard_selected_loads.c):
    • Extends coalesce_adjacent_ifs_in_list() to wrap loop-free multi-block then_lists and hoist up to 16 pure condition-prep instructions from intermediate blocks under a single fast-path guard.
    • Extends agx_nir_opt_forward_merge_loads() to forward unclobbered non-volatile/non-coherent store_agx to matching load_agx in straight-line code and into the unaliased prefix of immediately following if arms.
  4. Occupancy-safe direct-body LICM & backend cross-loop immediate sinking (agx_nir_opt_licm.c, agx_opt_licm.c):
    • Two-tier occupancy-safe direct-body NIR LICM (LICM_SPEC_ALL capped at <= 48 NIR halves; LICM_SPEC_SFU_CHAIN capped at <= 56 NIR halves) plus pre-unroll agx_nir_opt_licm_direct_sfu(), rejecting speculative modes when only load_consts would hoist.
    • Backend agx_opt_sink_immediates() sinks single-block-used MOV_IMMs when use_depth <= def_depth or when the immediate would otherwise remain live-in across a strictly deeper inner loop; agx_opt_licm() mirrors this by not hoisting outer-loop immediates across enclosed inner loops.
  5. AGX3C non-fragment uniform-address atomic aggregation (agx_compile.c):
    • Fixes agx_get_sr_coverage_native_width_to() to respect both 16-bit and 32-bit destinations and enables uniform_atomics subgroup aggregation for non-fragment AGX3C && !emit_agx3d.
  6. Unit tests (test-agx3-feature-matching-opts.cpp): 16 GoogleTest cases covering exactness and negative guards for every pass.
Evidence

Build, Unit Tests, and Clang -Werror (J714s / 7.3.0-m5-cdirect15)

  • Base (A): 72c49c5ea0cc3a2b10efa9cd1179c7d5a21ca7e9 (libvulkan_asahi.so SHA-256: df357d20bb5bdaaf44b7ed1c9348afaebc5f2f89b43fc925f387ac32dc375b74)
  • Candidate (B): 7a33ee1fb90b56fe822d0092a8792650be6bbdc2 (libvulkan_asahi.so SHA-256: 080006a60c689352666105e2e8213a1e65cafd334bf954461402baca16a8c0d2)
  • Release build (-Db_ndebug=true) meson test --suite asahi: 206/206 OK, 0 Fail (both A and B)
  • Assert build (-Db_ndebug=false) meson test --suite asahi: 206/206 OK, 0 Fail (B)
  • Clang -Werror check on all 8 touched C/C++ files: 8/8 PASS, 0 warnings, 0 errors
  • GPU health & kernel log: crashed=0, quarantined=0, 0 GPU/MMU faults, 0 kernel errors, 0 AVC denials

Same-Machine ABBA Private Geekbench 6.7.1 Vulkan (PrivateNetwork=yes, 20 measured iterations/workload)

Workload 1A (ms) 4A (ms) A avg (ms) 2B (ms) 3B (ms) B avg (ms) Delta (ms) %
Background Blur 2.830 2.831 2.830 2.827 2.838 2.832 +0.002 +0.07%
Face Detection 4.105 4.092 4.098 4.091 4.088 4.089 -0.009 -0.22%
Horizon Detection 4.861 4.877 4.869 4.888 4.876 4.882 +0.013 +0.27%
Edge Detection 3.625 3.633 3.629 3.618 3.635 3.626 -0.002 -0.06%
Gaussian Blur 2.379 2.393 2.386 2.397 2.389 2.393 +0.007 +0.28%
Feature Matching 8.229 8.209 8.219 7.501 7.483 7.492 -0.727 -8.85%
Stereo Matching 0.673 0.672 0.672 0.670 0.673 0.671 -0.001 -0.12%
Particle Physics 9.585 9.586 9.586 9.587 9.583 9.585 -0.001 -0.01%

Feature Matching Per-Kernel GPU Busy Time Breakdown (A avg vs B avg)

Kernel A avg (ms) (instrs/gprs) B avg (ms) (instrs/gprs) Delta (ms) %
fast_corners 1.932 (209/69) 1.649 (242/65) -0.283 -14.6%
scale_pyramid 1.248 (457/31) 1.102 (460/39) -0.146 -11.7%
knn_match 1.128 (111/63) 0.825 (150/47) -0.303 -26.9%
conv_h_gray 0.878 (352/79) 0.879 (353/79) +0.001 +0.1%
compute_keypoints 0.778 (668/53) 0.783 (665/53) +0.005 +0.6%
conv_v_gray 0.770 (563/87) 0.769 (565/87) -0.001 -0.1%
calculate_descriptors 0.754 (222/47) 0.760 (214/55) +0.006 +0.8%
sort_keypoints 0.626 (222/27) 0.629 (221/27) +0.003 +0.5%
nonmax_suppression 0.112 (98/31) 0.103 (124/39) -0.009 -8.0%

Targeted Vulkan & Zink GLES31 CTS (J714s)

Suite Arm A Arm B Diffs / Fails
dEQP-VK.spirv_assembly.instruction.compute.* 10036 Pass / 9841 NS / 29 Fail 10036 Pass / 9841 NS / 29 Fail 0 diffs
dEQP-VK.compute.pipeline.basic.* 80 Pass / 1 NS 80 Pass / 1 NS 0 diffs
dEQP-GLES31.functional.compute.* (Zink) 195 Pass 195 Pass 0 diffs
dEQP-VK.subgroups.ballot_broadcast.compute.* — 264 Pass / 1356 NS 0 fails
dEQP-VK.robustness.buffer_access.compute.* — 138 Pass / 66 NS 0 fails

…LICM, and AGX3C uniform atomics

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested a review from a team as a code owner November 25, 2026 14:19
@DjDeveloperr

Copy link
Copy Markdown
Author

Exact-Head Hardware Verification — MacBook Neo (J700, Apple A18 Pro, G17P B1 / AGX3B) — PASS (7a33ee1fb90b)

  • Exact head tested: 7a33ee1fb90b56fe822d0092a8792650be6bbdc2 vs base 72c49c5ea0cc3a2b10efa9cd1179c7d5a21ca7e9 (release -Db_ndebug=true, verified deviceName = Apple A18 Pro (G17P B1), driverInfo (git-7a33ee1fb9), empty BUILD-DIFF.patch).
  • Fedora --suite asahi: 206/206 PASS (FeatureMatchingOpts 16/16), 0 warnings across all 12 touched files (CI and release).
  • Targeted Vulkan CTS (vk-default mustpass, MAX_RECOVERIES=0): 1,062 Pass / 13 NotSupported / 0 Fail, 0 recoveries:
    • dEQP-VK.compute.pipeline.basic.*: 80 Pass / 1 NotSupported / 0 Fail
    • dEQP-VK.glsl.loops.*: 624 Pass / 0 Fail
    • dEQP-VK.subgroups.basic.*: 70 Pass / 0 Fail
    • dEQP-VK.glsl.builtin.function.integer.bitfield*: 288 Pass / 12 NotSupported / 0 Fail
  • gpubench-vk compute smoke: 5/5 valid (conv2d gaussian/bilateral, edge sobel/harris, stereo), exact CRCs.
  • Host health: 0 GPU fault delta, 0 AVC delta, 0 failed units (7.3.0-41.fc44.aurora.aarch64, SELinux Enforcing).

Strict ABBA Offline Geekbench 6.7.1 Vulkan (20 iters/workload, GPU-busy ms/iter median)

Workload Base (72c49c5ea0) A1 / A2 #1060 (7a33ee1fb9) B1 / B2 Delta
Feature Matching 23.435 / 23.457 21.398 / 21.338 -8.86%
Face Detection 14.362 / 14.392 14.347 / 14.356 -0.18%
Stereo Matching 3.232 / 3.232 3.226 / 3.227 -0.17%
Gaussian Blur 11.313 / 11.293 11.297 / 11.311 +0.01%
Horizon Detection 24.116 / 24.065 24.146 / 24.062 +0.05%
Edge Detection 18.632 / 18.612 18.633 / 18.632 +0.06%
Background Blur 9.907 / 9.930 9.972 / 9.976 +0.55%
Particle Physics* 49.219 / 49.220 45.442 / 45.426 -7.69%*

*Particle Physics selected X=64 (80b5f9d4) on A1/A2 and X=32 (f679d2eb) on B1/B2; 0 validation errors and 0 shader compiler warnings across all 4 legs.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verdict: MERGE at 7a33ee1fb90b

Blockers: none

Checked: Full diff across all 12 files (+3255/-103), AGX3C subgroup coverage width handling and non-fragment uniform_atomics gating in agx_compile.c, single-use guards on depth-2 bcsel algebraic rules, loop-free / non-trapping / dominance-preserving adjacent-if coalescing in agx_nir_opt_guard_chains.c, alias/volatility checks in agx_nir_opt_guard_selected_loads.c, two-tier speculative direct-body LICM safety guards in agx_nir_opt_licm.c, bounded index and tree fanout validation in agx_nir_opt_pack_byte_lut_select.c, lane_dependent() / remat_outer() / read-only loop load hoisting in agx_nir_unroll_runtime_loops.c, inner-loop immediate sinking in agx_opt_licm.c, native GCC 16 -Db_ndebug=false build, meson test --suite asahi, and live Vulkan CTS plus compute stress on Mac Studio M5 Max (J775c, T6050 G17C). Untested scope: G18G / AGX3D hardware execution (verified by unit tests and disassembly corpus only).

Evidence
  • Native aarch64 build on Mac Studio M5 Max (J775c, T6050) with GCC 16.1.1 (-Dbuildtype=release -Db_ndebug=false -Dbuild-tests=true -Dplatforms=wayland -Dglx=disabled -Dgallium-drivers=asahi,zink -Dvulkan-drivers=asahi): clean build.
  • meson test -C build --suite asahi: 206/206 OK, 0 Fail (including agx_tests, agx3_subgroup_core, agx3_alu_core, agx3_cf_core, agx3_mem_core, and agx3_native_corpus_disasm; 60/60 targeted *FeatureMatching*:*Lut*:*Guard*:*Licm*:*Unroll*:*Sink* tests passed).
  • Live Vulkan CTS on Apple M5 Max (G17C B1) (Mesa 26.3.0-devel (git-7a33ee1fb9), Borealis):
    • dEQP-VK.api.smoke.*: 8/8 Pass, 0 Fail
    • dEQP-VK.compute.pipeline.basic.*: 80/81 Pass, 0 Fail (1 Not supported)
    • dEQP-VK.subgroups.basic.compute.*: 12/12 Pass, 0 Fail
    • dEQP-VK.subgroups.ballot_broadcast.compute.*: 264/1620 Pass, 0 Fail (1356 Not supported)
    • dEQP-VK.subgroups.arithmetic.compute.subgroup*_*int: 42/84 Pass, 0 Fail (42 Not supported)
    • dEQP-VK.robustness.buffer_access.compute.*: 138/204 Pass, 0 Fail (66 Not supported)
    • gpubench-vk --test compute.heavy --depths 1: ok (4198.3 GFLOP/s median across 391 submits)
    • Kernel GPU/MMU fault delta across all runs: GPU_FAULT_DELTA=0 (0 -> 0).
  • CI: aurora-silicon/mesa runs under the local build + live Vulkan CTS waiver (0 active / 0 failing checks on 7a33ee1fb90b).

@RyanTheTide
RyanTheTide merged commit 08daa3e into aurora-wip Nov 25, 2026
RyanTheTide added a commit that referenced this pull request Nov 27, 2026
The base branch perf/agx3-unroll-jam-vision (#657) is merged into
aurora-wip, which since gained the skip_runtime_unroll set
(specialize_exact_nested, #1060) in agx_nir_unroll_runtime_loops.c.
Resolve: unswitch_nested() takes both the skip set and this branch's
small_peels list; the caller runs unswitch_uniform_ifs() and
specialize_exact_nested() first, then the small-window unswitch and
peels. test-agx3-vision-opts.cpp keeps the tests of both sides.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
RyanTheTide added a commit that referenced this pull request Nov 27, 2026
Forward-merge of #700 onto aurora-wip 65866bb. #1060 and #1183
landed related changes in the two touched passes:

- agx_nir_opt_guard_selected_loads.c: keep aurora-wip's store_matches_load()
  and straight-line/arm-prefix forwarding from #1060, drop this branch's
  duplicate same-block walk, and route every raw-format check through
  is_raw_forwarding_format() (pure-integer formats only), as this branch
  intended.
- agx_nir_unroll_runtime_loops.c: analyze_loop_opts() takes both
  allow_runtime_step (#1183) and allow_nested (this branch);
  unswitch_nested() takes skip_runtime_unroll and outer3_peels.
- test-agx3-vision-opts.cpp: keep the tests from both sides.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide
RyanTheTide deleted the perf/agx3-feature-matching-opts branch November 27, 2026 13:20
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