Repository navigation
hk,agx: version aligned robust compute loops on G16G and refine preamble weights - #1494
Conversation
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
g16_parse_invariant_bound accepts any bound defined outside the loop. That proves loop invariance but allows a per-invocation bound from a nonuniform SSBO array index. For example, with 32-byte records and lanes selecting 64- or 68-byte descriptors, g16_version_aligned_robust_loops splits the subgroup between the two loop copies. A subgroup reduction inside the original loop then sees a different active-lane set, and a workgroup barrier would also become divergent. Please require workgroup-uniform bounds for versioning and add a nonuniform descriptor test that leaves the loop intact.
…ble weights
Two compute-kernel compiler improvements:
1. hk_shader.c (g16_version_aligned_robust_loops):
- On G16G (!soft_fault), version compute loops containing AoS bounded
buffer loads (offset = amul(ib, stride) + local, provable
local + load_size <= stride <= 4096 < AGX_ZERO_PAGE_SIZE) on
bound % stride == 0 once before the loop.
- Require workgroup-uniform bounds via
nir_divergence_analysis_impl(..., nir_divergence_across_subgroups) and
nir_def_is_divergent_at_use_block() so per-invocation or per-subgroup
nonuniform descriptor bounds never split subgroups or workgroup
barriers.
- Inside the fast loop, share one (valid, vbase, vblock) check per
struct element across all fields of the element and emit unbounded
global loads so downstream load vectorization merges adjacent fields
without per-component tail masks.
- Arbitrary unaligned descriptor sizes take the unmodified fallback
loop with exact robustBufferAccess / robustBufferAccess2 /
nullDescriptor semantics.
- Add hk_aligned_robust_loop_test covering uniform descriptor
versioning and per-lane / per-subgroup nonuniform descriptor rejection.
2. agx_nir_opt_preamble.c:
- Model nir_op_usub_sat at its true 2-instruction AGX cost (iadd +
icmpsel = 2.0) instead of 1.0.
- Preserve preamble hoisting weight for loops nested inside uniform
branches (weight *= 8.0f per enclosing loop, clamped to 1.0f).
Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
|
Fixed
Verified offline with |
a37a6ac to
4ab7686
Compare
DjDeveloperr
left a comment
There was a problem hiding this comment.
Rechecked the uniformity fix at 4ab768672c5d. Both outside-loop bound paths now require workgroup-uniform values, and divergence analysis treats differences between subgroups as divergent. The new tests cover the uniform case and leave the original loop intact for both lane-varying and subgroup-varying descriptors. The author reports all three cases passed. Please record a J604 hardware run at this head before landing, including the G16G robust-loop path.
|
Row: @IronsideXXVI Do you already have the J604 run booked? @erikwb If J604 is still pending, can J713 run the G16G comparison on its existing boot? I have the checksum-verified 10,152-case kit ready to send. It loads the two ICDs through |
|
Non-M4 cross-generation row at exact head Method: base
Not covered: a standalone A/B from |
|
J773g (M4 Mac mini, T8132, G16G B0) hardware row PASS at exact head
|
|
Merge-tree hardware verification on Apple M4 Mac mini (
|
|
Local CI passed on The Asahi compiler, NIR, and HK shader pipeline source matches the J773g merge-tree A/B byte for byte. That run exercised both the aligned fast loop and unaligned fallback with matching outputs, zero CTS differences across 10,152 cases, and zero GPU faults. The J700 control and the earlier Arm64 CI also passed. |
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>
…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>
Resolve conflicts in src/asahi/vulkan/hk_shader.c after #1494 landed on aurora-wip (e86174f): - Keep both g16_version_aligned_robust_loops() (on AGX_CHIP_G16G, with follow-up CSE when versioned) and hk_nir_g16_merge_bounded_loads() under !global_loads.soft_fault in hk_lower_nir_ex(). - Deduplicate identical static helper g16_emit_global_load() shared by both passes. All other hunks auto-merged cleanly without changing any of #1472's own logic. Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
What: Add
g16_version_aligned_robust_loops()insrc/asahi/vulkan/hk_shader.cfor G16G (!soft_fault) compute loops with AoS bounded buffer loads, and updatesrc/asahi/compiler/agx_nir_opt_preamble.cto modelnir_op_usub_satat its 2-instruction AGX cost (2.0) and preserve preamble hoisting weight for loops nested inside uniform branches.Tested:
aurora-wip(f6ea9a1b, conflict-free against866b091e) in an aarch64 Linux container (gcc 16.1.1) with 0 warnings inhk_shader.candagx_nir_opt_preamble.c;agx_tests:1884 passed / 0 failed(1skipped);libvulkan_asahi.solinked cleanly.ASAHI_SHIM_CHIP=g16g,NIR_DEBUG=validate,agx_validate()): 27/27 G16Gvk-sdbshaders and 32/32omarchy-mlxQwen3.5-2B shaders pass with0:0spills and 0 occupancy regressions; realllama-benchVulkan compute hot loops dropMUL_MAT q4_K530 -> 466(-64/-12.1%),MUL_MAT q6_K748 -> 626(-122/-16.3%), andFLASH_ATTN_EXT2399 -> 2391(-8), keeping127GPRs /832threads.J604,T8132/G16G),Llama-3.2-1B-Instruct-Q4_K_M(llama-bench,n=10,0GPU faults):1.8317(0025+0026+0027vs1.8314):pp512 1379.00 tok/s(+8.90%,spread=0.52%,0faults).1.8320(on GOOD1.1677):pp512 1445.90 tok/s(+14.18%,89.8%of native Metal,spread=0.50%),tg128 92.50 tok/s(+4.18%,iqr=0.20%),0GPU faults.Risk: two-way door · M4 (G16G / T8132) and AGX preamble heuristic —
g16_version_aligned_robust_loops()is gated toAGX_CHIP_G16G && !soft_faultand preserves exactrobustBufferAccess/robustBufferAccess2/nullDescriptorsemantics by checkingbound % stride == 0once before the loop and routing any unaligned descriptor size to the unmodified fallback loop; preamble cost/weight changes only tune hoisting priority within existing uniform budgets.Not yet: Standalone hardware A/B built directly from
aurora-wip(a37a6ac1) and a non-M4 cross-generation hardware regression row for theagx_nir_opt_preamble.cheuristic change (we only have an M4J604locally).Details and verification
Summary of changes (
a37a6ac1onaurora-wipf6ea9a1b)src/asahi/vulkan/hk_shader.c(g16_emit_global_load,g16_version_aligned_robust_loops):!soft_fault), compute loops containing AoS bounded buffer loads of the formoffset = amul(ib, stride) + localwith provablelocal + load_size <= stride <= 4096 < AGX_ZERO_PAGE_SIZEcheckbound % stride == 0once before the loop.(valid, vbase, vblock)check (valid = block < bound), redirecting OOB blocks toAGX_ZERO_PAGE_ADDRESSwhile emitting unbounded global loads (nir_load_global/nir_load_global_constant) so downstream vectorization merges adjacent fields without per-component tail masks.robustBufferAccess/robustBufferAccess2/nullDescriptorbehavior.agx_nir_opt_shared_byte_windowsfrom our earliere705eca833fcarry is already covered onaurora-wipbyfold_elem_offsets_impl()inagx_nir_lower_shared_bitsize.c, and the 4-linenir_isubcleanup insideg16_merge_bounded_loadsdepends on hk,agx: vectorize bounded buffer loads on G16G without soft faults #1472 and is omitted here to keep this PR orthogonal and conflict-free.src/asahi/compiler/agx_nir_opt_preamble.c:nir_op_usub_satits true 2-instruction AGX cost (2.0foriadd + icmpsel) instead of1.0.weight *= 8.0fper enclosing loop, clamped toMIN2(weight, 1.0f)).Verification
ninja -C /build -j6 src/asahi/compiler/agx_tests src/asahi/vulkan/libvulkan_asahi.so: 0 warnings inhk_shader.candagx_nir_opt_preamble.c./build/src/asahi/compiler/agx_tests:1884 passed, 1 skipped, 0 failed.