Repository navigation
agx3: optimize byte LUT selects, nested read-only loops, direct-body LICM, and AGX3C uniform atomics - #1060
Conversation
…LICM, and AGX3C uniform atomics Signed-off-by: Diljit Singh <hey@djdev.me>
Exact-Head Hardware Verification — MacBook Neo (
|
| 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
left a comment
There was a problem hiding this comment.
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
aarch64build 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 (includingagx_tests,agx3_subgroup_core,agx3_alu_core,agx3_cf_core,agx3_mem_core, andagx3_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 FaildEQP-VK.compute.pipeline.basic.*: 80/81 Pass, 0 Fail (1 Not supported)dEQP-VK.subgroups.basic.compute.*: 12/12 Pass, 0 FaildEQP-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/smedian across 391 submits)- Kernel GPU/MMU fault delta across all runs:
GPU_FAULT_DELTA=0(0 -> 0).
- CI:
aurora-silicon/mesaruns under the local build + live Vulkan CTS waiver (0active /0failing checks on7a33ee1fb90b).
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>
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>
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) at7a33ee1fb90: release & assert (-Db_ndebug=false) builds +meson test --suite asahi206/206 PASS on both; Clang-Werror8/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
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 intoceil(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 redundantu2u8/u2u16 -> u2u32round-trips. Also adds depth-2bcselcondition-dominance algebraic simplifications.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 matchingfactor(e.g.8), folds pre-existing constant-derived bound predicates (such as0 < bound) inside the fast arm, and marks the cloned fallback inner looppartially_unrolled = trueso the cold fallback path does not inflate whole-shader register pressure.unswitch_uniform_ifs()hoists loop-invariant uniform two-armifs 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 byif (!init_exit)for single-top-exit bodies, excludingACCESS_BUFFER_BINDING_AGXfrom the 16-dword payload cap).agx_nir_opt_guard_chains.c,agx_nir_opt_guard_selected_loads.c):coalesce_adjacent_ifs_in_list()to wrap loop-free multi-blockthen_lists and hoist up to 16 pure condition-prep instructions from intermediate blocks under a single fast-path guard.agx_nir_opt_forward_merge_loads()to forward unclobbered non-volatile/non-coherentstore_agxto matchingload_agxin straight-line code and into the unaliased prefix of immediately followingifarms.agx_nir_opt_licm.c,agx_opt_licm.c):LICM_SPEC_ALLcapped at<= 48NIR halves;LICM_SPEC_SFU_CHAINcapped at<= 56NIR halves) plus pre-unrollagx_nir_opt_licm_direct_sfu(), rejecting speculative modes when onlyload_consts would hoist.agx_opt_sink_immediates()sinks single-block-usedMOV_IMMs whenuse_depth <= def_depthor 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.agx_compile.c):agx_get_sr_coverage_native_width_to()to respect both 16-bit and 32-bit destinations and enablesuniform_atomicssubgroup aggregation for non-fragmentAGX3C && !emit_agx3d.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)72c49c5ea0cc3a2b10efa9cd1179c7d5a21ca7e9(libvulkan_asahi.soSHA-256:df357d20bb5bdaaf44b7ed1c9348afaebc5f2f89b43fc925f387ac32dc375b74)7a33ee1fb90b56fe822d0092a8792650be6bbdc2(libvulkan_asahi.soSHA-256:080006a60c689352666105e2e8213a1e65cafd334bf954461402baca16a8c0d2)-Db_ndebug=true)meson test --suite asahi:206/206 OK, 0 Fail(both A and B)-Db_ndebug=false)meson test --suite asahi:206/206 OK, 0 Fail(B)-Werrorcheck on all 8 touched C/C++ files:8/8 PASS, 0 warnings, 0 errorscrashed=0,quarantined=0,0GPU/MMU faults,0kernel errors,0AVC denialsSame-Machine ABBA Private Geekbench 6.7.1 Vulkan (
PrivateNetwork=yes, 20 measured iterations/workload)Feature Matching Per-Kernel GPU Busy Time Breakdown (A avg vs B avg)
instrs/gprs)instrs/gprs)fast_corners209/69)242/65)scale_pyramid457/31)460/39)knn_match111/63)150/47)conv_h_gray352/79)353/79)compute_keypoints668/53)665/53)conv_v_gray563/87)565/87)calculate_descriptors222/47)214/55)sort_keypoints222/27)221/27)nonmax_suppression98/31)124/39)Targeted Vulkan & Zink GLES31 CTS (J714s)
dEQP-VK.spirv_assembly.instruction.compute.*dEQP-VK.compute.pipeline.basic.*dEQP-GLES31.functional.compute.*(Zink)dEQP-VK.subgroups.ballot_broadcast.compute.*dEQP-VK.robustness.buffer_access.compute.*