air.convert with a rounding suffix: parse it and lower each form
Apple's OpenCL compiler spells every convert_* it emits as an air.convert with a
rounding after the types (.rte, .rtz, .rtp, .rtn) and, to an integer, .sat after it
(convert_float4_rte(uchar4) is air.convert.f.v4f32.u.v4i8.rte, convert_int_sat(float)
is air.convert.s.i32.f.f32.rtz.sat; the forms are read from the OpenCL runtime library
the macOS 27.2 Metal toolchain ships). Convert::parse took exactly four tokens, so each
such name was an unknown intrinsic and the pipeline was refused.
- metal2vulkan-air: Convert gains `rounding: Option<ConvertRounding>` and `saturate`;
a rounding is accepted between numbers only (no bool, no 8-bit float) and .sat only
after one, to an integer. Static folding leaves the saturating and the directed forms
alone.
- Lowering (lower/arith/rounding.rs):
- float to integer: RoundEven / Ceil / Floor first (rte / rtp / rtn; rtz is the
conversion's own truncation), then the saturating conversion every air.convert to an
integer takes; the NaN test reads the operand itself. Denormal notes as rint / ceil /
floor take them.
- integer to integer: plain; .sat clamps to the range both types share (SClamp/SMax/SMin
of the sign extension, masked, or UMin; pairs on the wide path).
- integer to float and float to narrower float, nearest even: the plain conversion. Where
it can round to f32/f64 the entry declares RoundingModeRTE for the width and the widths
the device's independence ties to it (narrow::rte_modes); a device that cannot declare
them records the new PrecisionNote::NativeConversionRounding.
- toward zero or an infinity: no Vulkan conversion rounds so per instruction, so the
result is computed exactly by integer arithmetic: the magnitude's dropped bits with an
increment where the lane rounds away (f32, f64 from 64-bit, the wide path through its
sticky 32-bit fold), f32 to half on the bits (normal, overflow, subnormal, inf, NaN),
double to float by stepping the device's faithful conversion, double to half through
the round-to-odd f32. A conversion that cannot round is the plain one.
- PrecisionNote::NativeConversionRounding (native-conversion-rounding): codec, runtime
Degradation, comparison table (unbounded), fast_paths ledger class, docs/API.md.
- SEMANTICS_VERSION 2021, ARTIFACT_FORMAT_VERSION 501 (the codec gains the note);
api_signatures and the air api_surface blessed.
- Fixture kernel_convert_rounding_modes (owned MSL, air-rename to 64 suffixed intrinsics).
Unverified at this commit: build and tests follow in potluck jobs.
This commit is contained in:
1 parent
01a95a1932
commit
9f4590f124
26 files changed
+2901
-65
No files matched your search
+11
@@ -4196,6 +4196,17 @@ bound.
|
||||
`OpQuantizeToF16` alone, on every device without `shaderFloat16`, its quantize measured or not: a
|
||||
value below the smallest normal `half` may round to a zero where Metal answers the half denormal
|
||||
(or `2^-14`, from just below it). An integer's `half` rounds exactly instead.
|
||||
- `metal2vulkan-degrade-native-conversion-rounding` (precision).
|
||||
`PrecisionNote::NativeConversionRounding`: Native device maths (a conversion): an `air.convert`
|
||||
whose name rounds to nearest even (`.rte`: OpenCL's `convert_float` of an `int`, as Apple's
|
||||
OpenCL compiler spells it) and that can round (a 32- or 64-bit integer to `float`, a 64-bit
|
||||
integer to `double`, a `double` to `float`) is the device's correctly rounded conversion where
|
||||
the entry cannot declare `RoundingModeRTE` for the result's width with the widths the device's
|
||||
rounding-mode independence ties to it (MoltenVK, whose 64-bit rounding mode it does not state):
|
||||
either value around the exact one, the device's choice, where Metal answers the nearer one, ties
|
||||
to even. Where the entry declares the mode the conversion is Metal's and records nothing. The
|
||||
conversions that round toward zero or an infinity (`.rtz`, `.rtp`, `.rtn`) are exact on every
|
||||
device and record nothing.
|
||||
- `metal2vulkan-degrade-native-nan-encoding` (precision). `PrecisionNote::NativeNanEncoding`: Native
|
||||
device maths: a `float` or `half` operation's NaN result is the device's, its sign and payload
|
||||
unselected, where Metal answers a NaN the device is not measured to answer (every NaN but
|
||||
|
||||
Reference in new issue
Block a user