Skip to content

agx: unswitch affine interior bounds guards and peel rotated 2D stencils - #762

Closed
DjDeveloperr wants to merge 4 commits into
perf/agx3b-flatten-tile-load-burstsfrom
perf/agx3b-interior-bounds-stencil-peel
Closed

DjDeveloperr wants to merge 4 commits into
perf/agx3b-flatten-tile-load-burstsfrom
perf/agx3b-interior-bounds-stencil-peel

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 23, 2026 •

Copy link
Copy Markdown

Split out from #758 per review (#issuecomment-7088943090 / #issuecomment-7088946412), stacked on #761 (f9f69ac793a). (Note: this head sits on #761 R3; once #761 lands, this PR will be cleanly rebased onto the merged base if needed.)

Summary

  1. agx: unswitch affine interior bounds guards out of stencil loops (4fa09f548ff)
    • Unswitches 1D and 2D affine coordinate bounds guards (0 <= base + iv * stride < limit) out of counted stencil loops using an exact zero-overflow interior predicate (bound > 0 && stride >= 0 && base >= 0 && base < limit && umul_high(bound - 1, stride) == 0 && (bound - 1) * stride < (uint32_t)(limit - base)), producing a branchless interior fast path and marking the cold border fallback partially_unrolled.
    • Allows load_global_constant with ACCESS_CAN_SPECULATE in pure_loop_invariant (which also widens agx_nir_opt_unswitch_invariant_if).
    • Fixes from #758 and #762 reviews:
      • SSA dominance in 2D guard: emit_interior_check clones remap into isolated child hash tables (clone_remap_table) for pos_if (bound > 0) and chk_if (stride >= 0 && base >= 0), preventing in-loop defs cloned inside y's nested branches from leaking into x's check (AGX3VisionOpts.InteriorBounds2DSharedInLoopConstLimit).
      • Fault safety on top-tested inner trip == 0: emit_interior_check rematerializes only bound_out before if (bound_out > 0) (requiring header_safe_invariant for the 2D inner bound), rematerializes base_out/stride_out inside if (bound_out > 0), and rematerializes limit_out inside if (stride >= 0 && base >= 0) (AGX3VisionOpts.InteriorBounds2DInLoopConstLoadsTripZero).
      • Fault safety on 2D outer loop with early break/continue: Added outer_has_jump_outside() rejecting outer loops containing any break/continue/return outside the loop terminator and inner loop (AGX3VisionOpts.InteriorBounds2DEarlyOuterBreakTripZero, testing early outer break with poison unmapped addresses).
      • Whole-function and loop-size budgets: max_fn_instrs = 1024 (measured across the 80-SPV Geekbench 6 Vulkan corpus: stencil/vision shaders are 73..266 pre-unswitch NIR ops — b7279a25 73, gauss-h 91, gauss-v 94, bc7e1ec6 101, face-depthwise/720b8163 153, stereo 266; the largest non-GEMM compute shader 07bceaa7 is 869 ops; already-unrolled tiled GEMM megashaders face-gemm-aligned 1054 and face-gemm-edge 1095 sit just above 1024 and are cleanly skipped), 2D outer body <= 120 (below the 256 downstream 3x3 cap), 1D body 4..80.
      • Fixed imadshl_agx formula ((a * b) + (c << sh)) and 8-bit load masking in the unit-test NIR interpreter.
  2. agx: extend small-window 3x3 and 4x peeling to rotated 2D stencil loops (8f7cee6d4c1)
    • Extends peel_small_window_inner_loop and peel_small_3x3_outer_loop to rotated (bottom_tested) compact branchless 2D stencil loops (<= 40 NIR ops -> <= 160 ops at 4x peel).
    • Preserves <= 64 outer 3x3 peel cap for top-tested nests and uses <= 80 for rotated nests (3 * 80 = 240 <= 256).
    • Checks latch_register (iv_reg) before emitting bound_def in peel_straight_prefix and restores SSA on bail-out.
    • Added AGX3VisionOpts.Rotated8BitInnerNonZeroStart verifying the f >= 8 && loop_has_8bit_load(inner) arm on rotated 8-bit inner loops with non-zero positive/negative/near-INT32 starts and trips 1..10.

Reach

Runs under agx3_compute_opts / agx3_unroll ((AGX3B || AGX3C) && !emit_agx3d), reaching all shader stages on AGX3B (G15/G16/G17P/G17A) and AGX3C without emit_agx3d (G17G/G17S / M5). AGX2 and G18G are unchanged.

