Translator: a Converted half rounding's conversion pair is decorated NoContraction, as the Controlled one is
A `half` rounding in `QuantizeForm::Converted` (a profile with shaderFloat16 whose float
controls do not make the conversion Metal's) was an undecorated OpFConvert to 16 bits and
its widening. Vulkan assumes AllowTransform on every operation not decorated
NoContraction ("Precision and Operation of SPIR-V Instructions"), and Mesa's NIR folds
`~f2f32(f2f16(a))` into `a` wherever the instruction is not exact (nir_opt_algebraic.py;
vtn marks NoContraction exact), so the value went on unrounded. On KosmicKrisp (Mesa
26.3.1, Apple M3 Max) that broke half_simd_reductions: each round of the half tree kept
float precision, and 224 of 256 words differed from Metal's (job m3-max-82540, pin P's
leg). The MSL KosmicKrisp emits showed no half() between rounds; with the pair decorated,
0 words differ (job m3-max-82662).
`narrow::converted` now emits each conversion with `convert_no_contraction`, as
`narrow::controlled` does. The pair relies on Vulkan's environment rule, which reaches a
conversion, where the SPIR-V specification words NoContraction for an arithmetic
instruction only; the docs state that reliance at the Controlled pair's (narrow.rs), on
QuantizeForm::Converted, and in docs/API.md's native-half-conversion entry, and that a
driver which folds a decorated pair leaves the device's own answer, within
PrecisionNote::NativeHalfConversion, which a Converted module already records. NVIDIA's
measured fold of the decorated Controlled pair stays as recorded. SEMANTICS_VERSION 2333
-> 2334: every Converted module's words change (moltenvk-m3 is the committed profile on
that form; KosmicKrisp takes it at run time).
Evidence, all on the arms of this change before the ruling:
- KosmicKrisp conformance replay on the Apple M3 Max: 53 sites that differed from Metal
at the base now match, none added (job m3-max-82685).
- Cost: +0.46% host wall on half_mix on the M3 under KosmicKrisp, job 82685, three
alternated rounds of 200, spread 0.03%.
- Golden tables: 216 moltenvk-m3 cells change, no other profile's (job m3-max-82679).
They re-bless at the next named pin.
The red test (the commit before) asserts both forms' conversions are NoContraction;
it fails before this change and passes with it (the gate's jobs are in the READY note).
This commit is contained in:
1 parent
720753ca9d
commit
699f1167d6
4 files changed
+33
-20
No files matched your search
Vendored
+1
-1
@@ -60,7 +60,7 @@ mod tests;
|
||||
/// unchanged version, and its bless records the version. Independent of the crate's version and of
|
||||
/// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no
|
||||
/// history.
|
||||
pub const SEMANTICS_VERSION: u32 = 2333;
|
||||
pub const SEMANTICS_VERSION: u32 = 2334;
|
||||
|
||||
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
|
||||
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
//! compiler may fold the pair (NVIDIA's does, even under those controls) or fuse the operation
|
||||
//! computing the value into the narrowing, so the module records
|
||||
//! `PrecisionNote::NativeHalfConversion` on every device, a static note of the rounding. Elsewhere, where the
|
||||
//! profile has `shaderFloat16`, it is the device's conversion to 16 bits and its widening
|
||||
//! ([`QuantizeForm::Converted`]), recording `PrecisionNote::NativeHalfConversion`; without it, the
|
||||
//! profile has `shaderFloat16`, it is the device's conversion to 16 bits and its widening, each
|
||||
//! decorated `NoContraction` too ([`QuantizeForm::Converted`]), recording
|
||||
//! `PrecisionNote::NativeHalfConversion`; without it, the
|
||||
//! device's `OpQuantizeToF16` alone ([`QuantizeForm::Device`]), whose result below the smallest
|
||||
//! normal half may be a zero, recording `PrecisionNote::NativeHalfQuantize` on every such profile
|
||||
//! ([`quantizes`]); a texel's `half` takes [`round`] and keeps the NaN the device decoded
|
||||
@@ -169,14 +170,15 @@ pub fn native_rounding(form: QuantizeForm) -> Option<PrecisionNote> {
|
||||
}
|
||||
}
|
||||
|
||||
/// `x` (`f32` lanes of form `wide`) rounded to `half` by the device's conversion to 16 bits,
|
||||
/// `OpFConvert`, and widened back ([`QuantizeForm::Converted`]), recorded as
|
||||
/// `PrecisionNote::NativeHalfConversion`. The device's compiler may fold the conversion into the
|
||||
/// instruction computing `x`: Metal's compiler then rounds toward zero (`a1_half_tanh_regimes`,
|
||||
/// case 27353187: 1,204 of its 16,384 halves one ulp toward zero on MoltenVK). NVIDIA's compiler
|
||||
/// (RTX 3090) drops the pair, and so does lavapipe's where measured, so there the value is not
|
||||
/// rounded at all (the note's stated bound), and the store's conversion to bits rounds it
|
||||
/// ([`converted_bits`]).
|
||||
/// `x` (`f32` lanes of form `wide`) rounded to `half` by the device's conversion to 16 bits and
|
||||
/// its widening, each an `OpFConvert` decorated `NoContraction` as [`controlled`]'s are and for
|
||||
/// the same reason ([`QuantizeForm::Converted`]), recorded as `PrecisionNote::NativeHalfConversion`:
|
||||
/// undecorated, Mesa's compiler folds the pair and hands `x` on unrounded (KosmicKrisp on an Apple
|
||||
/// M3 Max). The device's compiler may fold the conversion into the instruction computing `x`:
|
||||
/// Metal's compiler then rounds toward zero (`a1_half_tanh_regimes`, case 27353187: 1,204 of its
|
||||
/// 16,384 halves one ulp toward zero on MoltenVK). A driver whose compiler folds the decorated pair
|
||||
/// anyway leaves the value not rounded at all (the note's stated bound), and the store's conversion
|
||||
/// to bits rounds it ([`converted_bits`]).
|
||||
fn converted(fb: &mut FunctionBuilder<'_>, wide: Form, x: Value) -> BResult<Value> {
|
||||
let e = fb.module().ty(Type::Float { width: 16 })?;
|
||||
let h = match wide.lanes {
|
||||
@@ -184,8 +186,8 @@ fn converted(fb: &mut FunctionBuilder<'_>, wide: Form, x: Value) -> BResult<Valu
|
||||
len => fb.module().ty(Type::Vector { elem: e, len })?,
|
||||
};
|
||||
let w = ty(fb, wide)?;
|
||||
let n = fb.convert(ConvOp::FConvert, x, h)?;
|
||||
fb.convert(ConvOp::FConvert, n, w)
|
||||
let n = fb.convert_no_contraction(x, h)?;
|
||||
fb.convert_no_contraction(n, w)
|
||||
}
|
||||
|
||||
/// `x` (`f32` lanes of form `wide`) rounded to `half` by the device's conversion to 16 bits and
|
||||
@@ -193,7 +195,13 @@ fn converted(fb: &mut FunctionBuilder<'_>, wide: Form, x: Value) -> BResult<Valu
|
||||
/// in an entry that declares [`controlled_modes`]: Metal's `half(float)` on every `f32` by the
|
||||
/// Vulkan spec. `NoContraction` keeps the pair: on a float operation without it Vulkan assumes
|
||||
/// `AllowTransform`, under which Mesa's compiler folds the widening of a narrowing into nothing and
|
||||
/// hands `x` on unrounded.
|
||||
/// hands `x` on unrounded. This pair and [`converted`]'s rely on Vulkan's environment rule
|
||||
/// ("Precision and Operation of SPIR-V Instructions": an operation not decorated `NoContraction` is
|
||||
/// assumed `AllowContract`, `AllowReassoc`, `AllowRecip` and `AllowTransform`), which reaches a
|
||||
/// conversion, where the SPIR-V specification words `NoContraction` for an arithmetic instruction
|
||||
/// only. A driver whose compiler folds a decorated pair (NVIDIA's folds this one) leaves the
|
||||
/// device's own answer, within `PrecisionNote::NativeHalfConversion`'s bound, which a module that
|
||||
/// rounds through either pair records.
|
||||
fn controlled(fb: &mut FunctionBuilder<'_>, wide: Form, x: Value) -> BResult<Value> {
|
||||
let e = fb.module().ty(Type::Float { width: 16 })?;
|
||||
let h = match wide.lanes {
|
||||
@@ -905,9 +913,9 @@ fn encode(fb: &mut FunctionBuilder<'_>, f: Form, x: Value) -> BResult<Value> {
|
||||
/// preserved"), where Metal moves a `half` NaN with its bits, and a denormal, which the device may
|
||||
/// flush to the zero of its sign without `DenormPreserve` for 16 bits: kept under the float
|
||||
/// controls ([`QuantizeForm::Controlled`], [`controlled_modes`]), and elsewhere within `PrecisionNote::NativeHalfConversion`'s bound; the module records
|
||||
/// `PrecisionNote::NativeNanEncoding` ([`encodes_bits`]). A value that is no `half` value (under
|
||||
/// native half rounding the device's compiler may fold [`converted`]'s pair and hand `x` on
|
||||
/// unrounded, as NVIDIA's and lavapipe's do) takes the device's rounding, within
|
||||
/// `PrecisionNote::NativeNanEncoding` ([`encodes_bits`]). A value that is no `half` value (a
|
||||
/// driver's compiler may fold a decorated pair of [`converted`]'s or [`controlled`]'s and hand `x`
|
||||
/// on unrounded, as NVIDIA's does [`controlled`]'s) takes the device's rounding, within
|
||||
/// `PrecisionNote::NativeHalfConversion`'s bound, which that module records.
|
||||
fn converted_bits(fb: &mut FunctionBuilder<'_>, f: Form, x: Value) -> BResult<Value> {
|
||||
let e = fb.module().ty(Type::Float { width: 16 })?;
|
||||
|
||||
@@ -177,8 +177,8 @@ pub enum QuantizeForm {
|
||||
/// below the smallest normal half may be a zero.
|
||||
#[default]
|
||||
Device,
|
||||
/// No quantize: `OpFConvert` to a 16-bit float and back, on a profile with `shaderFloat16`
|
||||
/// whose float controls do not make the conversion Metal's.
|
||||
/// No quantize: `OpFConvert` to a 16-bit float and back, each decorated `NoContraction`, on a
|
||||
/// profile with `shaderFloat16` whose float controls do not make the conversion Metal's.
|
||||
Converted,
|
||||
/// No quantize: `OpFConvert` to a 16-bit float and back, each decorated `NoContraction`, in
|
||||
/// an entry that declares `RoundingModeRTE`, `DenormPreserve` and `SignedZeroInfNanPreserve`
|
||||
|
||||
+6
-1
@@ -2402,7 +2402,12 @@ category, and says what makes an operation carry the note and what may differ. E
|
||||
Without the float controls that make that conversion Metal's `half(float)` (`RoundingModeRTE`,
|
||||
`DenormPreserve` and `SignedZeroInfNanPreserve` for 16 bits; on a device without 16-bit
|
||||
`DenormPreserve`, the other two, with `metal2vulkan-degrade-device-half-denormals`) the conversion
|
||||
is the device's own.
|
||||
is the device's own. The conversion and its widening are each decorated `NoContraction` with or
|
||||
without those controls: Vulkan assumes `AllowTransform` on an operation without it ("Precision
|
||||
and Operation of SPIR-V Instructions"), which reaches a conversion though the SPIR-V
|
||||
specification words `NoContraction` for an arithmetic instruction, and Mesa's compiler folds an
|
||||
undecorated pair into the value it started from. A driver that folds a decorated pair leaves the
|
||||
device's own answer, within this note.
|
||||
Under them it is Metal's by the Vulkan spec, but a driver's compiler may fold the conversion's
|
||||
round trip into the value it started from (NVIDIA's does) or fuse the `float` addition,
|
||||
subtraction, multiply or fused multiply-add computing the value into the narrowing and round its
|
||||
|
||||
Reference in new issue
Block a user