Repository navigation
agx: canonicalize shared-memory element indices across disjoint ior and imadshl_agx - #1497
Conversation
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
00f8df9 to
bf295d6
Compare
DjDeveloperr
left a comment
There was a problem hiding this comment.
Two shared-address rewrites use the wrong IMADSHL semantics. NIR defines imadshl_agx(a, b, c, k) as a*b + (c << k). In gather_sum_mod32, peeling the 1 from imadshl_agx(x + 1, 2, y, 1) adds 4 to the replacement, though it should add 2. The nested cases must also scale the inner product when folding an outer shift. In known_zero_bits_u32, imadshl_agx(x, 1, y, 1) can be odd when x is odd, so its low bit cannot be used to turn OR 1 into +1. Please fix both paths and add value-equivalence cases with nonzero shifts, including the nested case. The current test uses shift zero on the inner IMADSHL and only checks opcode counts.
…nd imadshl_agx Add agx_nir_opt_shared_index_reassoc() for AGX3 compute shaders with shared memory. Modular 32-bit index sums truncated by u2u16 are unconditionally associative and commutative, even when the constant offset exceeds LDTG/STTG's 8-bit immediate byte offset. Using known-zero-bit analysis, peel affine constants out of: - disjoint ior(x, c) where (known_zero_bits(x) & c) == c, - imul/amul/ishl(x + c, k) and imul/amul/ishl(x | c, k), and - imadshl_agx(x + c, k, addend, sh) = ((x + c) * k) + (addend << sh), including nested outer shifts (ishl and imadshl_agx(0, _, inner, sh)) which scale the inner multiplier by (1 << outer_sh), peel (c * k) << outer_sh, and enforce the hardware shift domain (tot_sh <= 4). Run a second reassoc+CSE pass when progress occurs so sibling tile loads and stores share a single base index register. Add unit tests SharedIndexReassocDisjointOrAndNestedImadshl and SharedIndexReassocImadshlNonzeroShiftValueEquiv verifying exact value equivalence across direct/nested nonzero shifts, odd-product ior preservation, and shift-domain limits. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
|
Good catch on both
Verified offline with |
bf295d6 to
3f9b0bc
Compare
|
Quick hardware update: the revised
|
|
Hardware row at exact head Method: base
All other cases were NotSupported on both base and PR. * The J473 GLES31 compute failures are the same on base and PR. They come from the known M2 kernel issue linux#3851 (an empty compute stream returns EINVAL and later compute in the same context fails), not from this PR. Not covered: M1 and M5 hardware, and the per-PR M4 benchmark. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Re-reviewed at 3f9b0bcf. Both IMADSHL paths now follow a*b + (c << k): the direct peel adds cv*kv unshifted, the nested and zero-product folds scale the inner multiplier by the outer shift and stay within the shift-4 limit, and imadshl_agx(x, 1, y, 1) no longer counts as even. The new value-equivalence cases cover nonzero shifts, the nested forms and the refused shift-5 case. This clears my earlier request.
|
J773g (Apple M4 Mac mini, T8132, G16G B0) same-boot Vulkan A/B receipt — PASS.
|
|
Merge-tree hardware verification on Apple M4 Mac mini (
|
|
Merged as Local CI on pc, since hosted CI is off. It used the Fedora 44 image from
Hardware: the J773g merge-tree row ran this head on |
Forward-merge aurora-wip at e86174f (through #1497). hk_shader.c: this branch moved the pre-bounds optimization and bounds lowering out of hk_lower_nir_ex() into hk_lower_nir_buffer_bounds(); #1494 added the G16G aligned robust-loop versioning to that block. Carry #1494's step into hk_lower_nir_buffer_bounds() unchanged and pass the pipeline robustness state in, which both callers already hold. The function body now matches aurora-wip's inline block except for the optimize parameter this branch introduced. hk_cmd_draw.c: keep sparse_bda_free_stages next to #1522's native-AGX3 bind_tail_compact and draw_state_offset fields. meson.build: keep both new tests (hk_m5_lazy_sparse_bda and hk_queue_family_transfer). Signed-off-by: DjDeveloperr <hey@djdev.me>
Forward-merge aurora-wip at e86174f (through #1497). test-shared-byte-offsets.cpp: both sides appended new tests at the end of the file (AffineStridedCrossBlockCluster/AffineStridedGuards here, the SharedIndexReassoc tests from #1497). Keep both, this branch's tests first. Signed-off-by: DjDeveloperr <hey@djdev.me>
…tfield-slices Resolve conflicts against aurora-wip (e86174f) after #1494 and #1497 merged: - src/asahi/vulkan/hk_shader.c: keep g16_try_version_bounded_loop() and its call before the landed #1494 aligned-loop fallback. - src/asahi/compiler/agx_nir_lower_shared_bitsize.c: keep #1497 shared-index reassociation followed by #1495 bitfield-slice folding. - src/asahi/compiler/test/test-shared-byte-offsets.cpp: keep #1497 shared-index tests followed by #1495 bitfield-slice tests. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
What: Add
agx_nir_opt_shared_index_reassoc()for AGX3 compute shaders with shared memory so modular 32-bitu2u16(...)element indices are canonicalized into(sorted variable terms) + constanteven when the constant offset exceeds LDTG/STTG's 8-bit immediate byte offset. Uses known-zero-bit analysis to peel affine constants out of disjointior(x, c),imul/amul/ishl, andimadshl_agx(including nested shift-leftimadshl_agx(0, 1, inner_imadshl, sh)), followed by CSE and a second pass when progress occurs so sibling tile loads/stores share one base index register.Tested:
origin/aurora-wip(3f9b0bcf,gcc 16.1.1,aarch64,-Db_ndebug=false):agx_tests1902 passed / 0 failed (1skipped;30/30SharedByteOffsetsincludingSharedIndexReassocDisjointOrAndNestedImadshlandSharedIndexReassocImadshlNonzeroShiftValueEquiv),0warnings on modified files.ASAHI_SHIM_CHIP=g16gNIR_DEBUG=validateacross all 16llama-bench(Llama-3.2-1B-Instruct-Q4_K_M) pipelines and all 27 G16Gvk-sdbpipelines:0validation errors,0spills (27/27vk-sdbpass;mlx_matmul_coopmat -114instrs,qmm_vec_q4_word_sub_bf16 -52instrs,mul_mm_f16_full -28instrs &832->896thr).G16G),Llama-3.2-1B-Instruct-Q4_K_M(llama-bench,n=10QUIET,0GPU faults): shipped combined1.8321build vs1.8320measuredpp512 1507.59 tok/s(+4.27%vs1445.90,min=1498.80 max=1509.98 spread=0.74%),tg128 92.59 tok/s(iqr=0.32% spread=0.58%), livePERF62q4_K=270.5ms (-11.1ms),q6_K=48.5ms (-3.6ms),fa=22.4ms (-0.4ms),0GPU faults.Risk: two-way door · M4 / M5 (AGX3 compute compiler) — modular 32-bit addition truncated by
u2u16is unconditionally associative and commutative;ior(x, c)distribution is strictly gated on(known_zero_bits_u32(x) & c) == cso carry-free equivalencex | c == x + cholds for every input. Scoped to AGX3 shaders withshared_size > 0.Not yet: Standalone per-PR M4 benchmark isolation at head
3f9b0bcfand a second-generation (M1/M2/M5) regression capture.Offline & hardware details
origin/aurora-wip(866b091e, standalone, zero stacking dependencies)src/asahi/compiler/agx_nir_lower_shared_bitsize.c,src/asahi/compiler/agx_nir.h,src/asahi/compiler/agx_compile.c,src/asahi/compiler/test/test-shared-byte-offsets.cpp1.8321vs1.8320onASAHI_SHIM_CHIP=g16g:MUL_MAT q4_Khot loop375 -> 299(-20.3%),MUL_MAT q6_Khot loop508 -> 377(-25.8%),FLASH_ATTN_EXT159 -> 153GPRs,0:0spills across all 16 pipelines.