RADV fuses float arithmetic into a half conversion: the pipeline records NativeHalfConversion

On the Radeon 780M (RADV PHOENIX) runtime_lane::half_conversions failed its product kernel:
2.6822087e-7 * 1.0000001 answered half 0x0005 where Metal's half of the float product is
0x0004, with notes only [NativeNanEncoding] (radvruns job 11026, 2 of 2 runs). The module
rounds under the float controls (QuantizeForm::Controlled), which make the conversion Metal's,
so it recorded no conversion note. RADV_DEBUG=shaders on the 780M (job 11121) shows why: ACO
compiles the product's OpFMul and the narrowing, both decorated NoContraction, as one
v_fma_mixlo_f16 v2, v1, v0, neg(0), rounding the exact product to half once where Metal rounds
the float product; the sum kernel's narrowing is one v_fma_mixlo_f16 1.0, a, b too.

That is the device's own rounding (rule 1), so the fix is the note, not Metal's bits:

- DriverWorkaround::HalfConversionFusedWithArithmetic, keyed on RADV on every GPU (the others
  unmeasured), as NVIDIA's HalfConversionPairFolded is keyed on its driver.
- narrow::rounds_arithmetic: whether a module rounds to half, through a conversion pair, the
  result of an f32 OpFAdd, OpFSub, OpFMul, OpFmaKHR or GLSL Fma.
- compile_kept records PrecisionNote::NativeHalfConversion where the module takes the
  controlled conversion, the profile carries the workaround and rounds_arithmetic holds. The
  controlled form itself stays: a loaded float's conversion is exact there and records nothing.
- Tests: radv_carries_the_fused_half_conversion (every committed RADV profile carries it, no
  other does, and RADV keeps the controlled form) and
  a_controlled_rounding_of_arithmetic_is_noted_where_the_driver_fuses_it (a float sum, product
  and fused multiply-add rounded to half record the note on every RADV profile and not on ANV;
  a loaded float narrowed alone records it on neither). Both fail with compile.rs and derive.rs
  at the base.
- The note's doc, the API guide's catalogue entry, HOWTO, the narrow module doc, the lane's doc
  and the signature table name the new variant.

(cherry picked from commit 799d39233c4e0ae2a18a716e794db8f67405ff00)
This commit is contained in:
Anees Iqbal committed 2026-11-09 03:12:03 -08:00
1 parent 541c5afec6
commit 7ed49fd04d
11 files changed
+245 -13

No files matched your search

+5 -1
View File
@@ -4101,7 +4101,11 @@ bound.
`DenormPreserve` and `SignedZeroInfNanPreserve` for 16 bits: ANV and RADV round through the
conversion under them, exactly, with no note): NVIDIA, whose driver folds the conversion's round
trip even under those controls (`DriverWorkaround::HalfConversionPairFolded`), MoltenVK,
lavapipe, and any device without them. Also recorded where a `half` read from its bits is the
lavapipe, and any device without them. Also recorded under those controls on RADV where the
`half` is the result of a `float` addition, subtraction, multiply or fused multiply-add: its
compiler fuses the operation into the conversion and rounds the exact result once
(`DriverWorkaround::HalfConversionFusedWithArithmetic`), one `half` ulp from Metal's where the
`float` result lies on a `half` midpoint. Also recorded where a `half` read from its bits is the
device's widening, or a `half` encoded to its bits (where they are not the bits it was read from)
is the device's narrowing, and that conversion is neither under those controls nor measured to be
Metal's: the conversion on NVIDIA and lavapipe, and `GLSL.std.450 UnpackHalf2x16` and