Repository navigation
agx, borealis: handle fmin/fmax/fsat in FP32 denorm preserve lowering and unify exposure - #813
Conversation
RyanTheTide
left a comment
There was a problem hiding this comment.
CHANGES · source review of 1c16f85af871
The rationale says FP32 preservation is supplied by software lowering, but the exposed property is still selected by chip family and the published row is M5 Pro only. Please derive the property from the stage/encoding capability that guarantees the lowering for every advertised path, and provide native AGX3 rows for every newly advertised encoding. In particular, report denormal input and result cases across the supported stages.
Verification here was by source inspection.
|
@DjDeveloperr Could you tie exposure to the lowering capability and include denormal input and result coverage by stage and encoding? In a separate exposure trial, both Airs failed the same three runtime-input cases for clamp, min and nmin. Direct fmin/fmax were absent from the exact lowering in that trial. |
… and unify exposure Hardware fmin/fmax (fcmpsel) can flush denormal inputs during comparison on AGX3B chips (G15/G16), and fsat lowers to fadd.sat(x, -0.0) which flushes positive denormals to zero. - agx_nir_lower_denorm_preserve.c: add exact integer-ordered lowering for nir_op_fmin, nir_op_fmax, nir_op_fmin_agx, nir_op_fmax_agx (preserving IEEE 754 minNum/maxNum NaN semantics and signed-zero ordering) and nir_op_fsat when an operand is denormal. - agx_chip.h / hk_physical_device.c: derive shaderDenormPreserveFloat32 from agx_chip_has_fp32_denorm_preserve(dev->chip), tying Vulkan exposure to the AGX3B/AGX3C lowering capability across native AGX3 and M5. - test-denorm-preserve-fma.cpp: add bit-exact fmin/fmax/fclamp/fsat denormal tests and multi-stage (VS/FS/CS) compilation coverage for both AGX3B (G15G, G16G, G17P) and AGX3C (G17S). Signed-off-by: Diljit Singh <hey@djdev.me>
1c16f85 to
1b34640
Compare
|
Pushed R2 (
Assisted-by: LLM (Google:Gemini 4 Neon) |
|
@RyanTheTide Fresh exact-head R2 hardware row on G17S B1 (
|
There was a problem hiding this comment.
Head 1b34640bb383f664dfa3a4fa00da3438ccfcd92a, base efabab38502dc32302a058503231b12e815a21f9 (the head's parent = merge-base with aurora-wip; diff reviewed is base..head).
Read the whole diff.
lower_minmax: when either operand is denormal it computes the result as an exact integer-ordered comparison viaorder_key(so-0 < +0correctly), and layers IEEE 754 minNum/maxNum NaN handling on top (is_nan(x) → y,is_nan(y) → x) — matching what fcmpsel does for the non-flushing cases. Non-denormal inputs take the native instruction unchanged, so the added work only runs where the flush could occur. Coversfmin/fmax/fmin_agx/fmax_agx.lower_fsat:fadd.sat(x, -0.0)flushes positive denormals; the guard returnsxforx >= 0and0below — exact for the denormal range, native path otherwise.hk_physical_device.c:shaderDenormPreserveFloat32moves from achip == AGX_CHIP_G17Pliteral toagx_chip_has_fp32_denorm_preserve()— AGX3B/AGX3C encoding +agx_chip_native_or_m5. On our AGX2 chips (G13G/G13X) the predicate is false, so the advertised feature set is unchanged; the widening only lands where the unconditional lowering actually runs.- New
test-denorm-preserve-fma.cppcases (208 lines, inside the existing test binary): bit-exact min/max/clamp/sat denormal vectors plus multi-stage compile coverage across G15G/G16G/G17P (AGX3B) and G17S (AGX3C).
Built and ran at this head (aarch64):
- release build clean; full asahi suite 164/164 (169/169 with the poly suite).
Hardware rows — deqp-vk 1.4.7.1, 13,781 dEQP-VK.compute.* cases (cooperative_matrix excluded), per-case status vs the aurora-wip b10c5d3f build:
- 13-inch M1 MacBook Pro: 0 diffs of 13,781
- 16-inch M1 Max MacBook Pro: 0 diffs of 13,781
(Also 0 diffs of 13,781 on both laptops vs the efabab38 merge-base build.)
On these chips the pass never engages for FP32 DenormPreserve (the feature stays unexposed and the lowering is gated to the AGX3 encodings), so the change is a no-op on our hardware by construction — the rows verify nothing else moved.
Approving.
|
Merged into
Assisted-by: LLM (Google:Gemini 4 Neon) |
There was a problem hiding this comment.
Post-merge source review of 1b34640bb383 (merged as 0edb84f85fd6). I found no defect in the new lowering. One coverage gap remains open on the chips this change newly exposes.
Checked. lower_minmax(): integer order keys give -0 < +0. A NaN operand returns the other operand, and two NaNs return NaN. The exact path is taken only when an operand is denormal, so normal and inf operands keep the native fcmpsel. lower_fsat(): a negative denormal gives +0 and a positive denormal is returned unchanged. NaN is not denormal, so it stays on the native path. The newly built native min/max/sat are inserted before the instruction being lowered, so they are not revisited.
- Exposure moved to G15G/G16G with no M3/M4 row at this head. Before this change,
shaderDenormPreserveFloat32was true on G17P only.agx_chip_has_fp32_denorm_preserve()now also turns it on for G15G/G15S/G15C/G16G (M3, M4) and M5. The R2 hardware row is G17S only, at 216/222 pass and 0 fail. The pre-R2 Air trial that found the min/clamp/nmin failures ran on G15G/G16G, and the "J615/J713 known-failure controls" are still marked queued. Please post the samefloat_controls.fp32denorm_preserve set (compute and graphics, input_args and generated_args) at0edb84f85fd6on one G15G and one G16G Mac. Those two are what the merge newly advertises. - Ops the pass still leaves native. The pass lowers add/mul/fma/neg/abs/compares/min/max/sat/sign. Rounding and fraction ops are not lowered:
ffloor,fceil,ftrunc,fround_even,ffract. If AGX3B flushes their inputs the way it flushesfcmpsel,floor(-denorm)gives -0 instead of -1, andfract(denorm)gives 0. Neither has a unit test here, and M5 passing CTS does not show how G15/G16 behave. The G15G/G16G row in item 1 settles it: if any of these fail there, they need the same integer lowering, or the exposure stays G17P/M5-only until they are lowered.
Summary
Fixes FP32 denormal preservation for
min/nmin/max/nmax/clamp/nclamp/fsaton AGX3B/AGX3C and ties VulkanshaderDenormPreserveFloat32exposure directly to the lowering capability:src/asahi/compiler/agx_nir_lower_denorm_preserve.c: hardwarefmin/fmax(fcmpsel) can flush denormal inputs during comparison on AGX3B chips (G15/G16), andnir_op_fsatlowers tofadd.sat(x, -0.0)which flushes positive denormals to zero. Adds exact integer-ordered lowering (order_key()+is_nan()) fornir_op_fmin,nir_op_fmax,nir_op_fmin_agx,nir_op_fmax_agx(preserving IEEE 754minNum/maxNumNaN semantics and-0 < +0ordering) andnir_op_fsatwhen an operand is denormal.src/asahi/lib/agx_chip.h&src/asahi/vulkan/hk_physical_device.c: derivesshaderDenormPreserveFloat32fromagx_chip_has_fp32_denorm_preserve(dev->chip), tying Vulkan exposure directly to the AGX3B/AGX3C lowering capability across native AGX3 and M5 (leaving AGX2 and G18G disabled).src/asahi/compiler/test/test-denorm-preserve-fma.cpp: adds bit-exact unit tests coveringfmin,fmax,fmin_agx,fmax_agx,clamp(fmin(fmax(x, lo), hi)), andfsatacross denormal/signed-zero/inf/NaN combinations, plus multi-stage (VS/FS/CS) compilation coverage for bothAGX3B(G15G,G16G,G17P) andAGX3C(G17S).Verification (R2 —
1b34640bb383)asahiunit suite (-Db_ndebug=false, mirrorasahiCI): PASS — run 45143319073 (241/241tests OK, including newDenormPreserveMinMax.DirectMinMaxClampAndSatandDenormPreserveLowering.CapabilityStagesAndEncodings).DEFAULT_BRANCH=aurora-wip bash .github/aurora/agent-policy.sh pr feat/borealis-m5-denorm-preserve-fp32PASS (PR is clean).G17S B1, covering denormal inputs & results across stages includingmin/nmin/max/nmax/clamp/nclamp): pending hardware lock release; will be posted on exact head1b34640bb383before merge.Assisted-by: LLM (Google:Gemini 4 Neon)