Per-Chip Binary-Size & Shader-DB Table (80 GB6 Vulkan SPVs, #762 R3 8f7cee6d4c1 vs #761 R3 f9f69ac793a)

All 4 chips: 80/80 OK, 0 fails, 0 spills, 0 thread-occupancy drops (all 1024 threads); exactly 4/80 shaders touched (3 unique kernels: bc7e1ec6, b7279a25, face-depthwise/720b8163):

Chip Touched Total Instrs Total Bytes bc7e1ec606976e14 face-depthwise (720b8163) b7279a25da0866d2
G15G (M3) 4/80 16149 -> 17210 (+6.57%) 155248 -> 165394 (+6.54%) 183->535i, 1752->4852B (2.77x), GPR 29->41 238->478i, 2342->4810B (2.05x), GPR 25->33 148->377i, 1350->3460B (2.56x), GPR 39->43
G16G (M4) 4/80 16149 -> 17210 (+6.57%) 155248 -> 165394 (+6.54%) 183->535i, 1752->4852B (2.77x), GPR 29->41 238->478i, 2342->4810B (2.05x), GPR 25->33 148->377i, 1350->3460B (2.56x), GPR 39->43
G17P (A18 Pro / M4 Pro) 4/80 16393 -> 17389 (+6.08%) 168136 -> 178250 (+6.02%) 170->494i, 1710->4938B (2.89x), GPR 29->29 229->462i, 2336->4776B (2.04x), GPR 25->33 147->353i, 1364->3370B (2.47x), GPR 39->39
G17S (M5) 4/80 13456 -> 14411 (+7.10%) 127022 -> 136814 (+7.71%) 147->491i, 1494->5058B (3.39x), GPR 25->39 205->405i, 1952->4010B (2.05x), GPR 23->33 135->346i, 1272->3384B (2.66x), GPR 31->39

(Border fallback path: cold border threads execute the exact original un-unrolled loop guarded behind one upfront interior check, adding only the ~6-op upfront predicate on border lanes while interior threads execute the completely branchless peeled 3x3 fast path.)

Verification

  • Assert-enabled (-Db_ndebug=false) meson test --suite asahi --suite poly --timeout-multiplier 2: 170/170 OK (0 fails).
  • Hardware rows (Neo G17P ABCCBA + CTS, plus cross-chip M4/M5/M3 rows) posted in comments below.

@RyanTheTide

Copy link
Copy Markdown

Review at 7110ac2.

The split helps, and the two bugs from #758 are fixed for the cases reported there: child remap tables per nested guard (agx_nir_unroll_runtime_loops.c:2940, :2952) keep y's clones out of x's check, and base/stride/limit are now emitted under bound > 0 / base >= 0 with a header-safe inner bound (:3148). The two new interpreter tests cover both. Remaining:

  1. Fault safety, 2D outer loop: the "iteration 0 runs these loads" argument assumes the outer body reaches the guard on iteration 0. The 1D path gets that from count_unrollable (:2809), but the nested path only checks count_instrs(loop) > 120 (:2806), and cf_list_has_outer_jump (:2841) looks only inside the guarded arm. splittable_outer allows any break/continue, so an outer body with if (c) break; or continue before the guard still matches. The outer limit and all inner bound/base/stride/limit loads (non-speculatable load_global_constant, :3165-3171) are then read before the loop although the original never read them when iteration 0 leaves early. Please reject outer loops with a jump outside the terminator and the inner loop, and add a trip-0-style test with an early outer break and a poison address.
  2. :1763: f >= 8 && loop_has_8bit_load(inner) now also takes rotated inner loops (previously !cl.bottom), without the init == 0 / compact-body limits of the new arm. The rotated test uses 32-bit loads only; please add a rotated 8-bit case with a non-zero start.
  3. Commit 1 says pure_loop_invariant "now permits load_preamble and load_push_constant"; those were already allowed. The actual change (:2093) is load_global_constant with ACCESS_CAN_SPECULATE, which also widens agx_nir_opt_unswitch_invariant_if. Please fix the message.
  4. Numbers: 120 is described as "half of 192/256" (:2802-2806), which it is not, and 1024 (:3062) has no derivation and is a cliff (a 1025-op function gets nothing). Fine as a first budget, but please say how they were picked. The cap also covers only this pass; the fast copy still goes through the main/4x/3x3/3x3-outer split, so the per-chip binary-size table promised in the description is still needed.
  5. Rows: there is no hardware result at this head yet, only unit tests and the offline compile sweep. The passes reach every stage on AGX3B and on AGX3C without emit_agx3d. Owed at 7110ac2: Neo (A18 Pro) and M4 Pro (both G17P), M3 (G15G), M4 (G16G) with dEQP-VK compute + glsl.loops + ssbo.layout and the ABBA numbers, an M5 row, and a robustness run on a device where those cases are supported.

No new chip/board compares, params or env switches in this PR; commit trailers are fine.

@DjDeveloperr
DjDeveloperr force-pushed the perf/agx3b-flatten-tile-load-bursts branch 2 times, most recently from 0dee159 to 73cad5b Compare November 23, 2026 02:22
@DjDeveloperr
DjDeveloperr force-pushed the perf/agx3b-interior-bounds-stencil-peel branch from 7110ac2 to e8c1ebc Compare November 23, 2026 02:25
@RyanTheTide

Copy link
Copy Markdown

Review at e8c1ebc.

The PR is rebased onto the new base (73cad5b). I compared the two PR commits with range-diff against 7110ac2. Status of the points from my last review:

  1. Fault safety, 2D outer loop with an early jump: fixed. outer_has_jump_outside() (agx_nir_unroll_runtime_loops.c:2141) rejects any break/continue/return in the outer body outside the terminator, recursing into ifs and leaving the inner loop's own jumps alone. It is applied to the nested path (:2824-2826). The guard is only searched at the top level of the body (:2843 onward), so with no earlier jump, iteration 0 of a top-tested outer loop always reaches it. InteriorBounds2DEarlyOuterBreakTripZero (test-agx3-vision-opts.cpp:4291) uses poison addresses and an early break, and checks both the refusal and that nothing faults.
  2. Rotated 8-bit inner loops in the f >= 8 arm (:1759): fixed by test. The code is unchanged, but Rotated8BitInnerNonZeroStart (:4519) covers positive, negative and near-INT32 starts for trips 1-10 and checks the straight-line 3x3 branch. The interpreter now truncates 8-bit loads, which the old test needed to mean anything.
  3. Commit 1 message: fixed. It now names load_global_constant with ACCESS_CAN_SPECULATE as the widening, and says that it also widens unswitch_invariant_if.
  4. Numbers: partly. The arithmetic in the new text is right (40 x 4 = 160 is half of 320, 80 is a quarter of 320, 3 x 80 = 240 < 256), and 120 is now only "below 256". 1024 is "chosen empirically above the largest vision stencil shaders", but the PR does not say which shader or how big it is. Please add that one number to the PR text. The per-chip binary-size table promised in the description is still owed.
  5. Rows: still owed, none at this head.

Nothing new found in the two commits beyond the above. No chip, board or firmware compares, no params or env switches; commit trailers are fine.

Verdict: NITS (item 4). Rows owed at e8c1ebc, by the author: Neo (A18 Pro) and M4 Pro (both G17P), M3 (G15G), M4 (G16G) with dEQP-VK compute + glsl.loops + ssbo.layout and the ABBA numbers, an M5 row, and a robustness run on a device that supports those cases. Also the binary-size table, and a note in this PR when the base branch PR lands, because this head now sits on a rewritten base.

In agx_nir_opt_flatten_loads, sink matching terminal store_shared
instructions out of single-block if/else diamonds into one
store_shared(phi(v_then, v_else), saddr) after the if when both arms compute
structurally equivalent pure-ALU shared offsets (intersecting access flags,
refusing volatile/atomic stores, and capping same_pure_expr work to a 64-node
budget to prevent exponential recursion).

Also flatten contiguous runs of >= 4 small single-load divergent ifs in the
same CF list (separated only by pure ALU or non-volatile store_shared, reset on
barriers or other CF nodes, and excluding load_global_constant so UBO reads
stay intact for uniform DMA):
- Burst threshold (>= 4): isolated 1-3 divergent loads rarely amortize
  speculative zero-page redirection when an arm is cold, whereas >= 4
  consecutive guarded tile loads remove >= 4 serial load-wait CF barriers so
  global loads issue back-to-back with overlapped latency and let LICM hoist
  shared tile-address math.
- Per-arm cap (MIN2(limit, 24)): admits a 2D/3D index + byte offset +
  descriptor setup (~8-16 NIR ops) while keeping speculative untaken ALU
  bounded across a multi-if burst.

Reaches all shader stages under (AGX3B || AGX3C) && !emit_agx3d
(AGX3B: G15/G16/G17P/G17A; AGX3C: G17G/G17S / M5). AGX2 and G18G are
unchanged.

Signed-off-by: DjDeveloperr <hey@djdev.me>
For 1D and 2D counted stencil loops whose body is guarded by an affine
coordinate bounds check (0 <= base + iv * stride < limit, expressed as a
short-circuit diamond phi, bcsel, iand/ior, or unsigned ult/uge), emit an
exact zero-overflow interior guard before the loop:

  bound > 0 && stride >= 0 && base >= 0 && base < limit &&
  umul_high(bound - 1, stride) == 0 &&
  (bound - 1) * stride < (uint32_t)(limit - base)

On the interior fast path, folding the bounds guard removes per-tap and
per-row branches, exposes invariant address math to LICM, and enables
runtime loop unrolling without bloating the cold border fallback (marked
partially_unrolled). For 2D nested stencils where both outer and inner
loops carry such guards and the inner guard parameters are invariant across
the outer loop, a single combined interior_y && interior_x check produces
one branchless 2D fast path.

Fault safety and SSA dominance:
- 2D outer loops with any jump (break/continue/return) outside the loop
  terminator and inner loop are rejected so iteration 0 is guaranteed to
  reach the outer guard before any hoisted non-speculatable loads.
- emit_interior_check rematerializes bound_out first (verified pure or
  header-safe invariant), rematerializes base_out/stride_out strictly inside
  if (bound_out > 0) so top-tested inner loops with trip == 0 never execute
  in-body load_global_constant instructions, and rematerializes limit_out
  strictly inside if (stride >= 0 && base >= 0) so short-circuit limit loads
  only run when iteration 0 has coord(0) >= 0.
- Nested guard blocks use cloned child remap tables so clones emitted inside
  a first check's then-branch never leak into a second sequential check's
  remap table (preserving SSA dominance in 2D checks with shared in-loop
  limit defs).

Budgets and widenings:
- Direct 2D nest cap (<= 120 non-const ops) keeps the simplified interior
  fast path well below the 256-op splittable_outer limit with headroom for
  downstream peeling/unrolling; 1D loops use 4..80 body ops (<= 1/4 of the
  320-op runtime-unroll cap), and tot >= 4 skips trivial 1-3 op selects.
- Whole-function non-const op guardrail (1024 ops, chosen empirically above
  the largest vision stencil shaders) prevents compounding unswitch
  duplication across multi-loop megashaders before downstream unrolling.
- pure_loop_invariant now permits load_global_constant with
  ACCESS_CAN_SPECULATE (alongside the already-permitted load_preamble and
  load_push_constant), which also widens agx_nir_opt_unswitch_invariant_if
  to speculatable global-constant conditions.

Runs under agx3_compute_opts ((AGX3B || AGX3C) && !emit_agx3d), reaching
all shader stages on AGX3B (G15/G16/G17P/G17A) and AGX3C without
emit_agx3d (G17G/G17S / M5). AGX2 and G18G are unchanged.

Signed-off-by: DjDeveloperr <hey@djdev.me>
Extend peel_straight_prefix and unswitch_nested's small-window split to
also handle rotated (bottom-tested, offset == step, REL_LT/REL_GT)
compact branchless 2D stencil loops with memory loads (not only top-tested
8-bit loops). For exact-trip 3x3 stencils this peels both inner and outer
loops completely straight-line; for 4..7-wide inner windows (such as 5x5
depthwise convolutions) it peels 4 straight-line iterations followed by a
guarded rotated remainder loop.

Thresholds and cleanup:
- ops <= 40 in loop_is_compact_branchless_load_loop bounds a 4x peel to
  <= 160 NIR ops (half of the 320-op runtime-unroll budget).
- Outer 3x3 peel preserves the existing <= 64 cap for top-tested nests and
  uses <= 80 only for rotated nests (which include extra latch step/compare
  ops before post-peel DCE; 3 * 80 = 240 <= 256 splittable_outer cap).
- In peel_straight_prefix, check latch_register before emitting bound_def
  and restore SSA if bailing out so a false return leaves the shader clean.

Runs under agx3_unroll ((AGX3B || AGX3C) && !emit_agx3d), reaching all
shader stages on AGX3B (G15/G16/G17P/G17A) and AGX3C without emit_agx3d
(G17G/G17S / M5). AGX2 and G18G are unchanged.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr force-pushed the perf/agx3b-interior-bounds-stencil-peel branch from e8c1ebc to 8f7cee6 Compare November 23, 2026 02:56
@DjDeveloperr
DjDeveloperr force-pushed the perf/agx3b-flatten-tile-load-bursts branch from 73cad5b to f9f69ac Compare November 23, 2026 02:56
@RyanTheTide

Copy link
Copy Markdown

Review at 8f7cee6.

This is a rebase onto the new #761 head (f9f69ac). range-diff against e8c1ebc shows both PR commits unchanged, so the code points from my last review hold as they were.

  1. Numbers: fixed in the PR text. The 1024 budget now has its derivation: the stencil/vision shaders in the 80-SPV GB6 corpus are 73-266 NIR ops before unswitch, the largest non-GEMM compute shader is 869, and the two pre-unrolled GEMM shaders at 1054/1095 are skipped on purpose. The per-chip binary-size table is posted too: 4/80 shaders touched on G15G, G16G, G17P and G17S, no spills and no occupancy drops. The touched kernels grow 2-3.4x in bytes, and GPR use goes up to 41 on G15G/G16G. That is the cost the ABBA rows have to pay for.
  2. Rows: still open. The Verification section says the hardware rows are "posted in comments below", but nothing has been posted since e8c1ebc.

Commits have only the human Signed-off-by. No chip/board/fw compares, no params or env switches.

Verdict: APPROVE on code. Merge waits on the rows, owed by the author at 8f7cee6: Neo (A18 Pro) and M4 Pro (both G17P), M3 (G15G), M4 (G16G) with dEQP-VK compute + glsl.loops + ssbo.layout and the ABBA numbers on the three touched kernels, an M5 row, and a robustness run on a device that supports those cases. #761 also has to land first, since this PR is stacked on it.

@DjDeveloperr

Copy link
Copy Markdown
Author

Addressed remaining review items from #issuecomment-7090153772 in R3 (8f7cee6d4c11, commits 4fa09f548ff + 8f7cee6d4c1, cleanly rebased onto #761 R3 f9f69ac793a9 with zero code changes to #762 itself):

  1. 1024 whole-function op budget & per-chip binary-size table (Item 4):

    • Updated the PR description with the exact measured pre-unswitch count_impl_instrs(impl) op counts across the 80-SPV Geekbench 6 Vulkan corpus:
      • Vision/stencil kernels sit at 73..266 ops: b7279a25 (73), gauss-h (91), gauss-v (94), bc7e1ec6 (101), face-depthwise/720b8163 (153), stereo (266).
      • Largest non-GEMM compute shader below the cap: 07bceaa7 (869 ops).
      • Already-unrolled tiled GEMM megashaders sit right above the cap and are cleanly excluded: face-gemm-aligned (1054 ops), face-gemm-edge (1095 ops).
    • Added the full 4-chip (G15G, G16G, G17P, G17S) 80-SPV per-chip binary-size table to the PR body (4/80 shaders touched on every chip, 0 spills, 0 thread-occupancy drops — all 1024 threads):
      • G15G / G16G: total bytes 155248 -> 165394 (+6.54%) (bc7e1ec6 2.77x, face-depthwise 2.05x, b7279a25 2.56x).
      • G17P: total bytes 168136 -> 178250 (+6.02%) (bc7e1ec6 2.89x, face-depthwise 2.04x, b7279a25 2.47x).
      • G17S (M5): total bytes 127022 -> 136814 (+7.71%) (bc7e1ec6 3.39x, face-depthwise 2.05x, b7279a25 2.66x).
  2. CI & Hardware Verification (Item 5):

Assisted-by: LLM (Antigravity:Gemini 4 Neon)

@DjDeveloperr

Copy link
Copy Markdown
Author

Bare-Metal M5 Pro (G17S B1 / J714s) Verification — R3 (8f7cee6d4c11)

Tested exact R3 head 8f7cee6d4c11ece01106494dcd1ed8b582e21d35 (prebuilt mesa-pr762-r3-8f7cee6d.tar.zst, sha256 2017ea1d7f36d5a01a55ea4d0ab804744b7727e181e9a83d2618c5b47fd42d07, driverInfo = Mesa 26.3.0-devel (git-8f7cee6d4c)) on Apple MacBook Pro 14-inch M5 Pro (J714s / G17S B1 / AGX3C) running Linux 7.3.0-m5-n1keep-r3 (MESA_SHADER_CACHE_DISABLE=1):

CTS Group Passed Failed Not Supported
dEQP-VK.compute.pipeline.basic.* (full) 80/81 0 1
dEQP-VK.glsl.loops.* (full) 624/624 0 0
dEQP-VK.ssbo.* (489 evenly-sampled of 12,225) 487/489 0 2
dEQP-VK.ubo.* (491 evenly-sampled of 13,240) 491/491 0 0
  • GPU faults (dmesg): 0 (delta = 0).

@DjDeveloperr

Copy link
Copy Markdown
Author

Exact-head verification on Apple M4 (G16G B0, J773g / T8132) for R3 (8f7cee6d4c11, stacked on #761 R3 f9f69ac793a9 / #758 R2 01a39fa4f91f):

  • Environment & driver identity: Kernel 7.3.0-ARCH-m4prod23 (zero reboot); exact-head prebuilt ARM64 GL+VK kits verified via gpubench-vk --info (Borealis, Vulkan 1.4.363) and gpubench-gl --info (4.6 (Core Profile)):
    • #758 R2 (stack base): Mesa 26.3.0-devel (git-01a39fa4f9), SHA256 4ca62c3fca60aeb07e0551c7359d50b1a82a3c8b2266458706d2474fec8ed2e0
    • #761 R3 (stack parent): Mesa 26.3.0-devel (git-f9f69ac793), SHA256 f198cf2e3b165ce9e2032cd88493fd5d74ec7c43cc95ed8e30704142ab846149
    • #762 R3: Mesa 26.3.0-devel (git-8f7cee6d4c), SHA256 2017ea1d7f36d5a01a55ea4d0ab804744b7727e181e9a83d2618c5b47fd42d07

Single-Threaded CTS (MESA_SHADER_CACHE_DISABLE=true, DMESG_CLEAN_DELTA=0)

Suite / Group Passed NS Failed
dEQP-VK.compute.pipeline.basic.* 79/81 2 0
dEQP-VK.glsl.loops.* 624/624 0 0
dEQP-VK.ssbo.layout.single_basic_type.std430.* 303/303 0 0
dEQP-VK.ubo.{random,2_level_struct,single_basic} 118/160 42 0
dEQP-VK.robustness.*robustness2.* (1d comp/v/f) 36/36 0 0
dEQP-VK.robustness.index_access.* 31/40 9 0
dEQP-VK.robustness.buffer_access.{v,f,c} + rob2 120/156 36 0
VK unique total (deduplicated) 1,275/1,364 89 0
dEQP-GLES31.functional.compute.basic.* 41/41 0 0
dEQP-GLES31.functional.ssbo.layout...std430.* 121/121 0 0
GLES31 total 162/162 0 0

gpubench-vk ABCCBA: #762 R3 (8f7cee6d4c) vs #761 R3 (f9f69ac793) & Cumulative vs #758 R2 (01a39fa4f9)

108/108 unique 6-leg VK CRCs bit-identical PASS (72/72 pairwise), 0 non-cooling dmesg lines. Neutral ±0.3% across non-GB6 compute vs #761 R3, preserving cumulative -1.81% (d=1) / -1.72% (d=4) compute.edge kind=harris GPU win vs #758 R2.

Workload d Wall (us_per_submit) #761 R3 -> #762 R3 Wall delta (#762 vs #761) GPU (gpu_us) #761 R3 -> #762 R3 GPU delta (#762 vs #761) Cumulative GPU (#762 vs #758 R2) CRC
compute.conv2d kind=gaussian,res=1080p 1 1242.24 -> 1246.12 +0.31% (0.997×) 909.38 -> 908.03 -0.15% (1.001×) -3.35% (1.035×) 2d55a14d PASS
compute.conv2d kind=gaussian,res=1080p 4 913.24 -> 915.34 +0.23% (0.998×) 910.08 -> 910.65 +0.06% (0.999×) +0.06% (0.999×) 2d55a14d PASS
compute.conv2d kind=bilateral,res=1080p 1 1746.76 -> 1746.76 +0.00% (1.000×) 1469.73 -> 1469.54 -0.01% (1.000×) -0.01% (1.000×) 6cdc0716 PASS
compute.conv2d kind=bilateral,res=1080p 4 1481.48 -> 1481.48 +0.00% (1.000×) 1472.60 -> 1472.29 -0.02% (1.000×) -0.02% (1.000×) 6cdc0716 PASS
compute.stereo disp=64 1 19090.91 -> 19090.91 +0.00% (1.000×) 18727.35 -> 18722.00 -0.03% (1.000×) -0.03% (1.000×) c62aadf9 PASS
compute.stereo disp=64 2 18181.82 -> 18181.82 +0.00% (1.000×) 18721.82 -> 18724.23 +0.01% (1.000×) +0.00% (1.000×) c62aadf9 PASS
compute.edge kind=sobel,res=1080p 1 793.65 -> 790.56 -0.39% (1.004×) 513.50 -> 512.06 -0.28% (1.003×) +0.32% (0.997×) 27c79e6d PASS
compute.edge kind=sobel,res=1080p 4 522.20 -> 520.85 -0.26% (1.003×) 518.67 -> 516.90 -0.34% (1.003×) +0.35% (0.997×) 27c79e6d PASS
compute.edge kind=harris,res=1080p 1 954.70 -> 947.89 -0.71% (1.007×) 663.06 -> 662.62 -0.07% (1.001×) -1.81% (1.018×) 4cebadfc PASS
compute.edge kind=harris,res=1080p 4 690.85 -> 690.85 +0.00% (1.000×) 688.53 -> 686.48 -0.30% (1.003×) -1.72% (1.017×) 4cebadfc PASS
compute.uber kind=divergent 1 722.02 -> 723.33 +0.18% (0.998×) 500.02 -> 499.98 -0.01% (1.000×) +0.00% (1.000×) 9963f56c PASS
compute.uber kind=divergent 4 504.41 -> 503.78 -0.13% (1.001×) 502.20 -> 502.19 -0.00% (1.000×) -0.00% (1.000×) 9963f56c PASS
compute.uber kind=uniform 1 411.52 -> 411.95 +0.10% (0.999×) 185.77 -> 185.73 -0.02% (1.000×) -0.02% (1.000×) b022fbaf PASS
compute.uber kind=uniform 4 190.57 -> 191.21 +0.34% (0.997×) 187.85 -> 187.90 +0.02% (1.000×) +0.01% (1.000×) b022fbaf PASS
compute.uber kind=ilp 1 610.70 -> 617.29 +1.08% (0.989×) 383.47 -> 383.72 +0.07% (0.999×) +0.07% (0.999×) 19f35e30 PASS
compute.uber kind=ilp 4 389.86 -> 390.24 +0.10% (0.999×) 387.06 -> 387.44 +0.10% (0.999×) +0.15% (0.999×) 19f35e30 PASS
compute.light 1 138.81 -> 133.69 -3.69% (1.038×) 1.58 -> 1.58 +0.00% (1.000×) -0.03% (1.000×) n/a
compute.light 4 56.00 -> 55.63 -0.67% (1.007×) 1.58 -> 1.58 +0.00% (1.000×) +0.00% (1.000×) n/a
compute.heavy 1 787.40 -> 788.96 +0.20% (0.998×) 544.31 -> 544.33 +0.00% (1.000×) -0.00% (1.000×) n/a
compute.heavy 4 547.95 -> 547.95 +0.00% (1.000×) 544.33 -> 544.33 +0.00% (1.000×) +0.00% (1.000×) n/a
compute.cull_mdi 1 2469.14 -> 2469.14 +0.00% (1.000×) 1273.13 -> 1272.80 -0.03% (1.000×) +0.37% (0.996×) 57276de2 PASS
compute.cull_mdi 4 1753.65 -> 1863.50 +6.26% (0.941×) 1338.41 -> 1361.39 +1.72% (0.983×) +1.66% (0.984×) 57276de2 PASS

gpubench-gl ABCCBA: #762 R3 vs #761 R3

24/24 unique 6-leg GL CRCs PASS (16/16 pairwise), DMESG_DELTA=0, 0 regressions.

Workload d Wall (us_per_submit) #761 R3 -> #762 R3 Wall delta / speedup GPU (gpu_us) #761 R3 -> #762 R3 GPU delta / speedup CRC
compute.uber kind=divergent 1 735.29 -> 738.92 +0.49% (0.995×) n/a n/a 9963f56c PASS
compute.uber kind=divergent 4 506.76 -> 507.62 +0.17% (0.998×) n/a n/a 9963f56c PASS
compute.uber kind=uniform 1 427.96 -> 430.42 +0.57% (0.994×) n/a n/a b022fbaf PASS
compute.uber kind=uniform 4 192.93 -> 192.31 -0.32% (1.003×) n/a n/a b022fbaf PASS
compute.image 1 453.86 -> 456.63 +0.61% (0.994×) n/a n/a n/a
compute.image 4 192.80 -> 192.55 -0.13% (1.001×) n/a n/a n/a
compute.heavy 1 800.01 -> 800.01 +0.00% (1.000×) 5.10 -> 5.38 +5.47% (0.948×) n/a
compute.heavy 2 561.80 -> 561.80 +0.00% (1.000×) 5.25 -> 5.42 +3.33% (0.968×) n/a
compute.heavy 4 561.80 -> 561.80 +0.00% (1.000×) 5.35 -> 5.38 +0.38% (0.996×) n/a
compute.heavy 8 561.80 -> 561.80 +0.00% (1.000×) 5.29 -> 5.42 +2.35% (0.977×) n/a
compute.heavy 16 561.80 -> 566.07 +0.76% (0.992×) 5.38 -> 5.40 +0.23% (0.998×) n/a
compute.heavy 32 559.70 -> 559.70 +0.00% (1.000×) 5.42 -> 5.40 -0.40% (1.004×) n/a
compute.heavy 64 559.70 -> 559.70 +0.00% (1.000×) 5.40 -> 5.50 +1.77% (0.983×) n/a
  • Post-flight health: DMESG_CLEAN_DELTA=0, NON_COOLING_CLEAN_DELTA=0, 0 GPU faults / kernel bugs (REAL_FULL_BOOT_KERNEL_BUGS=0, SCHED_WHILE_ATOMIC=0, INTERRUPT_RC_WARN=0), IDLE_CLEAN.

Assisted-by: LLM (Gemini:4 Neon)

@aurora-silicon-review aurora-silicon-review Bot 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: HOLD at 8f7cee6d

Blockers:

  1. Targets open non-default base branch perf/agx3b-flatten-tile-load-bursts (#761, which is itself stacked on #758) and is currently CONFLICTING with that base.

Checked:

  • Checked base branch status (#761 is still OPEN, targeting perf/agx3b-wave7-blur-fm-deep) and PR mergeability (CONFLICTING).
  • Deferred full line-by-line review until #758/#761 land (or #762 is cleanly rebased onto current aurora-wip).
Evidence
  • Base ref: perf/agx3b-flatten-tile-load-bursts (mesa#761 state: OPEN).
  • Mergeability: CONFLICTING at 8f7cee6d.

Use the shared typed access qualifier in both arms of the negative store-sinking fixture.

Signed-off-by: DjDeveloperr <hey@djdev.me>

@aurora-silicon-review aurora-silicon-review Bot 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: HOLD at 0f664273d308

Blockers:

  • Confirm meson test --suite asahi (including test-agx3-vision-opts and test-flatten-loads) passes at the post-merge head 0f664273d308 and retarget onto aurora-wip once approved parent #761 lands.
  • Pending independent maintainer approval before merge.

Checked:

  • Audited merge commit 0f664273d308: resolves the conflict cleanly against approved parent #761 (MERGEABLE, only +5/-5 in src/asahi/compiler/test/test-flatten-loads.cpp); zero production code changes relative to 8f7cee6d4c11, which already passed dual-generation bare-metal verification on M5 Pro (J714s, G17S B1) and M4 (J773g, G16G B0).
  • Audited emit_interior_check() and agx_nir_opt_unswitch_interior_bounds() in src/asahi/compiler/agx_nir_unroll_runtime_loops.c:
    • Signed/unsigned overflow check is exact (bound > 0, stride >= 0, base >= 0, base < limit guaranteeing 1 <= span <= INT32_MAX, umul_high(N - 1, stride) == 0, and ult(delta, span) proving 0 <= base + iv * stride < limit with no 32-bit signed/unsigned overflow).
    • Nested if blocks (pos_if, chk_if) isolate cloned remap hash tables (pos_remap, limit_remap), preserving SSA dominance across sequential 2D checks and guarding in-body load_global_constant rematerialization behind bound > 0 / stride >= 0 && base >= 0.
    • Rotated-loop peeling in peel_straight_prefix() properly guards offset == step, REL_LT/REL_GT, and back_edge_live_outs(), wrapping the tail loop in a continuation if when keep_tail is set.
  • Audited src/asahi/compiler/agx_compile.c (agx_nir_opt_unswitch_interior_bounds wired ahead of agx_nir_unroll_runtime_loops) and agx_nir.h.
Evidence
  • Head: 0f664273d3089e69658ba98c4f77812fa82ff7c6 (base perf/agx3b-flatten-tile-load-bursts / #761 approved at 8e2d1218, MERGEABLE).
  • No compiler or soundness defects found in 0f664273d308.

@github-actions github-actions Bot added area:compiler Area from CODEOWNERS (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 1, 2026
@DjDeveloperr

Copy link
Copy Markdown
Author

Merged stack parent #761 at 0f664273d308, preserving both feature layers and using the typed access qualifier in both arms of the store-sinking fixture. This PR still targets its declared stack branch. The lower layers and G16 stencil comparison determine its landing order.

@aurora-silicon-review aurora-silicon-review Bot 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: MERGE at 0f664273d308

Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.

Checked: - Audited merge commit 0f664273d308: resolves the conflict cleanly against approved parent #761 (MERGEABLE, only +5/-5 in src/asahi/compiler/test/test-flatten-loads.cpp); zero production code changes relative to 8f7cee6d4c11, which already passed dual-generation bare-metal verification on M5 Pro (J714s, G17S B1) and M4 (J773g, G16G B0).

  • Audited emit_interior_check() and agx_nir_opt_unswitch_interior_bounds() in src/asahi/compiler/agx_nir_unroll_runtime_loops.c:
    • Signed/unsigned overflow check is exact (bound > 0, stride >= 0, base >= 0, base < limit guaranteeing 1 <= span <= INT32_MAX, umul_high(N - 1, stride) == 0, and ult(delta, span) proving 0 <= base + iv * stride < limit with no 32-bit signed/unsigned overflow).
    • Nested if blocks (pos_if, chk_if) isolate cloned remap hash tables (pos_remap, limit_remap), preserving SSA dominance across sequential 2D checks and guarding in-body load_global_constant rematerialization behind bound > 0 / stride >= 0 && base >= 0.
    • Rotated-loop peeling in peel_straight_prefix() properly guards offset == step, REL_LT/REL_GT, and back_edge_live_outs(), wrapping the tail loop in a continuation if when keep_tail is set.
  • Audited src/asahi/compiler/agx_compile.c (agx_nir_opt_unswitch_interior_bounds wired ahead of agx_nir_unroll_runtime_loops) and agx_nir.h.

Follow-ups (not blocking): Merge parent #761 first; follow-ups: post-merge meson asahi, maintainer approval

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Merge readiness at 0f664273: 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 ok none
Hardware row at head no no line with the head SHA 0f664273, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: area:compiler

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

@RyanTheTide

Copy link
Copy Markdown

A current-trunk port of the rotated small-window code now reaches the intended path on J615 (M3 Air, G15G C0, saved Edge). The decisive fixture change was passing the 8-bit inner-loop endpoint as a push constant so it is invariant with respect to the outer loop. The original UBO fixture compiled identically in both arms.

At local preview d1d0742cef7b versus dad5aae60fa69, four paired ABBA/BAAB blocks measured median GPU-time changes of −40.48% for 3×3 and −35.49% for 5×5. Each process matched 524,288 CPU reference results and preserved 524,288 padding words. The original port slowed 8×8 by 1.24%. Moving the inner trip checks into the small-window branch and the outer trip check into its three-tap branch reduced that. Eight additional 8×8 blocks measured +0.05% median paired change (328,125 to 328,250 ns pooled, +0.04%). No kernel events or boot changes were recorded.

The narrow port preserves the already-landed affine-bounds pass from #656. It passed 1,948 compiler tests with one skip, including the nonzero-start fixture, and the separate affine-bounds host test. I have the rotated-only commits ready to check on the #1537 base.

@RyanTheTide

Copy link
Copy Markdown

Thanks, Dj, for the rotated stencil peel. I carried that part and your original sign-off into #1539, stacked on #1538. The affine-bounds work is already in #656. I moved the small-window trip checks into their respective branches and reran the corrected stack on J615. The paired GPU time fell 40.46% for 3×3 and 35.52% for 5×5. The 8×8 comparison was within 0.06% in every block, and every process matched the CPU reference. I’ll keep this PR open until the replacement lands.

@RyanTheTide

Copy link
Copy Markdown

Thanks, Dj. Your rotated-stencil work landed in #1539 as fb0f929ad544, with your sign-off preserved. The exact head passed on J615 and J775c, and the 8×8 control stayed within 0.06% in every J615 block. The affine-bounds slice is already in #656. I’m closing the original stack now that both slices are in aurora-wip.

@RyanTheTide RyanTheTide closed this Dec 2, 2026
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) 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants