Half sqrt at 16 bits: its bound belongs to NativeTranscendentals, which it records
On a device whose float functions are not Metal's, a half sqrt is the device's instruction for Metal's function and records NativeTranscendentals (function_notes), not DeviceArithmetic. The 16-bit Sqrt's bound moves to that note's doc and its catalogue entry; the division test asserts NativeDivision and NativeTranscendentals, as the Iris Xe profile records (job 24519: [NativeTranscendentals, NativeDivision, NativeNanEncoding]).
This commit is contained in:
1 parent
502650252b
commit
ae413fd7e9
4 files changed
+12
-15
No files matched your search
@@ -1328,7 +1328,7 @@ pub fn float_fn(
|
||||
/// operand narrowed to 16 bits, exactly since it is a `half`, the instruction, and its result
|
||||
/// widened, exactly. Vulkan bounds the 16-bit `Sqrt` as it does the `float` one, inherited from
|
||||
/// `1 / InverseSqrt` (2 ulp, then the division's 2.5), here in `half` ulp, where Metal's precise
|
||||
/// `sqrt` is correctly rounded (`PrecisionNote::DeviceArithmetic`). The module computes in 16 bits
|
||||
/// `sqrt` is correctly rounded (`PrecisionNote::NativeTranscendentals`). The module computes in 16 bits
|
||||
/// ([`narrow::computes_in_16_bits`]), so its entry declares the 16-bit float controls, under which
|
||||
/// a denormal operand and result are kept and a zero's sign, an infinity and a NaN are IEEE 754's.
|
||||
fn sqrt_16(fb: &mut FunctionBuilder<'_>, f: Form, a: Value) -> BResult<Value> {
|
||||
|
||||
@@ -757,10 +757,7 @@ pub enum PrecisionNote {
|
||||
PixelSamplerScaling,
|
||||
/// Float division, remainder, square root, fused multiply-add, and dot products use Vulkan's
|
||||
/// precision bounds (e.g. 2.5 ULP division, a possibly unfused `Fma`) rather than correct
|
||||
/// rounding. A `half` square root is the device's 16-bit `Sqrt` where the module computes
|
||||
/// `half` in 16 bits under the 16-bit float controls, within Vulkan's bound for it (inherited
|
||||
/// from `1 / InverseSqrt`, 2 then 2.5 `half` ulp), and the `float` one rounded to `half`
|
||||
/// elsewhere. A fast (`arcp`) division is the device's `OpFDiv`, where Metal's is `x` times a
|
||||
/// rounding. A fast (`arcp`) division is the device's `OpFDiv`, where Metal's is `x` times a
|
||||
/// reciprocal it rounds within about 0.64 ulp but not correctly. Not recorded by precise
|
||||
/// `fmod`, whose answer is the one right value on every device, nor, on a device whose `float`
|
||||
/// functions are Metal's own (MoltenVK), in an entry Metal compiles with fast math
|
||||
@@ -1792,7 +1789,9 @@ pub enum PrecisionNote {
|
||||
/// 6 ulp precise and its fast-math table fast (MSL Tables 8.1, 8.2): `Exp2` and `Exp` 3 + 2·|x|
|
||||
/// ulp; `Log2` and `Log` 3 ulp outside `[0.5, 2]` and `2^-21` absolute inside; `Pow` inherited
|
||||
/// from `Exp2(y · Log2(x))`; `Sqrt` inherited from `1 / InverseSqrt` (`fast::sqrt`'s too, where
|
||||
/// Metal's is `x · rsqrt(x)`); `FAbs` and `FSign` the correct result, `Fract` and `Trunc`
|
||||
/// Metal's is `x · rsqrt(x)`; a `half` `sqrt` the device's 16-bit `Sqrt`, its bound in `half`
|
||||
/// ulp, where the module computes `half` in 16 bits under the 16-bit float controls, and the
|
||||
/// `float` one rounded to `half` elsewhere); `FAbs` and `FSign` the correct result, `Fract` and `Trunc`
|
||||
/// correctly rounded, `round`'s and a `half` `fmod`'s zero of either sign; `InverseSqrt` 2 ulp; `Sin` and `Cos` `2^-11` absolute in `[-π,
|
||||
/// π]` (both answers in `[-1, 1]` beyond); `Tan` inherited from `Sin / Cos`; `Asin`, `Acos`,
|
||||
/// `Atan` and `Atan2` 4096 ulp; the hyperbolic functions inherited from their `Exp` and `Log`
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
//!
|
||||
//! Under the same controls a `half` division and square root are the device's 16-bit `OpFDiv` and
|
||||
//! `Sqrt` (`lower::arith::divide`, `lower::arith::math`), recording `NativeDivision` and
|
||||
//! `DeviceArithmetic`; on lavapipe the `float` ones rounded. A second kernel divides a `half2` and
|
||||
//! `NativeTranscendentals`; on lavapipe the `float` ones rounded. A second kernel divides a `half2` and
|
||||
//! a `half`, a divisor past `2^14` and a denormal one among them (each scaled into Vulkan's range
|
||||
//! for the 16-bit quotient), and takes a square root. `llvm-as` assembles the modules; without it
|
||||
//! the tests skip visibly.
|
||||
@@ -419,7 +419,7 @@ fn half_values_are_held_at_16_bits_under_the_float_controls() {
|
||||
/// On the Iris Xe and RADV (the 16-bit float controls) a `half` division, on two lanes and on
|
||||
/// one, and a `half` square root are the device's 16-bit `OpFDiv` and `Sqrt`, none at 32 bits and
|
||||
/// no exact half narrowed, and an undefined `float` vector stays one (no widening of its 16-bit
|
||||
/// twin), recording `NativeDivision` and `DeviceArithmetic` and passing L3; a
|
||||
/// twin), recording `NativeDivision` and `NativeTranscendentals` and passing L3; a
|
||||
/// divisor past `2^14` and a denormal one are scaled into Vulkan's range exactly. On lavapipe
|
||||
/// (the conversion alone) they are the `float` instructions. Each answers the exact results on
|
||||
/// the interpreter.
|
||||
@@ -449,7 +449,7 @@ fn half_division_and_sqrt_are_16_bit_under_the_float_controls() {
|
||||
link_and_validate(&a, &p).unwrap_or_else(|e| panic!("{stem}: L3: {e}"));
|
||||
assert!(
|
||||
a.precision.contains(&PrecisionNote::NativeDivision)
|
||||
&& a.precision.contains(&PrecisionNote::DeviceArithmetic),
|
||||
&& a.precision.contains(&PrecisionNote::NativeTranscendentals),
|
||||
"{stem}: {:?}",
|
||||
a.precision
|
||||
);
|
||||
|
||||
+4
-6
@@ -3977,10 +3977,7 @@ bound.
|
||||
constexpr sampler clamped to the edge fetches its texel.
|
||||
- `metal2vulkan-degrade-device-arithmetic` (precision). `PrecisionNote::DeviceArithmetic`: Float
|
||||
division, remainder, square root, fused multiply-add, and dot products use Vulkan's precision
|
||||
bounds (e.g. 2.5 ULP division, a possibly unfused `Fma`) rather than correct rounding. A `half`
|
||||
square root is the device's 16-bit `Sqrt` where the module computes `half` in 16 bits under the
|
||||
16-bit float controls (inherited from `1 / InverseSqrt`, in `half` ulp), and the `float` one
|
||||
rounded to `half` elsewhere.
|
||||
bounds (e.g. 2.5 ULP division, a possibly unfused `Fma`) rather than correct rounding.
|
||||
- `metal2vulkan-degrade-device-signed-zero-inf-nan` (precision).
|
||||
`PrecisionNote::DeviceSignedZeroInfNan`: Float operations LLVM requires to keep signed zeros,
|
||||
infinities, and NaNs run without `SignedZeroInfNanPreserve`, which the device does not support at
|
||||
@@ -4555,8 +4552,9 @@ bound.
|
||||
Native device maths: the module computes a `float` or `half` math-library function by the device's
|
||||
own `GLSL.std.450` instruction (`exp`, `log`, `pow`, `sinh`, `cosh` and `tanh` among them; a
|
||||
composition of the device's `Exp2` and `Log2` only for `exp10` and `log10`, which no instruction
|
||||
is) where Metal's function is not the device's own; `fast::sqrt` the device's `Sqrt`; the fast
|
||||
`sin`, `cos`, `tan`, `sinh`, `cosh`, `tanh` and `atanh` the device's instructions, not MSL's
|
||||
is) where Metal's function is not the device's own; `fast::sqrt` the device's `Sqrt`, and a
|
||||
`half` `sqrt` its 16-bit `Sqrt` where the module computes `half` in 16 bits under the 16-bit
|
||||
float controls; the fast `sin`, `cos`, `tan`, `sinh`, `cosh`, `tanh` and `atanh` the device's instructions, not MSL's
|
||||
fast-math formulas (`fast::sin` of `1e7` is the device's sine, where Metal answers `+0`;
|
||||
`fast::tanh(45)` is `1`, where Metal answers NaN); `fabs`, `sign` and `fract` the device's
|
||||
`FAbs`, `FSign` and `Fract`, their special operands the instruction's (Metal's `sign` of a NaN,
|
||||
|
||||
Reference in new issue
Block a user