Repository navigation
asahi,borealis: speed up cold AGX3/Borealis pipeline compilation - #1245
Conversation
…bitsets Eliminate wasted cold pipeline compile time with zero codegen changes: - nir_opt_fp_math_ctrl: drop preserve_signed_zero without FP range analysis when no consumer observes -0, and early-out when no ALU, derivative, or IO load can be updated. - agx_compile: gate loop-only and multi-block-only NIR passes on agx_nir_has_loop() / agx_nir_is_single_block(), skip cloning in agx_compile_shader_nir_unrolled() when loop-free, skip agx_nir_opt_shared_byte_offsets when shared_size == 0, gate post-forward-merge DCE on progress, and expose agx_compile_shader_nir_capture_ex() / agx_compile_shader_nir_postopt() for trivial monolithic fragment epilogs. - agx_pressure_schedule: replace the O(n^2) ready-node scan in ilp_schedule_block() with a dense BITSET_WORD ready set (preserving strictly ascending tie-break order) and switch ilp_max_pressure() and ilp_block_peak() from sparse to dense liveness bitsets. - Add unit tests in test-agx3-pso-compile-fastpath.c. Signed-off-by: DjDeveloperr <hey@djdev.me>
Reduce AGX3 instruction-packing overhead during cold shader compiles: - Cache the per-thread binder scratch pointer in an 8-byte _Thread_local while keeping tss_set() for thread-exit cleanup. - Shrink agx3_bind_memo::field from uint16_t to uint8_t, skip zero baseline writes, and reject mismatched explicit encoding-point probes via agx3_form_preds_match() before building a memo key or locking. - Add agx3_bind_compose_ep_range() to probe an encoding-point range with a single scratch populate/clear cycle, and adopt it in uniform_float_encode() and the wide fsel/fseli16 probe loops. - Add unit tests in test-agx3-bind-memo.c. Signed-off-by: DjDeveloperr <hey@djdev.me>
Avoid redundant cloning and NIR optimization during Vulkan pipeline compilation: - Add lightweight pre-filters before cloning/lowering NIR in the identity_copy4, tensor-op, byte-stencil, 2D-stencil, and pointwise-clamp compute matchers. - Switch hk_shader.c nir_opts() to a circular worklist fixed point and extend can_post_lower in hk_lower_nir() to loop-free IO-only shaders without shared memory. - Capture transient post-agx_optimize_nir NIR for non-preamble opaque fragments and reuse it via agx_compile_shader_nir_postopt() when pre-linking trivial non-ALU 1x epilogs, freeing the clone right after pre-linking. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
J714s (MacBook Pro M5 Pro,
|
…ompile-fastpaths Signed-off-by: DjDeveloperr <hey@djdev.me>
|
|
…ompile-fastpaths Bring in mesa#1255 (AGX3 ILP tile-store payload bank bound), mesa#1239, mesa#1228 and mesa#1257. mesa#1255's ilp_tile_store_bank_overflows() walks the candidate and original orders over sparse live sets, while this branch moved ilp_schedule_block()'s live_end/scratch to dense BITSET_WORD arrays. Port the tile-store bank helpers to the dense sets (BITSET_FOREACH_SET, memcpy, sched_liveness_update_dense) so the check runs over the same live set the pressure check uses. The bank fit and the reject rule (overflow when the original order fits, or a higher peak than the original order) are unchanged. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
|
|
J714s (M5 Pro, G17S) refresh at eab548e, kernel 7.3.0-m5-cdirect16. Built on the machine, driver loaded only through VK_DRIVER_FILES.
|
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: MERGE at eab548e306f194b1f719b024f66b9fcdcc0f6267
Blockers: none
Checked: I read the whole diff (22 files) at the exact head and tried to break each fast path.
- Cache and keys: nothing new reaches a cache key or a serialized blob.
g17p_mono_postopt_nirlives in memory only. It is NULL after a binary-cache clone and freed once prelink finishes, so a shader loaded from cache takes the old deserialize path. The postopt path is only taken for a 1x, no-preamble, non-uniform-blend, non-inline-samples epilog made of mov/vec/load_exported/store_local_pixel with a constant 0xFF mask. Uniform exports fall back to the pre-preamble NIR. For that shape the skippedagx_nir_lower_g17p_tile_samples, zs hoist and refusal scan are no-ops. The key fields that differ fromg17p_mono_key(no_stop, secondary, rodata hint, partitions) are the ones the existing preoptimized path already accepts. - Skipped passes: every pass newly gated on
has_loopswalks loops only (monotonic_bit_insert, top2_min, factor_loop_mac, const/runtime unroll, hoist_readonly_loop_loads, unswitch_affine_bounds, loop-invariant guard bits). shared_index_sort and shared_byte_offsets now needshared_size > 0, and both only touch shared memory. The single-block skips only drop if/phi passes. The worst case for a stalesingle_blockis a missed optimization, not wrong code.agx_nir_has_loopscans every impl. The loop-free shortcut inagx_compile_shader_nir_unrolleddrops only the factor-4 and factor-1 retries, andm5_unroll_factoronly gates loop passes, so those retries would give the same binary. - Preprocess: the signed-zero min/max block now runs only on the first preprocess. The generic
lower_fminmax_signed_zerois still set inagx_nir_options, so ops added before the post-lower pass are still lowered correctly, just generically. The widenedcan_post_loweris backed by the debug asserts inagx_assert_post_lower_invariants(flrp, frexp, sincos and subgroups already lowered), and the assert-enabled gate below passes with them on. nir_opt_fp_math_ctrl: the early clear of preserve_signed_zero gives the same result as the old!pass_flags ||branch. Running it beforenir_analyze_fp_classcan only widen the zero bits (handle_sz), which matter only for the flag that has already been cleared. Theany_workpre-scan covers every case where the pass can make progress (ALU sz/inf/nan flags, ddx/ddy sz, IO loads without no_signed_zero).nir_optsworklist: the wake sets are sound. copy_prop, cse and constant_folding do not re-wake themselves, and DCE cannot create work for copy_prop, cse, constant folding, undef or remove_phis.- Binder: the AGX3D refusal in
agx3_bind_compose_ep_rangematches the old per-epagx3_bind_compose, which also rejected AGX3D with an explicit ep. Leaving out zero-valued fields depends on the scratch vector starting at zero, andclear_nonzeroplus the stack memset keep it that way. Theuint8_tmemo field holds indices up to 160, and memo hits compare everything under the lock. The_Thread_localpointer only caches whattss_getreturns, andtssstill owns the cleanup. - Scheduler: the ready bitset is set only at init and at the single
--ndeps == 0site. Iteration stays ascending, so droppingi < bestkeeps the same tie-break. - Determinism and codegen parity: asahi_clc precomp (libagx for all 8 targets, g13g through g18g, including g17p/g17g) is byte-identical between tip
c9ec6b97and this head, and three head runs give identical output. - NO-GATES: no new chip or board gates. The one
agx_chip_g17_m5()use was moved, not added. - Rows at this exact head: J316s (G13S), J615 (G15G), J700 (G17P) and J714s (G17S, with an interleaved cold
compile.psoABBA: -9.4 / -13.0 / -11.5 %).
Non-blocking:
test_fp_math_ctrl_fast_pathswould also pass against the old pass. It checks equivalence, not a regression, which is fine for a pure speed change. A case with a load that already hasno_signed_zeroplus a flagged ALU would exercise theany_workscan's false-negative direction.- Nothing at this head exercises cold-compile timing on J700 (the J700 timing was at
8c87753b), and there are no J413 or J773g rows. Two generations are present, so this does not hold the merge.
Evidence
- Scratch merge of
eab548e3intoaurora-wipc9ec6b97(clean, treee96e01f9). x86 drm-shim gate (-Dbuildtype=release -Db_ndebug=false,meson test --suite asahi --suite poly): 339/339 OK. Tip baseline: 339/339 OK. libagx_shaders.hsha25677fe1f5c...e90aandlibagx_shaders.csha25690ff37d2...f8are identical for the tip build, the head build and two extra headasahi_clcruns.
#1245 changed when hk_lower_nir() may take the post-lower preprocessing (can_post_lower). This branch moved texture lowering and that preprocessing into hk_lower_nir_post_tex(), so the new condition now feeds the hk_lower_nir_post_tex() call at the end of hk_lower_nir_ex(); lowered_tex is still checked inside it. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Post-merge correction to my review above: I missed a real defect, and the tip gate caught it after the merge.
Repro on tip a0164c9 (x86 drm-shim, Fix and a deterministic unit-test check: #1264. |
Summary
Eliminate wasted CPU time during cold Vulkan pipeline compilation (
gpubench-vk compile.psocompute, graphics, and uber) across NIR, the AGX3 backend/binder, and Borealis with zero shader-codegen regressions:NIR & AGX3 compiler/scheduler fast paths (
0d342cb6e57):nir_opt_fp_math_ctrl: clearnir_fp_preserve_signed_zerowithout FP range analysis when no consumer observes-0, and early-out when no ALU, derivative, or IO load can change.agx_compile: gate loop-only and multi-block-only NIR passes onagx_nir_has_loop()/agx_nir_is_single_block(), skip cloning inagx_compile_shader_nir_unrolled()when loop-free, gateagx_nir_opt_shared_byte_offsetsonshared_size > 0, gate post-forward-merge DCE on progress, and exposeagx_compile_shader_nir_capture_ex()/agx_compile_shader_nir_postopt()for trivial monolithic fragment epilogs.agx_pressure_schedule: replace the O(n²) ready-node scan inilp_schedule_block()with a denseBITSET_WORDready set (preserving strictly ascending tie-break order) and switchilp_max_pressure()/ilp_block_peak()from sparse to dense liveness bitsets.src/asahi/compiler/test/test-agx3-pso-compile-fastpath.c.AGX3 binder fast path & TLS scratch cache (
c27925c4c81):_Thread_localwhile keepingtss_set()for thread-exit cleanup.agx3_bind_memo::fieldtouint8_t, skip zero baseline writes, and reject mismatched explicit encoding-point probes viaagx3_form_preds_match()before building a memo key or locking.agx3_bind_compose_ep_range()to probe an encoding-point range with a single scratch populate/clear cycle, used byuniform_float_encode()and the widefsel/fseli16probe loops.src/asahi/compiler/test/test-agx3-bind-memo.c.Borealis compute pre-filters & post-opt monolithic fragment reuse (
d9c742c9171):identity_copy4, tensor-op, byte-stencil, 2D-stencil, and pointwise-clamp compute matchers.hk_shader.c:nir_opts()to a circular worklist fixed point and extendcan_post_lowerinhk_lower_nir()to loop-free IO-only shaders without shared memory.agx_optimize_nirNIR for non-preamble opaque fragments and reuse it viaagx_compile_shader_nir_postopt()when pre-linking trivial non-ALU 1xALL_SAMPLES(0xFF) epilogs, freeing the clone immediately after pre-linking.Benchmarks (Exact-Head ABBA+BAAB, 4 base + 4 head,
count=32, shader cache disabled)MacBook Neo (
J700, Apple A18 ProG17P B1, stock7.3.0-41.fc44.aurora.aarch64, isolated overlays)Tested exact-head
b2a7eecc318+0vs parent1e793d856d4+0(same boot2b400cd8-57f6-4af8-b7ae-fcd12b592205,stock.shPRE==POST 0 diffs,kfaults=0,avc_delta=0). Rebased cleanly ontoaurora-wip(ef132f590b2) with identical logic (d9c742c9171).P-core pinned (
cpu5, eliminating A18 Pro E-core/P-core migration jitter):compile.psokindper_pso(ms)per_pso(ms)compute0.60540.562019.4917.99graphics1.28391.184541.5537.95uber1.43541.283547.4142.63Unpinned (default EAS scheduler):
compile.psokindper_pso(ms)per_pso(ms)compute1.19391.190540.1841.80graphics1.85581.747367.4663.17uber1.91851.812973.3169.01*Unpinned
computeruns ~40 ms total and randomly stays on E-cores (~1.52–1.56 ms) vs migrating to P-cores (~0.55–1.15 ms).Host
drm-shim(g17p, P-core pinned, 4-round ABBA)compile.pso[compute]:0.9016 -> 0.8489 ms/pso(1.062x, total-8.03%)compile.pso[graphics]:1.8325 -> 1.6915 ms/pso(1.083x, total-7.99%)compile.pso[uber]:2.1993 -> 1.9927 ms/pso(1.104x, total-9.13%)vk-mini(39 foz, 297 shaders):1418.6 -> 1366.4 ms(1.038x,-3.69%)Verification
g17p:compile.pso(64 shaders: 0 diffs),gb6-horizon-edge(8 foz, 28 shaders: 0 diffs),vk-mini(39 foz, 297 shaders: 296 identical, 1 improvement —gpubench-stress.fault.comp.fozCProggpr_halves 8 -> 6, same62bytes).g17s(M5):compile.pso(56 shaders: 0 diffs),vk-mini(178 shaders: 0 diffs),gb6-horizon-edge(28 shaders: 0 diffs).ASAHI_MESA_DEBUG=verify(8/8 PASS):render.postfx(5deb69ac),render.deferred(2cfe9a54),render.shadow(c0fb9993),render.mdi(06f8412a),compute.edge(27c79e6d),compute.conv2d(2d55a14d),compute.uber(9963f56c),compute.blur_fp32(abee0456) — all bit-exact across base, head, and head+verifywith emptyverify.err.deqp-vk, shader cache disabled) — 1,311 / 1,311 PASS, 0 FAIL:dEQP-VK.pipeline.monolithic.cache.*: 774/774 PASSdEQP-VK.pipeline.monolithic.blend.format.r8g8b8a8_unorm.*: 100/100 PASSdEQP-VK.shader_object.binary.*: 437/437 PASSfedora-mesaci.sh):b2a7eecc318(pre-rebase exact-head): 217/217 PASS, 0 FAIL, 0 new warnings.d9c742c9171(rebased ontoef132f590b2): 217/218 PASS (only failure is pre-existinghk_sync_stampsline 1237 onef132f590b2tip, untouched by this PR).