Repository navigation
agx: affine strided shared-offset decomposition and M5 multi-bank texture staging cache - #1524
Conversation
…-block clusters Extend agx_nir_opt_shared_byte_offsets() to decompose affine shared-memory element-index expressions (iadd, isub, ishl, imul/amul, imadshl_agx, imsubshl_agx) into scaled terms and a modular constant offset, while rolling back decompositions that do not extract a constant or merge terms so fused multi-term address ops are never unfused. For bounded clusters spanning a 256-byte chunk boundary or multiple blocks (such as unrolled strided stencil taps around a nonzero base offset), greedily anchor each 256-byte window at its minimum element offset using a canonical imadshl_agx expression so NIR CSE shares one address calculation across all taps and folds per-tap deltas into LDTG/STTG immediate byte offsets. Signed-off-by: DjDeveloperr <hey@djdev.me>
Add a 4-entry per-block multi-bank coordinate staging cache for M5 (AGX3C, non-G18G) plain 2D texel fetches and relocatable 2D texture samples: - Add agx3_m5_next_fetch_xy() and agx3_m5_next_sample_xy() to scan forward within a basic block past register-only ops and up to 3 intervening disjoint-banked plain 2D fetches/samples (stopping on any coordinate register overwrite, non-banked texture op, barrier, or memory op). - Reserve active cached bank halves in agx3_staging_plan_above_reserved() and agx3_emit_texture_fetch() so intervening ops allocate disjoint banks without evicting cached coordinates before their next consumer. - Preserve exact hardware .coord_kill liveness (false while a verified later consumer remains in the block, true on the final consumer) and accumulate every consumer's scoreboard slot in staging_banks. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Independent exact-head M5 Max ( Stack & build:
Correctness (
Same-boot ABBA (
|
satchlj
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at dd115067502d20aa226b45fc1b48dfa9f9362731
Blockers:
- Missing second-generation exact-head hardware row: commit
259474f2eb86changes shared-memory offset codegen across both AGX3B and AGX3C targets, while the posted exact-head hardware row covers M5 Max (J775c, AGX3C) only. Once one AGX3B exact-head row (J700G17P orJ773gG16G, already queued inNot yet) passes and is posted, this review is ready to flip toAPPROVEwithout a full re-review.
Checked: no Apple material, no inappropriate model gating, full diff of both commits (affine shared-offset decomposition and M5 multi-bank staging cache), unit tests, exact-head M5 Max hardware receipt
Evidence
- Commit 1 (
259474f2eb86,src/asahi/compiler/agx_nir_lower_shared_bitsize.c+test-shared-byte-offsets.cpp): verifiedgather_affine_sum()modular arithmetic and rollback on unmerged ops,analyze_elem_candidate()non-wrapping 16-bit bounds check (scale <= UINT16_MAX,ub <= UINT16_MAX,scale * ub <= UINT16_MAX,bound <= UINT16_MAX - elements), cross-block greedy min-anchor windowing (prefer_greedy),emit_affine_expr()/expr_matches_canonical()idempotency, andsmall_sharedfallback. - Commit 2 (
dd115067502d,agx3_lower_texture_publications.c,agx3_pack_binary.c,agx3_staging.h,test-agx3-pack-binary.cpp,test-agx3-uniform-alu.cpp):- Scoped to
AGX_ISA_ENCODING_AGX3C && !emit_agx3d && !is_preamble && !has_ray_traversalon fragment/compute stages. agx3_m5_next_fetch_xy()andagx3_m5_next_sample_xy()stop on any coordinate/packed-level destination overlap, non-plain fetch/sample, or non-preserves_publications()instruction, matchingagx_foreach_instr_in_block()emission order.- Verified
staged_samplealready retireswaitbefore thereuse_xybranch (assert(relocatable_coordinates && staged_sample && !wait)),agx3_staging_hold()still holdsbank_basefor every reusing slot, andstage_cache_halvesexcludes reserved banks in bothagx3_allocate_staging()andagx3_emit_texture_fetch(). - Non-blocking defensive nit: in
agx3_emit_texture_fetch()(src/asahi/compiler/agx3_pack_binary.c), if!placed && !have_fallback(currently unreachable becauseARRAY_SIZE(stage_cache) == 4andplain_banks >= 6), returningfalseinstead of falling through tostaging_coord = fallback_coordwould guard against overwriting a reserved bank if cache capacity increases later.
- Scoped to
- Exact-head M5 Max (
J775c,G17C B1) verification atdd115067502dpassed243/243unit tests, 2D texture dEQP,llama.cpptest-backend-ops, bit-exactgpubench-rt-vkCRCs, and same-boot ABBA with0GPU faults.
|
Exact-head M4 Mac mini (
|
|
J714s (M5 Pro, G17S B1) exact-head row at Base is the PR's merge base with MacBook Pro (M5 Pro, G17S B1), stock
|
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>
|
Forward-merged This is a merge commit ( Conflict resolved: there was one conflict, in The PR's diff is unchanged. I compared
So the J714s exact-head row (#issuecomment-7344582749) carries over to this head, and so do the J775c and J773g rows at Interaction with #1497: on AGX3, #1497's new
Local CI on the new head: run on pc, because hosted CI is disabled. The tree is
These counts match the Parked for TAG CUT. Merge command: |
satchlj
left a comment
There was a problem hiding this comment.
MERGE at 91a7b69947a0.
Forward-merge on aurora-wip e86174f6 verified clean:
agx_nir_lower_shared_bitsize.cpreserves#1497'sknown_zero_bits_u32alongside#1524's unchanged hunks across all 7 source files.test-shared-byte-offsets.cppkeeps both#1497'sSharedIndexReassocDisjointOrAndNestedImadshland#1524'sAffineStridedGuardstests cleanly.- Exact-head/source-identical hardware verification now covers M4 (
J773g,G16G B0: 582 shared-memory CTS 0 diffs,gpubench-vk6/6valid=true, 0 faults) and M5 Pro (J714s,G17S B1: 107/107cts-rq, 20,000 tiered CTS 0 diffs, 24 ABBAgpubench-vk, 0 faults), plus exact-head local CI (389 Ok / 0 Fail,610/610gtests) and green GitHub CI.
What
Ports two compiler optimizations cleanly onto
aurora-wip(always-on, no new debug/env flags):agx_nir_lower_shared_bitsize.c, shared across all AGX3B and AGX3C targets, including G18G and G17P):agx_nir_opt_shared_byte_offsets()to decompose affine shared-memory element-index expressions (iadd,isub,ishl,imul/amul,imadshl_agx,imsubshl_agx) into scaled terms plus a modular constant offset, rolling back decompositions that do not extract a constant or merge terms.imadshl_agxexpression so NIR CSE shares one address calculation across taps and folds per-tap deltas intoLDTG/STTGimmediate byte offsets.agx3_lower_texture_publications.c,agx3_pack_binary.c,agx3_staging.h,agx_compiler.h, M5/AGX3C-only excludingemit_agx3d):agx3_m5_next_fetch_xy(),agx3_m5_next_sample_xy()), scanning forward past register-only ops and up to 3 intervening disjoint-banked plain 2D fetches/samples while stopping on any coordinate register overwrite, non-banked texture op, barrier, or memory op.agx3_staging_plan_above_reserved()andagx3_emit_texture_fetch()so intervening texture ops allocate disjoint banks without evicting cached coordinates, while preserving exact hardware.coord_killliveness and accumulating every consumer's scoreboard slot instaging_banks.Tested
dd115067502d(base7fe256e03606):-Dbuild-tests=true), 0 new warnings.meson test --suite asahi --suite vulkan --suite poly: 247/247 PASS (0fail), includingagx_tests(1924 passed, 1 skippedNativeFMA.ExactDyadicOracle, 0 failed), coveringSharedByteOffsets.AffineStridedCrossBlockCluster,SharedByteOffsets.AffineStridedGuards,SharedByteOffsets.NestedImulIorImadshlBounds,AGX3PackBinary.M5MultiBank*,AGX3PackBinary.M5SampleXY*,AGX3PackBinary.ComputeShadow2DArrayRegisterDescRetiresLiveSlot6OnAGX3C, andAGX3FetchGroups.*.7.3.0-m5-pr67, differentrc14adevelopment stack — NOT exact-headdd115067502d):cts-rq,cts-sparse-ssbo-residency) PASS, GPUBench RT (rt.scene, checksumb541b83e) PASS,0GPU faults.2560x1440, Very High RT, FSR Quality, 5-pass headless, priorrc14astack): no regression across the 5 passes (median+0.33 FPS, pass deltas[+0.388, +0.328, -0.050, +2.247, -0.103],0GPU faults,0clamp seconds).-83native (-11.6%), FSR1-80native (-10.2%) across 5.44M thr/fr;-1,834staging copies /-1,958native across 104 shaders (Denoise1-25%, Denoise2-23%, Lighting-10,0regressions).Risk
Two-way door confined to
src/asahi/compiler/. Commit 1 changes shared-memory offset codegen (including bounded cross-block anchoring) on all AGX3B and AGX3C targets, including G18G and G17P; G13X is untouched. Commit 2 is gated to AGX3C excludingemit_agx3d, preamble, and ray-traversal shaders.Not yet
aurora-wip(7fe256e03606vsdd115067502d) J714s (G17S) hardware A/B qualification row (paired bundle staged on Mini).G17P) and J773g (G16G) (both requested inrow-requests.tsv).