Hello,
We observed different floating-point results for NoContraction-decorated operations once a SPIR-V
module declares the FloatControls2 capability. We put together a small, standalone reproduction
with synthetic data and would appreciate it if someone could take a look.
What the shader does. A compute shader, and a vertex shader captured with transform feedback,
evaluate w = a3*b3 + ((a0*b0 + a1*b1) + a2*b2) on vec4. All seven multiplies and adds are
decorated NoContraction, so the expected result is the separately rounded binary32 sequence.
The only difference between the passing and failing variants:
OpCapability Shader
+ OpCapability FloatControls2
+ OpExtension "SPV_KHR_float_controls2"
OpMemoryModel Logical GLSL450
The failing variant (V1) has no FPFastMathMode decoration and no FPFastMathDefault execution
mode. All modules pass spirv-val --target-env vulkan1.3.
Observed results. Each figure is the number of lanes, out of 4608, matching the separately
rounded result (SEP) or a fused multiply-add model (FMA3):
| GPU | Driver | V0 (NoContraction) | V1 (+ FloatControls2 declared) | V2 (explicit FPFastMathMode 0x7 + FPFastMathDefault 0x7000F) | V3 (FPFastMathMode None, no default) |
|---|---|---|---|---|---|
| GeForce RTX 5080 | 621.14 | 4608 SEP | compute: 1060 SEP / 2824 FMA3 / 47 FMA2 / 677 other; xfb: 4608 FMA3 | 4608 SEP | same as V1 |
| GeForce RTX 3090 | 610.88 | 4608 SEP | 4608 FMA3 (compute and xfb) | 4608 SEP | 4608 FMA3 |
| AMD Radeon™ Graphics | 24.30.18 | 4608 SEP | 4608 SEP | 4608 SEP | 4608 SEP |
Specification references.
- SPIR-V
NoContraction(decoration 42): the operation “cannot be combined with another
instruction to form a single operation”, for example a multiply cannot be combined with an
addition into a fused multiply-add. SPV_KHR_float_controls2deprecatesNoContractionbut does not remove it. Without
FPFastMathModeorFPFastMathDefault, the client API defaults apply.- The Vulkan SPIR-V environment does not assume
AllowContractfor operations decorated
NoContraction.
Based on this, we expected V1 and V3 to produce the same results as V0.
Workaround we use. We use the explicit float-controls-2 form (V2), or omit the
FloatControls2 declaration when the module does not need it.
Repro. GitHub - 5andr0/nv-fc2-nocontraction-repro · GitHub
It contains the SPIR-V assembly and precompiled modules, and a Python script (pip install -r requirements.txt,
then python repro.py; no compiler needed) that tests every Vulkan device in the system and checks each result
against a CPU reference model. An equivalent C++ host is included as an alternative.
Thank you for taking a look.
NVIDIA would do everyone a favor if most of their stack was open source. I hope the new CEO will push open source more.
This could be a PR ready to be implemented, but nah - now I have to wait a year until it gets fixed by NVIDIA