Repository navigation
asahi/compiler: keep unmodified scalar f16 FFMA GPR sources native on AGX3C compute - #1191
Conversation
… AGX3C compute Extend unmodified all-scalar-register F32 FFMA half-GPR preservation in agx_lower_agx3_fma_sources() from AGX3B to AGX3C (non-emit_agx3d) compute shaders. Previously single-use f16 GPR sources (such as normflt.f16 + hmul from agx_opt_agx3_normflt_byte_pairs or dense f16-source F32-accum loops) were re-widened via fmov/fadd before every FFMA even though AGX3C encodes unmodified all-scalar-register mixed-width F32 FFMA natively via agx3_falu_fma_mod_runtime(). Keeping those sources native eliminates the extra widening instructions and reduces ALU pressure and code size on compute inner loops while preserving explicit widening on non-compute stages, modified/uniform-mixed forms, and emit_agx3d devices. Update NativeForms.Agx3bFfmaKeepsUnmodifiedHalfGprNative to cover both AGX3C compute (kept native) and AGX3C vertex (widened). Signed-off-by: oreater <145754695+oreater@users.noreply.github.com>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict at 088d165da4f4: ready on the code; CI and hardware rows still owed
I found no code blocker. The new path keeps half GPR sources only in a form AGX3C already encodes today. Widening an f16 to f32 is exact, so results don't change. The gate is narrow: only the encoding and the stage decide it.
Blockers
none
Checked
-
The gate (
agx_lower_agx3_fma_sources()). The newall_scalar_regsterm needs all of these:AGX_ISA_ENCODING_AGX3C, with!g18g, whereagx_is_g18g()isAGX3C && emit_agx3d, so it is the PR's "non-emit_agx3d";- a compute stage;
- a scalar 32-bit destination that isn't memory;
- every source a scalar NORMAL or REGISTER operand, so no immediates, uniforms, memory or vectors;
- no
abs/negon any source (native_scalar_half_gpr = all_scalar_regs && !src_modifier).
Saturating FFMAs return earlier (
I->saturate) and don't reach this test. AGX2 returns at the top, and AGX3B and G18G behave as before. -
Encoding. On AGX3C,
agx3c_native_half_gpralready keeps halves read by two or more FFMAs. So an FFMA with an f32 destination and half GPR operands in any slot is already emitted there, and packed byagx3_falu_fma_mod_runtime()with per-operand width bits (agx3_pack_binary.c).- The new path extends that to single-use values, and to precoloured
AGX_INDEX_REGISTERhalves, which become the same 16-bit register operand after register allocation. - The packer refuses a combination it can't encode (it returns -1) and doesn't mis-encode it.
- The new path extends that to single-use values, and to precoloured
-
Precision. The widening move it drops is an exact f16-to-f32 conversion, and the AGX3C operand slot widens exactly too (the comment in the pass says so). The single rounding of the FFMA is unchanged, and the bit-exact hashes in Tested agree.
-
Stage split. Graphics stages keep the old single-use widening, with its stated reason (an FFMA on a half register being slower). That's a measured heuristic, not a correctness rule. The compute side is supported by the J716c ABBA numbers.
-
Build and tests, in a separate shallow clone (aarch64 host, debugoptimized,
-Dvulkan-drivers=asahi -Dbuild-tests=true):- it builds, with no warnings on the changed lines; the 4
-Wdangling-elsewarnings intest-native-form-regressions.cpp(6342, 8280) come from other commits; meson test --suite asahi: 212/212 OK;--suite poly: 5/5 OK;NativeForms.Agx3bFfmaKeepsUnmodifiedHalfGprNativepasses.- Each of two mutations fails the test:
- dropping the compute-stage condition fails
agx3c_vertex_src0_widened; - removing the AGX3C clause fails
agx3c_compute_src0_native.
- dropping the compute-stage condition fails
- it builds, with no warnings on the changed lines; the 4
-
Small test gap (not blocking). The precoloured-register case exists only for AGX3B (
agx3b_src0_precoloured). An AGX3C compute precoloured case, and one with a modifier (e.g.agx3c_compute_neg_widened), would pin the new path's other two conditions. -
Merge and text. It merges cleanly with the current
aurora-wip(8ac326f31d4f). The commit is signed off and carries no attribution.
Owed before merge
- CI. No checks are reported on this head yet.
- Hardware rows. Only J716c (G17C) is listed. The change covers every AGX3C part, so a G17S (J714s) row, which Not yet already names, and ideally a G17G row are owed. Each should repeat the CTS groups (
precision_fp16_storage16b.fma,compute.float16,compute.16bit_storage,compute.8bit_storage) and the bit-exact compute set.
Evidence
head 088d165da4f4958c73a9a1d8d41693e725b7fee6, base 41fe336dffae, merge-tree clean with aurora-wip 8ac326f31d4f
agx_compile.h:560 agx_is_g18g(dev) = encoding == AGX3C && emit_agx3d
agx_compile.c all_scalar_regs = (AGX3B || (AGX3C && !g18g && compute)) && 1 dest, !memory, 32-bit, 1 channel
+ every src NORMAL/REGISTER, !memory, 1 channel; native only if no src abs/neg
existing: agx3c_native_half_gpr keeps halves with ffma_reads >= 2 (same FFMA form)
agx3_pack_binary.c AGX3B/AGX3C FFMA -> agx3_falu_fma_mod_runtime(enc, d, s0, s1, addend, &m{src*_16, addend_16}, ...)
meson test --suite asahi -> Ok: 212, Fail: 0
meson test --suite poly -> Ok: 5, Fail: 0
mutation: no compute-stage condition -> agx3c_vertex_src0_widened FAILED
mutation: no AGX3C clause -> agx3c_compute_src0_native FAILED
CI checks on this head: none reported
|
J714s (MacBook Pro 14" M5 Pro, G17S B1) row at Setup:
1. Vulkan CTS (
2. gpubench-vk
3. Kernel log for the slot: 0 GPU faults, 0 WARN and 0 error lines. The GPU was online with 0 crashed and 0 quarantined owners before and after. |
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 088d165da4f4
Blockers: none
Checked: Read the diff. Keeping unmodified all-scalar-register f16 FFMA sources native on AGX3C compute uses the encoding AGX3B already emits and agx3_falu_fma_mod_runtime packs; widening f16 to f32 is exact, so results do not change. Gated on encoding and stage only. M5-only; J716c and Dj's J714s rows are on the PR at this head. Gate green.
Evidence
Local Mesa gate (stands in for CI; buildbox x86 docker aurora/hk6356-mesa-x86-tests:local, clang release with asserts, -Dbuild-tests=true -Dtools=asahi,drm-shim, meson test --suite asahi --suite poly):
- base
aurora-wip90211df6816: 335/335 OK. - batch build:
90211df6816with 22 open PR heads merged on top (#1133 #1137 #1155 #1136 #1140 #1157 #1158 #1160 #1164 #1165 #1167 #1168 #1170 #1171 #1172 #1175 #1182 #1183 #1185 #1187 #1190 #1191; each also merges cleanly alone, and into currentaurora-wipd2e883ab2e3): 335/336 OK. The one failure,agx3_cmat_mixed_mma8, reproduces with #1187 alone on the base (329/330) and is caused by that PR's new test; nothing else in the batch fails.
What: Keep unmodified all-scalar-register F32
FFMAhalf-GPR sources native inagx_lower_agx3_fma_sources()on AGX3C (non-emit_agx3d) compute shaders, matching AGX3B and eliminating redundantf16->f32widening moves onnormflt.f16byte-unpack and single-use f16-source compute loops.Tested: J716c Apple M5 Max at 088d165: 334/334
asahi+polydebug CI tests pass (incl. updatedNativeForms.Agx3bFfmaKeepsUnmodifiedHalfGprNativecovering AGX3C compute vs vertex); 3-round ABBA vs41fe336dffawins-19.2%(1.24x) on serial single-use f16->f32 FFMA,-12.7%(1.15x) on 8-wide dense f16->f32 FFMA (-31ALU instrs,-3GPRs), and-8.3%(1.09x) on 15-tap u8 byte-unpack blur (-56ALU instrs,-302 B), all bit-exact; Vulkan CTSprecision_fp16_storage16b.fma+float16+16bit/8bit_storageA/B 135/154 pass (0 fail, 0 status diffs).Risk: two-way door · M5 Macs (AGX3C non-
emit_agx3d) — scoped strictly to unmodified all-scalar-register F32FFMAin compute shaders onAGX_ISA_ENCODING_AGX3C && !emit_agx3d; AGX3C graphics stages, modified/uniform-mixed forms, AGX2, AGX3B, and G18G (emit_agx3d) are unchanged.Not yet: Not yet hardware-tested on M5 Pro/Base variants beyond J716c Apple M5 Max.
Benchmarks, shaderdb stats, and CTS details
3-round ABBA vs
41fe336dffa(J716c Apple M5 Max, G17C B1,MESA_SHADER_CACHE_DISABLE=1)serial_f16_fma(single-chain f16->f32 FFMA)dense_f16_fma(8-wide f16->f32 FFMA loop)u8_blur_15tap(u8 byte-unpack + dynamic weight)meson test --suite asahi --suite poly334/334 PASS, 0 FAIL.deqp-vk,precision_fp16_storage16b.fma,compute.float16,compute.16bit_storage,compute.8bit_storage): 135/154 PASS, 19 NotSupported, 0 FAIL, 0 status diffs vs41fe336dffa.