Repository navigation
agx: peel proven non-wrapping exact loop tails in 4/2/1 chunks - #1353
Conversation
Adapt the exact bottom-tested tail from DjDeveloperr's 13a65a6 and the no-wrap proof in 01a39fa to the current counted-loop unroller. Reuse the existing register-backed live-outs and guard math, and retain the scalar tail where the first step or inclusive endpoint could wrap. Keep the bottom-rotated integer-only main loop on its current path. Compare optimized NIR execution against the original loop for divergent bounds, boundary wrap controls and carried and invariant live-outs. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
@aurora-silicon-review please review a8b9e2d. The native J615 and J700 runs cover the same production source and the final commit adds inclusive-bound fallback tests only. The hardware matrix and raw timings are in the description. |
|
@aurora-silicon/aurora-maintainers @DjDeveloperr, please review a8b9e2d for the Mesa code-owner gate. The PR includes the J615 and J700 hardware results and the tests that retain the scalar fallback when inclusive bounds can wrap. |
There was a problem hiding this comment.
Verdict: MERGE at a8b9e2dd
Blockers: None.
Checked:
- Audited
binary_tail_no_wrap(),tail_continuation_is_pure(),emit_tail_chunk(),loop_continue(), and the 4/2/1 tail emission insrc/asahi/compiler/agx_nir_unroll_runtime_loops.c:- Wrap proof (
binary_tail_no_wrap):analyze_loop_opts()restrictsiv/boundto 32-bit scalars and enforces(rel == REL_LT || rel == REL_LE) == (step > 0); requiringexact_tail,factor == 8, unitstep(±1), constantiv0 != extreme, and either strict (REL_LT/REL_GT) or constantbound != extremefor inclusive relations proves neither the forced first bottom-tested iteration nor any main/4/2/1 chunk can wrap across all signed/unsigned ascending/descending extremes. - Guard math & exact trip count:
guard_bound()+emit_guard_cont(..., exact_tail=true)forcount = 4, 2and the finalcount = 1guardnir_ieq(iv, iv0) || loop_continue(iv, bound)preserve exact bottom-tested semantics across 0..7 remaining trips as well asiv0already pastbound(guaranteed 1 iteration; because induction is strictly monotonic without wrap,iv == iv0is true at the 1-chunk iff no earlier chunk ran). - Live-outs and CFG cleanup:
tail_continuation_is_pure()guards the extracted continuation branch, bottom-rotated integer-only main loops keepbinary_tail = false,outs[i]live-out loads/rematerializations are emitted right after the 1-chunk before removing the originalloop, andnir_lower_reg_intrinsics_to_ssa_impl()runs immediately afterward. - Head commit
a8b9e2ddtouches onlysrc/asahi/compiler/test/test-agx3-vision-opts.cpp(adding inclusive-bound wrap fallback tests); production code is unchanged from hardware-verified3478c981.
- Wrap proof (
- Host
agx_tests(1,834pass /1skip, including NIR interpreter differential tests across signed/unsigned,±1, inclusive/exclusive, and wrap fallbacks) and J615 G15G (-4.27%to-9.24%) / J700 G17P (-8.13%to-14.02%) integer convolution runs with16,384/16,384exact word readbacks and zero kernel errors support merging.
Evidence
src/asahi/compiler/agx_nir_unroll_runtime_loops.c: verifiedanalyze_loop_opts()(L361–569),guard_bound()(L582–641),back_edge_live_outs()(L709–747),binary_tail_no_wrap()(L823–837),tail_continuation_is_pure()(L840–858),emit_tail_chunk()(L861–875), andunroll_loop()(L901–1130).src/asahi/compiler/test/test-agx3-vision-opts.cpp: verifiedBinaryTailExactLiveOuts,BinaryTailRetainsUnprovenFallback, andBinaryTailRetainsInclusiveBoundFallback(nir_validate_shader()+ NIR execution parity).- Reported hardware rows at
3478c9815c32(identical production source toa8b9e2dd): J615 G15G-7.39%/-9.24%/-4.27%and J700 G17P-14.02%/-11.61%/-8.13%across 0–7, 8–15, 0–63 bounds,16,384/16,384words exact.
|
Rechecked exact a8b9e2d on aurora-wip 58abf3b in preview baf4e84a8f5d. The patch ID matches the original branch. Host compiler tests passed 1,834 with one skip. J615 and J700 integer-convolution readbacks matched all 16,384 words per invocation, and each compute binary matched its earlier capture byte for byte. Paired GPU time fell 2.62%–5.50% on J615 and 8.05%–11.85% on J700 across the three bound distributions. The saved boots remained unchanged and the run windows had no kernel messages. |
|
Integration with aurora-wip at |
|
J713 M4 G16G peer on saved fleet85. Compared landed |
|
@DjDeveloperr, code-owner heads-up: App approval at |
|
Merge-train landing at
Revert: |
What: Replace the scalar remainder of an eligible factor-eight exact-tail loop with guarded 4/2/1 chunks when induction cannot wrap. This adapts the binary tail and wrap proof from Dj’s #743 and #758 to the current counted-loop unroller.
Tested: J615 M3 Air G15G and J700 Neo G17P at production 3478c98. Both checked all 16,384 words per run and exercised the 4/2/1 tail. PR head a8b9e2d adds only regression tests and passed 1,834 host compiler tests with one skip. J615 integer convolution improved 4.27%–9.24% and J700 improved 8.13%–14.02%. Main shader size increased by 242 bytes for convolution and 374 for the other fixtures. Strided J615 timing was inconclusive.
Risk: two-way door · shared AGX3B and AGX3C runtime-loop optimization. Bounded code duplication can increase shader size. Mutable or extreme bounds and existing integer-only bottom rotation keep their scalar path.
Not yet: Native M4 and M5 timing, or a stable result on the J615 strided fixture.
Revert: Revert the merge commit. No persistent state changes.
Details
The pass requires the existing exact-tail live-out conditions, a unit step, a factor-eight main loop, and the 2× body-instruction estimate. The initial value must be a known non-extreme constant. Inclusive bounds must be known and below the directional extreme. The scalar tail remains for all other cases.
The compare now leads to guarded chunks with 4/2/1 iterations, using the current register-backed accumulator and invariant live-outs. The compiler can vectorize the tail loads. The regression tests run original and optimized NIR through ascending and descending wrap on inclusive signed and unsigned limits, and check finite runtime bounds.
Evidence
Baseline 8bad0a5. Native candidate 3478c98. Proposed a8b9e2d changes only the compiler test file from the native candidate. Both devices used Linux 7.3.0-aurora-edge from 933f822675e4d6d7197084f833d4aec3aecaa574. Stage 2 SHA-256 c5d7ef6ceb959d97242837005dfbf099cab273b4af54844c4617bab107de74f7 on J615 and c0654b4996d2d03e41c59897e628e0abd94ed7834020268a7b254eab704d6936 on J700. The kernel journals returned “No entries” during the paired runs. Both saved boots, Enforcing and zero failed units stayed the same.
Six ABBA blocks per row, 160 warmups and ten timestamps per process. Overlapping loads improved 4.36%–10.57%. The J615 strided identical-ICD control varied from −45.82% to +37.54% across individual blocks. The two strided A/B runs disagree on the larger bounds.
Benchmark sources, commands, raw timings and ICD hashes