Repository navigation
agx: hoist compute loads/addrs and balance multi-slot waits on G14X (+1.13% 2B decode) - #1224
Conversation
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
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. |
fdae4ff to
7dc0f63
Compare
There was a problem hiding this comment.
find_first_use_pos() scans to the end of the block when a load has no nearby register use, and the 16-instruction lookahead can repeat that unbounded scan for several later operations. Long independent-load blocks can therefore make this scheduling pass quadratic. Precompute first-use positions or cap the scan consistently with the distances the heuristic uses. Add a long-block compile-time check, plus a compute synchronization case showing which threadgroup barriers device-load hoisting may cross safely.
|
Matched interleaved ABBA verification on Apple M2 Max (
|
|
CHANGES on 7dc0f63 [test] No CI checks are reported on this branch and the PR carries no full-suite receipt, so the change is unverifiable at head 7dc0f63 as filed; the diff itself reads clean (hoist dep-chain handling preserves def-before-use, hoist_can_cross blocks device stores/memory barriers/coherent loads, smart_waits is G14X-compute-gated with positive and negative unit tests on both passes), but merge needs CI or a suite receipt at this exact head. |
|
Addressed review feedback in
|
There was a problem hiding this comment.
The backward precomputation removes repeated suffix scans, resets both register and barrier boundaries, and preserves input positions because waits are inserted before the current instruction. An independent model agreed with the forward scan across 2,400 seeded blocks. The added tests cover the long-block case and distinguish the two barrier types. The author reports 1,714 compiler tests passed and one pre-existing skip at this head. Code approved. I did not run the full Mesa binary independently. Hosted checks are absent, so carry the exact suite receipt and have the landing owner confirm the G14X and required regression evidence.
727e9df to
2a02de4
Compare
There was a problem hiding this comment.
Verdict: FINISH, then merge at 2a02de4cc5b5
Blockers: Remove the prohibited attribution trailer from the rebased commit and provide a clean landing head with the required sign-off. Use a replacement branch or PR if cleaning the commit would require rewriting the published branch.
Checked: Confirmed the rebased commit's parent and message. The author reports 1,722 compiler tests and 767 chip-capability tests passed on this head, with one pre-existing skip. Carry the existing G14X and peer evidence to the clean head and obtain landing-owner confirmation.
Evidence
Reviewed PR source and recorded results at 2a02de4cc5b5.
…ait slots on G14X Add two AGX2 compute-shader scheduling passes gated via agx_chip_caps on G14X (Apple M2 Pro/Max/Ultra), with no new runtime switches: 1. AGX_CAP_COMPUTE_HOIST_LOAD_ADDRS (1u << 28; agx_hoist_loads in agx_pressure_schedule.c, run after agx_ilp_schedule on AGX2 compute): hoists non-coherent device_loads together with up to 3 pure SSA address-producing predecessors (depth <= 4) up to 64 instructions earlier while maintaining a strictly-earlier SSA dominance invariant. 2. AGX_CAP_COMPUTE_SMART_WAITS (1u << 27; agx_insert_waits_local in agx_insert_waits.c): precomputes per-block first-use positions in a single O(N) backward pass (respecting #1232 reorderable loads across threadgroup barriers) and partitions the two hardware scoreboard slots by first-use distance to eliminate mid-burst AGX_MAX_PENDING=8 slot-0 overflow stalls. Rebased cleanly onto aurora-wip 7617c83 (preserving #1232 drain_on_tg_barrier and #1233 G13X CDM defer flush). Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
2a02de4 to
bb81a8a
Compare
There was a problem hiding this comment.
Verdict: HOLD at bb81a8ad8d4c
Blockers: Landing-owner confirmation of the G14X and peer runtime evidence. Hosted checks are absent.
Checked: Code approved. The new head has the required sign-off and resolves the prior commit-message blocker. GitHub reports identical source tree and parent IDs for this head and the tested revision.
|
Updated commit trailer at |
|
|
|
GREEN on bb81a8a GREEN on bb81a8a [test] Prior CHANGES resolved at head: agx_tests full 154-suite run (1722 pass / 0 fail / 1 pre-existing skip) documented in the PR body at tree 2cf39081e0e1, verified identical to head's tree (git rev-parse bb81a8a^{tree}). CTS 440-case runs show 0 diffs on both base commits; chip-caps 767/767; RyanTheTide cross-machine PASS comment at this head. The receipt attests that documented run - Mesa was not rebuilt locally. Full-suite receipt: /tmp/receipt-1224.json |
|
Forward-merged |
There was a problem hiding this comment.
Verdict: MERGE at 2d6602a after the current-head hardware rows.
Checked: The forward merge keeps coherent store and queued buffer copy at 26/27 and moves the two G14X capabilities to distinct bits 28/29. The chip tests assert G14X scope and retain both base checks. The reported host suite passed Vulkan and chip-table tests. The prior target and regression results cover the previous head. Please refresh hardware evidence on this integration and recheck the shared chip table when the other branch lands.
|
@DjDeveloperr, code-owner heads-up: App approval at |
|
Merge-train landing at
Revert: |
… comments Follow-up hygiene for #1224: - Gate agx_hoist_loads on !(agx_compiler_debug & AGX_DBG_NOSCHED) in agx_compile_function_nir(), matching agx_pressure_schedule and agx_ilp_schedule so AGX_MESA_DEBUG=nosched disables all scheduling passes. - Document in hoist_can_cross() why non-coherent device_loads may cross AGX_OPCODE_THREADGROUP_BARRIER without inspecting memory_can_reorder (global/device-scope barriers emit AGX_OPCODE_MEMORY_BARRIER first, where hoisting stops). - Clarify AGX_CAP_COMPUTE_SMART_WAITS and AGX_CAP_COMPUTE_HOIST_LOAD_ADDRS comments in agx_chip_caps.h to reflect that AGX_CHIP_G14X covers gen-14 Pro/Max/Ultra (G14S/G14C/G14D), with measurements collected on G14C. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
G13 measurement addendum (the
|
| cell | base → hoist | Δ | pairs won | bit-exact |
|---|---|---|---|---|
| decode | 23.20 → 23.30 tok/s | +0.46% | 3/5 | yes, all legs |
| prefill | 136.2 → 134.9 tok/s | −0.91% | 0/5 | yes |
Per-pair decode: −0.02, +1.67, −1.95, +0.27, +2.13%. Prefill: −0.74, −0.91, −0.79, −0.67, −1.11%.
G13X (16-inch M1 Max, gen=64).
| cell | decode base → hoist | Δ | pairs won | prefill base → hoist | Δ | bit-exact |
|---|---|---|---|---|---|---|
| ctx512 | 89.17 → 89.22 tok/s | +0.06% | 2/5 | 414.5 → 412.1 tok/s | −0.59% | yes, 5/5 |
| ctx2048 | 66.90 → 66.77 tok/s | −0.19% | 2/5 | 493.6 → 487.4 tok/s | −1.26% | yes, 5/5 |
Correctness at the exact head (native aarch64, clang 18.1.3 release): asahi-agx-chip-caps 628/628, HoistLoads.* 10/10, meson test --suite asahi 212/212 — 0 fail/skip/timeout. Sync CTS on G13G (dEQP-VK.synchronization.*, synchronization2.*, memory_model.*, 16,421 cases): base 5,175 Pass / 11,246 NotSupported / 0 Fail, hoist identical, 0 status changes, 0 regressions.
Read: the G13 dies already take the load-latency win from agx_ilp_schedule's occupancy-capped intra-block hoisting (shared_compute_loads, agx_pressure_schedule.c:2102-2225, which skips has_cooperative_matrix for small_loop_loads). Unbounded post-schedule hoisting on top adds nothing measurable in decode (+0.46% G13G, +0.06%/−0.19% G13X — inside noise) and costs prefill (−0.91% G13G, −0.59%/−1.26% G13X). Recommendation from the numbers: keep AGX_CAP_COMPUTE_HOIST_LOADS closed on G13G/G13X; the cap and pass land here for the G14X result and as the off-switch, with the G13 negative result on record so it is not re-litigated.
What
Add post-schedule compute load/address hoisting (
agx_hoist_loads+addr_chain) and multi-slot wait balancing (AGX_CAP_COMPUTE_SMART_WAITS) on Apple M2 Max (G14X/G14C) on top ofaurora-wip, with full unit tests and Apple M2 Max decode/CTS verification.aurora-silicon/mesaaurora-wip):7617c835cd8b(benchmarked matched againstaurora-wip@3edbd1c46211and re-verified onaurora-wip@a15657a362b7, harmonized cleanly with merged#1232drain_on_tg_barrierand#1233G13XCDM defer flush)agx/agx2-compute-hoist-addr-smart-waits, single cohesive commitbb81a8ad8d4cd5f9983a81894baff8df066db492(9files,+685/-8:agx_chip_caps.h,test-chip-caps.c,agx_compile.c,agx_compiler.h,agx_insert_waits.c,agx_pressure_schedule.c,meson.build,test-hoist-loads.cpp,test-insert-waits.cpp)G14Xcapability enablement + failing-on-base unit tests):agx_hoist_loads+ address-producer hoisting (agx_pressure_schedule.c,agx_compile.c,agx_compiler.h), lifting compute device loads and their address arithmetic above independent ALU after scheduling.AGX_CAP_COMPUTE_SMART_WAITSinagx_chip_caps.handagx_insert_waits.c), splitting>8-load compute bursts across scoreboard slots so loops avoid AGX2's 8-pending-load mid-burstslot 0stall.G14X(Apple M2 Max, leavingG13G,G13X,G14G,G14S,G14D, fragment shaders, and AGX3/Gen 15+ untouched;G13Xwill be proposed separately once measured onaurora-wip), with no new runtime env switches.Table 1: Measured Results on
aurora-wipBase (Apple M2 Max, G14C B1)Matched interleaved ABBA across three
aurora-wip.sobinaries built from the exact same base (MESA_SHADER_CACHE_DISABLE=1,MLX_OMARCHY_DEFER_TOKENS=0,omarchy-mlx819625f8f34e, zero driver env flags,/proc/self/maps+ SHA-256 verified, 100% bit-identical greedy token digests):aurora-wip)basevssmart_waitsonly4784df039da04560basevshoist_addr + smart_waits(this PR)4784df039da04560smart_waitsvshoist_addr + smart_waits4784df039da04560basevshoist_addr + smart_waits(this PR)c5fb4074d0b56223basevshoist_addr + smart_waits(this PR)cedd5549b251572aThe 3-way comparison shows that
agx_hoist_loads+ address hoisting adds+0.52%(4/5) on top ofsmart_waitsalone even alongsideaurora-wip'sagx_ilp_schedule, for a combined+1.13%(5/5,-50.0 us/tok) win onQwen3.8-2B ctx=512and+0.70%(5/5) onctx=2048.Table 2: Reference Measurements on Shipped Mesa Vulkan Driver Line (
1650fc1a33, non-aurora-wip)For reference on our shipped Mesa Vulkan driver line (
1650fc1a33, which usesagx_pressure_schedulerather thanagx_ilp_schedule), matched same-binary interleaved ABBA (MESA_SHADER_CACHE_DISABLE=1,MLX_OMARCHY_DEFER_TOKENS=0,omarchy-mlxf63bb9878) togglingAGX_HOIST_LOADS=0vs1won all24/24decode pairs and all6/6prefill cells (zero regressions, bit-exact):=0)=1)=0->=1)4784df039da04560c5fb4074d0b56223a6fad159dfa900479115b5280c1d7e33cedd5549b251572a5b327e139ad9b881Enabling all three (
AGX_HOIST_LOADS+AGX_HOIST_ADDR+AGX_SMART_WAITS) on the shipped line adds another+1.85%(5/5) onomarchy-mlx819625f8f34e(2B@512:202.71 -> 206.42 tok/s,2B@2048:198.74 -> 202.49,9B@512:63.41 -> 64.35,9B@2048:62.13 -> 63.10,16/16wins, bit-exact).Conformance & Unit Tests
test-chip-caps):767/767checks PASSED (verifyingAGX_CAP_COMPUTE_SMART_WAITS = 1u << 27andAGX_CAP_COMPUTE_HOIST_LOAD_ADDRS = 1u << 28strictly onG14X, clear of merged#12191u << 25, unchanged onG13G/G13X/G14G/G14S/G14D).agx_tests): Full 154-suiteagx_testsrun on the exact tree (2cf39081,bb81a8ad8d4catopaurora-wip@7617c835cd8b):1722passed,0failed,1pre-existing skip (test-rte-fma.cpp:245), including16/16HoistLoads.*:InsertWaits.*(0 ms, coveringAddrProducerNeverMovesDownward,SmartWaitsAvoidsMidBurstOverflowOnG14X,SmartWaitsLinearOnLongIndependentLoadBlock, andComputeSyncCrossesThreadgroupBarrierStopsAtMemoryBarrier).deqp-vkon Apple M2 Max G14C,MESA_SHADER_CACHE_DISABLE=true,cases-8bit.txt440 cases):aurora-wipbasevssmart_waits:440total (111 Pass,329 NotSupported,0 Fail) vs440(111 Pass,329 NotSupported,0 Fail),diffs=0.aurora-wipbasevshoist_addr + smart_waits(this PR, verified on both3edbd1c4and rebaseda15657a3):440total (111 Pass,329 NotSupported,0 Fail) vs440(111 Pass,329 NotSupported,0 Fail),diffs=0.Risk
Two-way ·
G14X(Apple M2 Max) compute shader scheduling and wait-slot assignment only; fragment shaders,G13G,G13X,G14G/G14S/G14D, and AGX3/Gen 15+ are unchanged.