Repository navigation
agx: AGX3B W8/byte-convert/uniform-base codegen, capped speculative LICM, and invariant-if unswitching - #704
DjDeveloperr wants to merge 3 commits into
Conversation
|
Reviewed the three commits on top of #700 (6854dee, 6318d59, 081e321).
Assisted-by: LLM (Claude:Opus 5.5) |
081e321 to
e1a91e9
Compare
|
Updated
Verification at Exact R2 Head (
|
|
Re-reviewed at e1a91e9 (only commits 1 and 3 changed; commit 2 is identical).
Assisted-by: LLM (Claude:Opus 5.5) |
e1a91e9 to
cca699d
Compare
|
Re-checked cca699d (range-diff against e1a91e9; commit 2 is unchanged).
Code-wise this is fine from my side once that data is linked. Assisted-by: LLM (Claude:Opus 5.5) |
|
Addressed all 3 polish items from
There is zero GPU codegen change relative to R2 ( Assisted-by: LLM (Antigravity:Gemini 4 Neon) |
Clean-room M5 Pro (
|
| Check | Result | Notes |
|---|---|---|
Vulkan CTS 1.4.7.1 (sconvert*, uconvert*, 8bit_storage.*, glsl.loops.*, ssbo.layout.single_basic_type.std430.*, compute.pipeline.basic.*) |
1,098 pass / 0 fail / 1 unsupported | 38/38 sconvert*, 24/24 uconvert*, 29/29 8bit_storage.*, 624/624 glsl.loops.*, 303/303 ssbo.std430.*, 80/81 compute.pipeline.basic.* |
gpubench-vk (conv2d gaussian/bilateral, edge sobel/harris, stereo disp=32, fp16 alu_mix d=1 & gemv d=1,4) |
13/13 bit-exact CRC-32 (CRC_BAD=0) |
0 regressions (e.g. conv2d gaussian 1080p d=4 334.71 us, stereo disp=32 d=2 2760.50 us) |
Offline Geekbench 6.7.1 Vulkan (HK_FRAME_ANATOMY_TS=all) |
8/8 workloads pass, 0 spills (sp>0 = 0) |
BG Blur 5.110 ms, Face 7.618 ms, Horizon 5.216 ms, Edge 4.207 ms, Gaussian 4.570 ms, Feature 11.040 ms, Stereo 2.400 ms, Particle 22.118 ms |
Kernel dmesg delta |
0 new lines / 0 GPU faults | Clean |
Runtime on M5 Pro (AGX3C) is 0-regression green; please fix the two .format/.sign_extend designator orders in test-agx3-vision-opts.cpp:1373,1388-1389 for GCC 16 builds.
Assisted-by: LLM (Antigravity:Gemini 4 Neon)
|
Thanks for the M5 row. The GCC 16 failure it found blocks merging: Assisted-by: LLM (Claude:Opus 5.5) |
…tore peel Enable three AGX3B codegen paths matching the validated AGX3C forms: - 1-instruction W8 integer unpack in agx_unpack_integer_8_agx3 (16-bit low-byte mask / shift-right-by-8 per channel). - Native byte-to-float conversions (s8->f16, s8->f32, u8->f32) in agx_lower_agx3_half_converts, preserving G18G's halfword fallback. - Scalar W8 device_store u2u8 mask peel in agx_emit_store: a scalar W8 store writes only the low 8 bits of its 16-bit source register, so skip the redundant u2u8 0xff mask. Signed-off-by: DjDeveloperr <hey@djdev.me>
… stores Extend AGX3B aligned low-uniform 64-bit base folding in agx_optimizer_copyprop from scalar/packed I8 device_load to all non-coherent, non-internal, non-preamble compute device_load and device_store instructions. Both LDDEV and STDEV encode an aligned low-uniform base (< 256, 4-half aligned) across W8/W16/W32 widths and masks 1..15. Signed-off-by: DjDeveloperr <hey@djdev.me>
…tching Enable invariant-if loop unswitching, capped speculative LICM, and canonical minmax on AGX3B compute shaders, while keeping G18G (AGX3C + emit_agx3d) and AGX3B graphics stages unchanged: - Reuse outer-loop splitting's structural guards (splittable_outer, live_outs_are_alu, no continue construct, no successor-block phis) in agx_nir_opt_unswitch_invariant_if so invariant-condition duplication handles live-out ALU values and safely refuses multi-break exit phis. - Empirically cap AGX3B compute LICM at 64 half-registers (avoiding G17P compute register-pressure regressions while leaving agx_max_registers_for_occupancy unchanged) and gate speculative pure-ALU/preamble hoisting on !nir->info.internal. - Add pack_64_2x32_split matching in same-block store-to-load forwarding. - Add unit tests for live-out unswitching, two-break exit-phi refusal, AGX3B uniform-base folding (load/store, aligned/unaligned/high/coherent), W8 byte-to-float codegen, and exact scalar W8 u2u8 store mask peeling. Empirical G17P (M5) measurement behind the 64-half-register cap: uncapping to regs - 8 (96 half-regs) regressed face-gemm-aligned (69 -> 103 GPRs, +20 instrs), 07bceaa7f3a4c1b1 (69 -> 103 GPRs, +28 instrs), and face-gemm-edge (43 -> 93 GPRs), whereas capping at 64 half-regs keeps them at 65 GPRs / 643 instrs and 43 GPRs / 724 instrs while still hoisting all vision, stereo, and feature-matching loops (all <= 47 GPRs) in full (see PR #704 R2/R3 comment). Signed-off-by: DjDeveloperr <hey@djdev.me>
75f4b08 to
a1a32a0
Compare
cca699d to
60bafb4
Compare
|
Pushed R4 (
Assisted-by: LLM (Antigravity:Gemini 4 Neon) |
|
Checked 60bafb4, rebased on #700 R3. The test initializers are now in declaration order ( Nit: the message says "G17P (M5)". G17P is the A18 Pro / M4 Pro part, and M5 is AGX3C, where this path is off. Please name the chip the counts came from. Since the cap applies to every AGX3B compute shader, the announced M4 (G16G) row is still the one I'd like to see before merge. Code-wise this is fine from my side. Assisted-by: LLM (Claude:Opus 5.5) |
|
Exact-head M4 hardware verification (
Assisted-by: LLM (Gemini:4 Neon) |
|
Thanks. The M4 (G16G) row covers the non-Neo AGX3B ask: the exhaustive byte-convert sweep is bit-exact. Commits 1-2 are range-diff identical and commit 3 changes only the test and the message, so the e1a91e9 row applies to this head. Approval stands. The only nit left is the "G17P (M5)" label in the commit message. Assisted-by: LLM (Claude:Opus 5.5) |
|
Root cause of the The cause is 6aa6bb3 ("agx: enable AGX3 compute unroll, shared-memory, and 32x32 GEMM passes on AGX3B"). Fix: #738 (against aurora-wip). The loop reads its trip count from memory, so it survives any unroll limit. Results:
With #738 merged first, this stack no longer has the test blocker. The two merge conflicts with #728's move of the shared-phase CSE remain. One question, not a blocker: the commit title and comment describe this as a compute/GEMM change, but the preprocess change applies the 64-trip unroll to every stage on AGX3B (AGX3C already does that). If you meant it for compute only, a stage check belongs here. #738 is correct either way. |
check_main_side_effects_fence_strip() builds a geometry shader whose loop runs exactly 64 times and expects the main kernel to keep that loop with one atomic and one fence_mem_to_tex_agx. The loop's only job is to check that stripping the atomic in replay also strips the fence, so the raster variant does not keep a loop alive for the fence alone. With "agx: enable AGX3 compute unroll, shared-memory, and 32x32 GEMM passes on AGX3B" (in aurora-silicon#704), agx_preprocess_nir_g17p() raises max_unroll_iterations to 64, as M5 already does. The 64-trip loop is then fully unrolled before hk_nir_lower_gs() sees it: the main kernel has 64 atomics, 64 fences and no loop, and the test fails at its first count check although the strip itself still works. Read the trip count from memory instead, so no unroll limit can remove the loop. The checks are unchanged and still fail if strip_fence_mem_to_tex() stops removing the fence. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
satchlj
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 60bafb40ca56
Blockers: none
Checked: Full diff audit of AGX3B W8/byte-convert/uniform-base codegen (agx_emit_load_const / agx_emit_undef SSA emission in agx_compile.c), capped peel/device-load logic, and unit tests; clean -Dbuildtype=release -Db_ndebug=false build with Clang (GCC 16 errors confirmed strictly in untouched base-branch lines test-agx3-vision-opts.cpp:383,385); meson test --suite asahi and live Mac Studio M5 Max (J775c, T6050) Vulkan CTS with GPU_FAULT_DELTA=0.
Evidence
- Build (
60bafb40ca56,-Dbuildtype=release -Db_ndebug=false): GCC 16 failed only on pre-existing base linessrc/asahi/compiler/test/test-agx3-vision-opts.cpp:383,385(0 errors in PR diff); Clang build succeeded cleanly. - Host tests (
meson test --suite asahi):146/146PASS,0FAIL (includingasahi - mesa:agx_tests). - Live Mac Studio M5 Max (J775c, T6050) Vulkan CTS (
LD_DEBUG=libsconfirmed loading freshly builtlibvulkan_asahi.so):dEQP-VK.compute.pipeline.basic.*:80/81PASS,0FAIL,1NotSupporteddEQP-VK.subgroups.basic.compute.*:12/12PASS,0FAILdmesgGPU fault delta:0
|
@DjDeveloperr #700 is forward-merged onto The overlaps I found, all on
For #704 I pushed a candidate forward-merge to the branch Everything above #704 (#735, #743, #758, then #761/#762/#801/#804/#805/#920) waits on this. #761, #801 and #804 also have open review items from satchlj. |
Stacked on #700 (
perf/agx3-3x3-outer-peel-store-fwd,75f4b085bfa).This series adds three general AGX3B compute compiler optimizations covering W8/byte-convert codegen, aligned low-uniform 64-bit address-base folding, and loop-invariant hoisting / invariant-
ifunswitching:Commits
ed7c1a4eff7—agx: enable AGX3B 1-instr W8 unpack, byte-to-float converts, and W8 store peel(src/asahi/compiler/agx_compile.c)agx_unpack_integer_8_agx3W8 lane unpack path onAGX3B(matchingAGX3Cwhen!emit_agx3d).S8_TO_F(f16/f32) andU8_TO_F(f32) lowers inagx_lower_agx3_half_convertsonAGX3B(verified by exhaustive sweep onG17CandG17P B1;G18Gkeeps the halfword fallback).nir_op_u2u8directly on scalar 1-byteAGX_FORMAT_I8store_agxemissions from 16-bit or 32-bit low halves on(AGX3B || AGX3C) && !emit_agx3d.1850138bf87—agx: fold aligned low-uniform 64-bit bases on AGX3B compute loads and stores(src/asahi/compiler/agx_optimizer.c)agx_optimizer_copypropaligned low-uniform 64-bit base folding (< 256, 4-half aligned) from scalar/packedI8DEVICE_LOADto all non-coherent, non-internal, non-preambleAGX3BcomputeDEVICE_LOAD(s == 0) andDEVICE_STORE(s == 1) acrossW8/W16/W32and masks1..15.cca699d5471—agx: enable AGX3B capped speculative LICM and invariant-if loop unswitching(src/asahi/compiler/agx_compile.c,agx_nir.h,agx_nir_opt_guard_selected_loads.c,agx_nir_opt_licm.c,agx_nir_unroll_runtime_loops.c,test/test-agx3-vision-opts.cpp)agx_nir_opt_unswitch_invariant_iffor compact innermost AGX3B compute loops (<= 192instrs), reusing outer-loop splitting's structural guards (splittable_outer,live_outs_are_alu, no continue construct, no successor-block phis, no return/halt) to safely unswitch a jump-free loop-invariant top-levelnir_ifwhose arms have>= 12work instructions and>= 2invariant ALU instructions.same_base_ptrinagx_nir_opt_guard_selected_loads.cto recognize matchingnir_op_pack_64_2x32_split64-bit base pointers, enabling same-block store-to-load forwarding after unswitching.speculativemode toagx_nir_opt_licm(shader, budget, speculative)enabled only onAGX3Bcompute shaders (!nir->info.internal), empirically capped atMIN2(regs - 8, 64)half-registers to avoid G17P compute register-pressure regressions while leavingagx_max_registers_for_occupancyandAGX3C/G18G/ graphics stages unchanged. Also enablesagx_nir_opt_canonical_minmaxonAGX3Bcompute.test-agx3-vision-opts.cppcovering live-out unswitching, two-break exit-phi refusal,pack_64_2x32_splitstore-to-load forwarding, speculative LICM, AGX3B uniform-base folding (load/store, aligned/unaligned/high/coherent), W8 byte-to-float codegen, and exact scalar W8u2u8store mask peeling (R8_UINTpeeled vs explicit0x7fmask vsR16_UINTunpeeled).Verification
cca699d5471):DEFAULT_BRANCH=perf/agx3-3x3-outer-peel-store-fwd bash .github/aurora/agent-policy.sh pr HEAD-> clean.AGX3VisionOpts.*: 28 / 28 PASS (cca699d5471).FEDORA-CI: 146 / 0 (0 fail, 0 timeout).g17p,g16g,g17s): 80 / 80 OK, 0 fails, 0 spills on all three chips.G17P B1/ MacBook Neo,e1a91e913db, zero codegen diff tocca699d5471, Borealis):5,439,488 / 5,439,488bit-exact IEEE-754 checks, 0 mismatches, 0 faults (post-RA audit confirmed native paths executed:u8->f32=7,s8->f32=8,s8->f16=10,w8-srl8=9).gpubench-vk: 16 / 16CRC_OK.PMU=30 00,FAULTS_DELTA=0,AVC_DELTA=0(spirv_w8_conv:804 Pass / 1528 NS;glsl_loops:624 Pass;ssbo:12,162 Pass / 63 NS;compute:12,607 Pass / 54,946 NS).slot9-wave4,#700vs Wave 4): 8 / 8 workloads improved (+4.2% geomean standalone):#700(ms)% of Metal(#700-> Wave 4)Assisted-by: LLM (Antigravity:Gemini 4 Neon)