Issue Summary:
We identified a clear behavioral discrepancy in CUDA’s unary negation operator (operator-) defined in cuda_fp16.h. For the exact same QNaN payload input (0x7f557e01), the output bit pattern diverges drastically depending on whether the value is passed as a dynamic kernel argument (arg) or defined as a kernel const:
-
Path A: Dynamic Argument (
-arg)-
Output Bit Pattern:
0x7fff7fff -
Analysis: The QNaN payload is canonicalized and lost (
0x7e01and0x7f55are replaced by0x7fff).
-
-
Path B: In-kernel Constant (
-const)-
Output Bit Pattern:
0xff55fe01 -
Analysis: The original NaN payload is preserved, and only the sign bit is flipped (
0x7e01$\rightarrow$0xfe01,0x7f55$\rightarrow$0xff55).
-
This divergence violates the compiler invariant where $f(arg)$ must equal $f(const)$ for identical input binary representation.
Compiler Explorer: Compiler Explorer
Questions for NVIDIA:
-
Why does dynamic argument evaluation canonicalize NaN payloads to
0x7fff7fff, whileconstevaluation preserves the payload by only flipping the sign bit (0xff55fe01)? -
Which output pattern is the intended IEEE-754 / CUDA specification for
cuda_fp16.h’soperator-(__half2)?