From 2c61e4fc52d4ee894c9eb278dba81099ba35cbb4 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 3 Dec 2026 01:45:27 -0800 Subject: [PATCH] Translator docs: NativeFma states that an unfused half product can overflow What: NativeFma's rustdoc and its docs/API.md catalogue entry state the one case its recorded bound does not cover: an unfused product can overflow where Metal's fused result is finite, and the overflow stays the device's answer. A 16-bit product of magnitude 65520 or more rounds to the infinity of its sign, so the result is that infinity where Metal's is finite, or a NaN where the addend is the infinity of the other sign and Metal's result is that infinity. Why: the bound (half an ulp of the product plus half an ulp of the result) read as covering every input; the public cases fused-multiply-add-rounding-and-fmuladd-without-fast-math and fused-multiply-add-rounding-and-contraction-under-fast-math show the other answer on lavapipe: fma(256.0h, 256.0h, -65504.0h) is inf where Metal answers 32, and fma(65504.0h, 65504.0h, -inf) a NaN where Metal answers -inf (job m3-max-82667's rows against the committed Metal rows of the Apple M3 Max). No lowering changes; the note stays unbounded in validation. Text only: no output and no recorded note changes, so SEMANTICS_VERSION stays. artifact.rs is not a runtime source input, so runtime-sources.sha256 stays. --- crates/metal2vulkan/src/pipeline/artifact.rs | 8 +++++++- docs/API.md | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index 29c585ea4..5ecee5079 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -1445,7 +1445,13 @@ pub enum PrecisionNote { /// Metal's (the product of two `half` values is exact in `float`, so only the two roundings /// differ); a `float` one, and a 16-bit one, within half a unit in the last place of the /// product plus half a unit in the last place of the result, in its own format (Vulkan lets - /// `Fma` round the product and then the sum). Validation derives no tolerance from it. + /// `Fma` round the product and then the sum). The stated exception: an unfused product can + /// overflow where Metal's fused result is finite, and the overflow is the device's answer. A + /// 16-bit product of magnitude `65520` or more rounds to the infinity of its sign, so the + /// result is that infinity where Metal's is finite, or a NaN where the addend is the infinity + /// of the other sign and Metal's result is that infinity (lavapipe: + /// `fma(256.0h, 256.0h, -65504.0h)` answers `inf` where Metal answers 32). Validation derives + /// no tolerance from it. NativeFma, /// Native device sampling (a texel conversion): the module hands a read, sample or gather /// with a `float` result the device's own conversion of the texel's codes. Recorded for every diff --git a/docs/API.md b/docs/API.md index 01b4f20d7..c2225d3d4 100644 --- a/docs/API.md +++ b/docs/API.md @@ -2373,7 +2373,11 @@ category, and says what makes an operation carry the note and what may differ. E device that computes `half` in 16 bits under the 16-bit float controls, a `half` one is the device's 16-bit `Fma` on the `half` operands. Recorded bound: a `half` result held in `float` within one `half` ulp of Metal's; a `float` one, and a 16-bit one, within half an - ulp of the product plus half an ulp of the result, in its own format. + ulp of the product plus half an ulp of the result, in its own format, but where the unfused + product overflows: an unfused `half` product can overflow where Metal's fused result is finite, + and the overflow is the device's answer (a 16-bit product of magnitude `65520` or more is the + infinity of its sign, so `fma(256.0h, 256.0h, -65504.0h)` answers `inf` on lavapipe where Metal + answers 32). - `metal2vulkan-degrade-device-texel-conversion` (precision). `PrecisionNote::DeviceTexelConversion`: Native device sampling (a texel conversion): the module hands a read, sample or gather with a `float` result the device's own conversion of the texel's