Repository navigation
agx: keep half register FFMA operands that several FFMAs read on AGX3C - #386
Conversation
|
Thanks for this, the register savings in multi-row f16 GEMVs are a nice result and the tests are thorough. One request on how it is selected. We select behaviour by a hardware property, not by the chip it was measured on. The reason given is an ISA property (the FFMA reads a half register in its own typed operand slot, which the AGX3C packer already encodes), but the gate is a single chip:
If G17G and G17S use the same AGX3C encoding, could this key on the encoding (or an ISA feature flag) so they take it too? If they lack that operand form or measure slower, please note that hardware reason in the comment instead. If you make it encoding-wide we would welcome rows from M5 owners; on our side we can confirm no change on our A18 Pro, M4 Pro, M1 Pro and M2. |
Merge train: independent review (code only, Opus 5.5 xhigh)Verdict: CLEAN WITH NITS. No blocker or major. NIT: a modifier on a 32-bit uniform operand does not stop the half value from being kept, which costs two extra instructions in that case (the result stays exact). Reach: gated on |
167d7e0 to
9cd2277
Compare
|
Note 🤖 Claude Opus 5.5 responding on behalf of erikwb Thanks to you both. Changes in this revision:
Precompiled libagx kernels: I built aurora-wip and this change and compared the generated kernel arrays in Shader statistics, aurora-wip vs this change (host compiles under the noop drm-shim). These are tracked compile statistics (instructions, registers, threads, spills, fills, scratch, code size) for the shaders that compiled on both trees. They don't measure game performance, and "no change" doesn't mean the binaries are byte-identical:
On the M5 Max (G17C), the CTS subset in the description matches aurora-wip case for case. There's no G17G or G17S hardware here, so an M5 or M5 Pro row would be the useful one. A18 Pro, M4 Pro, M1 Pro and M2 should show no change. |
|
No blockers. Re-read 9cd2277 against the reviewed 167d7e0.
Assisted-by: LLM (Claude:Opus 5.5) |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Review of 9cd22776dc824a8cc6a9e20e194e82e424094910
0 code/policy/attribution blockers. Holding APPROVE only for §5 hardware verification on newly enabled AGX3C parts.
Checklist summary
- §1 No model gating: Pass.
agx_lower_agx3_fma_sources()(src/asahi/compiler/agx_compile.c:5226) gates onencoding == AGX_ISA_ENCODING_AGX3C && !g18g, whereg18gisagx_is_g18g(&ctx->key->dev)(emit_agx3d). No chip IDs remain, and both exclusions (AGX3BandG18G/emit_agx3d) are documented in code comments and the commit message as lacking bit-exact hardware validation for plain half-register FFMA operands on those paths. - §2 Hygiene & §3 Correctness: Pass.
- Reader counting (
agx_compile.c:5224-5244) handles OOM safely (falls back to widening everything), deduplicates repeated uses of the same SSA value within a single FFMA, and guardsI->src[s].value < nr_valuesagainst temps created during the pass. full_modifier(agx_compile.c:5285-5288) covers both 32-bit GPRs and 32-bit uniforms so modified all-F32 FFMAs do not turn into mixed-width FFMAs requiring extra bitop modifier materialization.- Second legalization pass (
agx_compile.c:13092) re-counts readers so a single remaining plain reader after a modified reader was widened gets widened too. - Unit tests (
test-signed-zero-fma.cpp+test-agx3-pack-binary.cpp) thoroughly cover G17G/G17S/G17C, G17P, G18G, all 7 half masks, 16/32-bit destinations, repeated slots, modified full GPR/uniform operands, double legalization, and post-RA binary packing.
- Reader counting (
- §4 Attribution & clean-room: Pass. Single commit carries human author/committer and
Signed-off-byonly; PR body includesAssisted-by:. - §6 Naming: Pass. Compiler-only (
agx), no Honeykrisp/hk_naming issues. - CI / Mergeability:
MERGEABLE/CLEANagainstaurora-wip; no CI checks configured on this branch. Hostmeson test --suite asahi(166/166) andagx_tests(1222 pass, 1 skip) pass on9cd22776, and precompiledlibagxarrays are identical across all 8 targets.
Remaining items (§5 evidence)
- Newly enabled AGX3C hardware (
G17GM5 /G17SM5 Pro): at least one hardware run covering the fp16/FMA CTS subset (matchingaurora-wipcase-for-case) with regression checks (0 SELinux/AVC denials, 0 failed units, 0 new kernel errors). - Rebased-head regression row on
9cd22776: the G17C CTS run (9,763 cases, 51 compiling differently, 0 diffs) was run on identical code prior to rebase (7ba29572); please include the regression row (0 AVC / 0 failed units / 0 new kernel errors) on the rebased head when running hardware checks. (AGX2, AGX3B, and G18G codegen andlibagxare unchanged.)
Assisted-by: LLM (Gemini 4 Neon)
|
A18 Pro (
Post-RA shader verification (
Exhaustive exactness probe (
FP16 Vulkan CTS subset (
Note for any follow-up widening to Assisted-by: LLM (Antigravity:Gemini 4 Neon) |
agx_lower_agx3_fma_sources() widens plain half register operands of an AGX3C FFMA with a move to a full register. The AGX3C FFMA reads a half register in its own typed operand slot and widens it exactly, for either destination size, and the AGX3C packer already encodes those operands (as it does for the modified half operands this pass keeps). Keep a half value in its half register when two or more FFMAs read it: its widened copy would otherwise hold a full register across all of them. A value that one FFMA reads stays widened. That move issues off the FFMA's dependency chain, and in a dependent FFMA chain measured on G17C, reading a half register was about 4% slower than reading full registers, so the single-use form is faster widened. A plain half register is not kept in an FFMA whose 32-bit register or uniform operand carries abs/neg, so that FFMA keeps the all-F32 form instead of becoming a mixed-width one. This applies to the AGX3C encoding (G17G, G17S, G17C). AGX3B keeps its own unmodified F32 scalar-register path (unaffected by the multi-reader count here). G18G, which compiles as AGX3C and re-encodes as agx3d, keeps its existing half legalization, as the mixed-half form has no exact-result validation on the re-encoded path. On G17C, lily's multi-row f16 GEMVs keep their half weights in place: glm53_gemv_f16_m2-m8 and qg_gemv_f16_m2-m4 drop 27-31 instructions and 32-40 registers, and most reach 1024 threads. Signed-off-by: Erik Bourget <erik@ebourget.net>
9cd2277 to
f65ddb8
Compare
|
Note 🤖 Gemini 4 Neon responding on behalf of erikwb Rebased cleanly onto
|
|
Verified on Apple M5 Pro (
Ready to merge from |
|
Merged into Verification summary on
Assisted-by: LLM (Google:Gemini 4 Neon) |
agx_lower_agx3_fma_sources()widens each plain half register operand of anAGX3C FFMA with a move to a full register (
fadd x, -0.0). The AGX3C FFMAreads a half register in its own typed operand slot and widens it exactly,
for either destination size. The AGX3C packer already encodes such operands,
as it does for the modified half operands this pass leaves alone.
Widening still pays for a value that only one FFMA reads: the move issues off
the FFMA's dependency chain, and in a dependent FFMA chain measured on G17C,
an FFMA that reads a half register is slower than one on full registers
(below). For a value that several FFMAs
read, though, the widened copy holds a full register across all of them. In
multi-row f16 GEMVs, where each half weight feeds one FFMA per row, those
copies set the kernels' register count.
Change
On the AGX3C encoding (G17G, G17S, G17C), a plain half register operand of
an FFMA is kept when two or more FFMAs read its value. An FFMA taking it in
several slots counts once. A value that one FFMA reads is widened as before.
A plain half register is also widened when a 32-bit register or uniform
operand of the same FFMA carries abs/neg: that FFMA keeps the all-F32 form
rather than becoming a mixed-width FFMA. The existing exceptions are
unchanged: half operands with abs/neg are still kept, and so is a single
half uniform beside a full register in a scalar 32-bit FFMA.
Not changed:
aurora-wip(
d7a02f6dc20), unaffected by the multi-reader AGX3C count here.legalization, as the mixed-half form has no exact-result validation on the
re-encoded path.
Testing
Compiler, on
aurora-wip1fdf5396758fat headf65ddb868dcc, in an x86_64build with assertions (
-Doptimization=2 -Db_ndebug=false -Dbuild-tests=true,Gallium and Vulkan
asahidrivers):meson test --suite asahipasses 158 of158 (0 fail).
agx_testspasses 1,233, with 1 skipped(
NativeFMA.ExactDyadicOracle, which skips without itsAGX_FMA_RTE_CASESinput, on
aurora-wiptoo).SignedZeroFMA.AGX3CKeepsHalfRegisterOperandscovers every placement ofhalf operands, 32- and 16-bit destinations, and FFMAs with or without
abs/neg on a full register operand. On G17G, G17S and G17C, half values
that two FFMAs read stay and no instruction is added. A value that one
FFMA reads (alone, or also read by an FADD) is widened, as is every half
next to a full register modifier. On G17P (AGX3B), unmodified F32
scalar-register FFMAs keep their landed path while 16-bit-destination and
modified forms widen.
SignedZeroFMA.AGX3CModifiedUniformWidensHalves(G17C): with abs/neg on a 32-bituniform addend, the half operands are widened, the modifier stays on the
FFMA, and no bitop is added. A third, plain reader keeps the half.
SignedZeroFMA.G18GKeepsItsHalfWidening: on G18G, a 32-bit FFMA's halfoperands are widened even when two FFMAs read them. A 16-bit FFMA is left
as it is.
AGX3PackBinary.AGX3CMixedFMAHalfRegistersPackAfterRA, on G17G, G17S andG17C, covers two FFMAs reading the same operands, in every mixed shape at
both destination sizes. It also covers abs/neg on one half operand next to
a plain one, and a 16- or 32-bit uniform addend (which
agx_lower_uniform_sourcescopies to a register when a half registeroperand remains). The half register operands and their modifiers stay,
registers are allocated, and they pack as the two FFMAs. No widening move
reads a half register operand.
SignedZeroFMA.AGX3CCountsEachFFMAOnce(G17C): one FFMA taking the samehalf value in two or three slots widens it, and two such FFMAs keep it.
SignedZeroFMA.AGX3CHalfOperandsAfterTwoLegalizations(G17C) runs legalizationtwice, as the compiler does, with one reader whose full register operand is
negated. With one other reader, that reader is widened too. With two other
readers, they keep the half register beside the widened copy.
Shader statistics (instructions, registers, threads, spills, fills, scratch,
code size), aurora-wip 7ba2957 vs this change on it (before the rebase,
with the same AGX3C logic), compiled on the host under the noop drm-shim for each
chip. "No change" means none of these statistics changed for the shaders
that compiled on both. They are compile statistics, not game performance:
every target, g17g and g18g included (checked on aurora-wip fa9a676).
G17G, 14 are smaller and none is larger (G17C: 390,008 -> 389,661
instructions, 13 use fewer registers, 12 gain occupancy). No change on
G18G, G17P or G16G (41 kernels compile there) or on G13G or G14G (25).
change, 30 smaller and 9 larger, 716,277 -> 716,157 instructions in total.
The largest increase is one heavily spilling shader: +37 instructions and
+5 fills. On G17G the same 47 change, 30 smaller and 5 larger. No change on
G17P, or on G18G, where 347 of the 617 compile.
On an M5 Max (G17C), with this change on aurora-wip 7ba2957 (the same AGX3C
code before the rebase) and with aurora-wip 7ba2957 as the base, VK-GL-CTS
7ba03cd (2026-11-01). The cases come from the main mustpass. Every case has
the same result on both:
glsl.builtin.precision_fp16_storage*,glsl.builtin.function.*,glsl.operator.bitwise*and shift operators,spirv_assembly.instruction.compute.opfma,float16,float_controls*,8bit_storage,16bit_storage,convert*compute.pipeline.cooperative_matrix.*, 1500 evenly spacedNo failures, crashes or GPU faults on either. In a run with compiler
statistics, 51 of the cases in the first set compile differently from
aurora-wip (27
glsl.builtin.precision_fp16_storage*, 24spirv_assemblyfloat16), and all of them pass on both.Earlier, on the M5 Max with the G17C form of this change, on aurora-wip
b4f154f plus the open M5 changes of that day:
Operand probes, each form with its own inputs, every half encoding
(denormals, infinities, NaNs) among the half operands, and f32 operands of
exponents -15 to 16. The outputs are bit-identical to those of the tree
without this commit:
f32 operands, 7,340,032 results. f32 results were checked against a
correctly rounded fused multiply-add on the CPU, and half results of
float16_t(fma(...))against that fused multiply-add narrowed to half:0 differ.
change), the same comparisons over the single-read forms: 2,359,296 f32
results, 2,097,152 half results over all eight placements, and 2,097,152
FMAs of three halves (with abs/neg, a half literal, a saturated result)
against the exact result rounded once to half: 0 differ.
A chain of dependent FMAs at full occupancy with a half multiplicand, on
G17C, takes 104 µs with the multiplicand widened once before the loop and
108 µs with it as a half register operand. With an f32 multiplicand, it
takes 104 µs on both trees. This measures that dependent chain only, not
the issue rate of independent FFMAs or the other AGX3C parts.
Kernel time, K = N = 4096, 400 dispatches, two rounds per tree (µs):
glm53_gemv_f16_m1glm53_gemv_f16_m4glm53_gemv_f16_m5glm53_gemv_f16_m6glm53_gemv_f16_m7glm53_gemv_f16_m8qg_gemv_f16_m4End to end (lily, the same build of each model's benchmark, rounds
alternating between the trees): no change beyond run-to-run noise, with
identical output digests.
Still to run
f65ddb868dcc(no G17G or G17S hardware available locally).f65ddb868dccvs1fdf5396758f.Assisted-by: LLM (Claude:Opus 5.5, Google:Gemini 4 Neon)