Metal FP32 arithmetic rounding-mode and denormal controls for deterministic shaders

Metal already provides a strong precise floating-point contract. With fast math disabled (mathMode = .safe and mathFloatingPointFunctions = .precise, or -fno-fast-math), the Metal Shading Language specification requires correctly rounded FP32 add, subtract, multiply, reciprocal, divide, sqrt, rsqrt, and fma.

I am looking for clarification and, if necessary, API support for the two remaining pieces needed for portable bit-exact numerical shaders:

  1. Arithmetic rounding mode

MSL §8.2 says either round-to-nearest-ties-to-even or round-toward-zero may be supported for floating-point operations. I cannot find a way to select or query the arithmetic rounding mode. The newer MTLCompileOptions.floatingPointConversionRoundingMode appears to apply only to narrowing float-to-float conversions, not arithmetic operations.

Do all currently supported Apple GPU families use round-to-nearest-ties-to-even for precise FP32 add/subtract/multiply/divide/sqrt? If so, could that be made a documented guarantee? Otherwise, could Metal expose an arithmetic rounding-mode compile option and a corresponding MTLDevice capability query?

  1. Denormal behavior

MSL §8.1 and §8.5 permit denormalized FP32 operands and results to be flushed to zero, including with fast math disabled. I cannot find a control or capability query for preserving denormal inputs and results.

Do current Apple GPU families support denormal-preserving FP32 arithmetic? Could Metal expose a preserve/flush mode and a MTLDevice query?

A convenient end state would be a queryable strict FP32 configuration combining:

  • safe math;
  • precise FP32 functions;
  • contraction disabled when separate rounding points are required;
  • round-to-nearest-ties-to-even arithmetic;
  • preserved FP32 denormal inputs and results;
  • defined signed-zero, infinity, and NaN behavior.

My use case is deterministic GPU numerical simulation. A small compute-shader probe can identify effective rounding and denormal behavior on one GPU/OS/compiler combination, but it cannot provide the portable or future-proof contract needed by applications and higher-level APIs such as WebGPU.

Related cross-API work:

Relevant Metal documentation:

Metal FP32 arithmetic rounding-mode and denormal controls for deterministic shaders
 
 
Q