Contributors
-
Ben Ashbaugh, Intel
-
Dmitry Sidorov, Intel
-
Dounia Khaldi, Intel
-
Eyal Radiano, Intel
-
Greg Lueck, Intel
-
Joe Garvey, Intel
-
John Lu, Intel
-
Mateusz Garbowski, Intel
-
Pawel Jurek, Intel
-
Victor Mustya, Intel
-
Viktoria Maksimova, Intel
Dependencies
This extension is written against the SPIR-V Specification, Version 1.6 Revision 8.
This extension requires SPIR-V 1.0.
Overview
This extension adds instructions to convert floating-point values with stochastic rounding, and to convert floating-point values and clamp the result to the nearest representable integer value. Stochastic rounding replaces deterministic rounding behavior with a stochastic (probabilistic) rounding behavior. Stochastic rounding is important for certain numerical algorithms, particularly those relying on small floating-point types.
Modifications to the SPIR-V Specification, Version 1.6
Capabilities
Modify Section 3.2.30, Capability, adding rows to the Capability table:
| Capability | Implicitly Declares | |
|---|---|---|
6215 |
FloatConversionsFToFINTEL |
|
6216 |
FloatConversionsFToSINTEL |
|
Instructions
3.3.11. Conversion Instructions
Convert an input value numerically from one floating point width to another using stochastic rounding. For finite input values, stochastic rounding is performed by adding a pseudo-random bias value to the mantissa of the input value. If this causes the mantissa to overflow, then the exponent of the input value is increased by one and the mantissa bits are shifted right. The value is then converted to the Result Type, rounding towards zero. If the input value is infinity, or if the exponent overflows when converting to Result Type, the result is determined as follows: if the result is decorated with SaturatedToLargestFloat8NormalConversionEXT or Result Type has no representation for both NaN and infinity, the result is the nearest representable value of Result Type; otherwise, if Result Type has a representation for infinity, the result is infinity with a matching sign; otherwise, the result is NaN. If either the input value or the result is NaN, and Result Type has no representation for NaN, then the result is an unspecified stable value. The pseudo-random bias values are generated with an implementation-defined algorithm using Seed as a starting point. The algorithm is guaranteed to produce repeatable bias values when the same value is passed for Seed. The instruction may optionally return a new seed value in Next Seed. When multiple stochastic rounding conversions will be performed by the same invocation, the value returned in Next Seed should be passed as Seed for the next stochastic rounding to generate good quality bias values. Result Type is the type of the converted value and must be a scalar or vector of floating-point type. Value must be a scalar or vector of floating-point type. It must have a wider range than the Result Type and it must have the same number of components as Result Type. Seed must be a 32-bit scalar integer type. Next Seed must be a pointer to a 32-bit scalar integer type in the Function storage class. Results are computed per component. |
Capability: |
|||||
5+ |
6217 |
<id> |
Result <id> |
<id> |
<id> |
Optional <id> |
Converts an input value numerically from floating point to signed integer using stochastic rounding. Has the same semantics as OpStochasticRoundFToFINTEL. If the input value is infinity or overflows, the result is saturated to the nearest representable value of Result Type. If the input value is NaN, the result is an unspecified stable value. Result Type is the type of the converted value and must be a scalar or vector of integer type. Value must be a scalar or vector of floating-point type. It must have a wider range than the Result Type and it must have the same number of components as Result Type. Seed must be a 32-bit scalar integer type. Next Seed must be a pointer to a 32-bit scalar integer type in the Function storage class. Results are computed per component. |
Capability: |
|||||
5+ |
6219 |
<id> |
Result <id> |
<id> |
<id> |
Optional <id> |
Converts an input value numerically from floating point to signed integer by rounding to the nearest even. If the input value is infinity or overflows, the result is saturated to the nearest representable value of Result Type. If the input value is NaN, the result is an unspecified stable value. Result Type must be a scalar or vector of integer type. Value must be a scalar or vector of floating-point type. It must have the same number of components as Result Type. Results are computed per component. |
Capability: |
|||
4 |
6424 |
<id> |
Result <id> |
<id> |
Validation Rules
Add the following bullets to section 2.16.11, Universal Validation Rules:
-
It is valid to use the SaturatedToLargestFloat8NormalConversionEXT decoration with OpStochasticRoundFToFINTEL when the Result Type is Float8E4M3EXT or Float8E5M2EXT.
-
It is not valid to apply the FPRoundingMode decoration to the OpStochasticRoundFToFINTEL, OpClampStochasticRoundFToSINTEL, or OpClampConvertFToSINTEL instructions.
-
It is not valid to apply the SaturatedConversion decoration to the OpClampStochasticRoundFToSINTEL or OpClampConvertFToSINTEL instructions.
Client API Environment
This section describes supported conversions for types and instructions added by the SPV_INTEL_fp_conversions, SPV_EXT_float8, SPV_INTEL_int4, and SPV_EXT_ocp_microscaling_types extensions when supported by Intel Level-Zero and OpenCL platforms.
The following conversions are supported for OpFConvert:
-
For conversions to the fp8 types Float8E4M3EXT and Float8E5M2EXT, the SaturatedToLargestFloat8NormalConversionEXT decoration is supported and controls whether the conversion is saturated.
-
For conversions to the fp4 type Float4E2M1EXT, the conversion is always saturated to the nearest representable value, with NaN converting to an unspecified stable value.
-
For conversions to the BFloat16KHR type, the RTE (round to nearest even) rounding mode is supported and is the default rounding mode.
-
For conversions to the fp8 types Float8E4M3EXT and Float8E5M2EXT, the RTE (round to nearest even) rounding mode is supported and is the default rounding mode.
-
For conversions to the fp4 type Float4E2M1EXT, the RTE (round to nearest even) rounding mode is supported and is the default rounding mode.
OpFConvert: |
To: |
|||||||
64-bit IEEE754 |
32-bit IEEE754 |
16-bit IEEE754 |
BFloat16KHR |
Float8E4M3EXT |
Float8E5M2EXT |
Float4E2M1EXT |
||
From: |
64-bit IEEE754 |
- |
Yes |
Yes |
||||
32-bit IEEE754 |
Yes |
- |
Yes |
Yes |
||||
16-bit IEEE754 |
Yes |
Yes |
- |
Yes |
Yes |
Yes |
||
BFloat16KHR |
Yes |
- |
Yes |
Yes |
Yes |
|||
Float8E4M3EXT |
Yes |
Yes |
- |
|||||
Float8E5M2EXT |
Yes |
Yes |
- |
|||||
Float4E2M1EXT |
Yes |
Yes |
Yes |
Yes |
- |
|||
The following conversions are supported for OpStochasticRoundFToFINTEL:
-
For conversions to the fp8 types Float8E4M3EXT and Float8E5M2EXT, the SaturatedToLargestFloat8NormalConversionEXT decoration is supported and controls whether the conversion is saturated.
OpStochasticRoundFToFINTEL: |
To: |
|||||||
64-bit IEEE754 |
32-bit IEEE754 |
16-bit IEEE754 |
BFloat16KHR |
Float8E4M3EXT |
Float8E5M2EXT |
Float4E2M1EXT |
||
From: |
64-bit IEEE754 |
- |
||||||
32-bit IEEE754 |
- |
Yes |
||||||
16-bit IEEE754 |
- |
Yes |
Yes |
Yes |
||||
BFloat16KHR |
- |
Yes |
Yes |
Yes |
||||
Float8E4M3EXT |
- |
|||||||
Float8E5M2EXT |
- |
|||||||
Float4E2M1EXT |
- |
|||||||
The following conversions are supported for OpConvertFToS, OpClampStochasticRoundFToSINTEL, and OpClampConvertFToSINTEL:
-
For OpConvertFToS conversions to a 4-bit Integer type, the RTE (round to nearest even) rounding mode is supported.
OpConvertFToS, |
To: |
|
4-bit Integer |
||
From: |
64-bit IEEE754 |
|
32-bit IEEE754 |
||
16-bit IEEE754 |
Yes |
|
BFloat16KHR |
Yes |
|
Float8E4M3EXT |
||
Float8E5M2EXT |
||
Float4E2M1EXT |
||
The following conversions are supported for OpConvertSToF:
-
For OpConvertSToF conversions from a 4-bit Integer type, the default rounding mode is supported. Because all of the supported conversions are exact, there is no rounding.
OpConvertSToF: |
To: |
|||||||
64-bit IEEE754 |
32-bit IEEE754 |
16-bit IEEE754 |
BFloat16KHR |
Float8E4M3EXT |
Float8E5M2EXT |
Float4E2M1EXT |
||
From: |
4-bit Integer |
Yes |
Yes |
Yes |
Yes |
|||
Issues
-
Why do we need OpClampConvertFToSINTEL? Can we just reuse OpConvertFToS with the SaturatedConversion decoration?
RESOLVED: Although it would be nice to reuse OpConvertFToS, OpClampConvertFToSINTEL has two key differences that warrant an additional instruction instead:
-
The only supported rounding mode for OpClampConvertFToSINTEL is implicitly RTE (round to nearest even). This is different than the default rounding mode for other float-to-int conversions, which is RTZ (round toward zero).
-
For NaN inputs, OpClampConvertFToSINTEL produces an unspecified stable value rather than converting to zero. Note that the current implementation produces either the smallest or largest representable value depending on the most significant bit of the (NaN) input.
-
-
Should it be valid to include the SaturatedConversion decoration on OpClampStochasticRoundFToSINTEL or OpClampConvertFToSINTEL?
RESOLVED: Due to the differing NaN behavior, it would be confusing to allow the SaturatedConversion decoration on OpClampStochasticRoundFToSINTEL or OpClampConvertFToSINTEL, therefore this is not valid.