Repository navigation
Guard unsupported FP64 native math builtins and finalize FP64 tests/docs - #1753
Conversation
|
This is looking good, but as the doc part removes the fp64 incomplete, I'll wait for #1752 to land first. |
|
Could you rebase it on top-of-tree? I want to make sure that we have everything here, so the CI feedback is relevant. |
|
Got it, I'll get right on it! |
0b4f79e to
e3fa5d6
Compare
rjodinchr
left a comment
There was a problem hiding this comment.
Thanks for rebasing! Could you change Fixes #321 to Ref #321 (in both the commit message and PR description)? A few pre-existing FP64 issues remain that I'll document on #321 for follow-up PRs, so we shouldn't close the issue yet.
Other than that, this PR is good to land once the comments below are resolved.
| // FP64-DAG: [[fp64_v4double:%[^ ]+]] = OpTypeVector [[fp64_double]] 4 | ||
| // FP64-NOT: OpExtInst [[fp64_double]] {{.*}} {{(Acos|Acosh|Asin|Asinh|Atan|Atanh|Atan2|Sin|Sinh|Cos|Cosh|Tan|Tanh|Exp|Exp2|Log|Log2|Pow)($| )}} | ||
| // FP64-NOT: OpExtInst [[fp64_v4double]] {{.*}} {{(Acos|Acosh|Asin|Asinh|Atan|Atanh|Atan2|Sin|Sinh|Cos|Cosh|Tan|Tanh|Exp|Exp2|Log|Log2|Pow)($| )}} | ||
| // FP64-NOT: OpExtInst %v{{[23]}}double {{.*}} {{(Acos|Acosh|Asin|Asinh|Atan|Atanh|Atan2|Sin|Sinh|Cos|Cosh|Tan|Tanh|Exp|Exp2|Log|Log2|Pow)($| )}} |
There was a problem hiding this comment.
Could we capture [[fp64_v3double:%[^ ]+]] = OpTypeVector [[fp64_double]] 3 in FP64-DAG (just like fp64_v4double) instead of hardcoding %v{{[23]}}double? (test_mixed only uses double3, and capturing the ID avoids relying on spirv-dis friendly names.)
There was a problem hiding this comment.
Fixed in 6e904434. I've captured fp64_v3double under FP64-V3 for the --use-native-builtins run since --cl-native-math lowers double3 to %v4double.
|
|
||
| bool is_unsupported_fp64_glsl_op(clspv::glsl::ExtInst Op) { | ||
| switch (Op) { | ||
| case clspv::glsl::ExtInst::ExtInstAcos: |
There was a problem hiding this comment.
bool is_unsupported_fp64_glsl_op(clspv::glsl::ExtInst Op) {
switch (Op) {
- case clspv::glsl::ExtInst::ExtInstRadians:
- case clspv::glsl::ExtInst::ExtInstDegrees:
case clspv::glsl::ExtInst::ExtInstAcos:
There was a problem hiding this comment.
Fixed in 6e904434. I've added ExtInstRadians and ExtInstDegrees as suggested.
e3fa5d6 to
6e90443
Compare
|
Thanks for the review. I've updated the commit message and PR description to use |
rjodinchr
left a comment
There was a problem hiding this comment.
Sorry, one last small thing I missed in the previous pass: since we're keeping #321 open for the remaining FP64 builtin fixes, could you revert the docs/OpenCLCOnVulkan.md change here so we drop that note in the PR that closes #321? Everything else looks great and ready to merge once that's updated.
Ref google#321. Series follow-up PR (4/4) for google#321 following google#1750, google#1751, and google#1752 (remaining pre-existing FP64 edge cases are tracked in google#321). ## Summary Keep `libclc` software implementations for FP64 math builtins that lack 64-bit `GLSL.std.450` support in Vulkan SPIR-V under `--cl-native-math` / `--use-native-builtins`, add dedicated `double` operator tests. ## Problem In SPIR-V `GLSL.std.450`, angle-conversion, transcendental, and power/logarithmic instructions (`Radians`, `Degrees`, `Acos`, `Acosh`, `Asin`, `Asinh`, `Atan`, `Atanh`, `Atan2`, `Sin`, `Sinh`, `Cos`, `Cosh`, `Tan`, `Tanh`, `Exp`, `Exp2`, `Log`, `Log2`, `Pow`) only support 16-bit and 32-bit floats. Under `--cl-native-math` or `--use-native-builtins`, `NativeMathPass` deleted the `libclc` bodies of `double` math builtins regardless of type, either emitting invalid 64-bit `GLSL.std.450` instructions (`spirv-val` failure) or lowering via `ReplaceOpenCLBuiltinPass` into unlowered `llvm.sincos` (`sincos`, `tanpi`), which also broke transitive `libclc` callers such as `erf`, `erfc`, `lgamma`, `lgamma_r`, `tgamma`, and `rootn` (and relied on downstream `ReplaceOpenCLBuiltinPass::replaceDegreesOrRadians` for FP64 `degrees` / `radians`). In addition, there was no standalone `double` operator lit test. ## Change - In `lib/NativeMathPass.cpp`, add `is_unsupported_fp64_glsl_op` and `keep_fp64_libclc_body` to retain `libclc` bodies (`!F.isDeclaration() && F.getReturnType()->getScalarType()->isDoubleTy()`) for: - builtins mapping via `Builtins::getExtInstEnum` to the 20 16/32-bit-only `GLSL.std.450` ops above (covering `radians`, `degrees`, `sin..powr`, and `acospi..atan2pi`), and - `ReplaceableBuiltins` math lowerings that expand to them (`exp10`, `expm1`, `log10`, `log1p`, `pown`, `cospi`, `sinpi`, `tanpi`, `sincos`). - Guard both body deletion (`have_native_impl`) and the `--use-native-builtins` unsupported-builtin error with `!keep_libclc_body`, leaving `float` native math and 64-bit native-capable GLSL/IR builtins (`sqrt`, `rsqrt`, `floor`, `ceil`, `trunc`, `rint`, `fma`, `fmin`, `fmax`, `mix`, `step`, `smoothstep`, `sign`, `ldexp`, `frexp`, `fract`, `length`, `distance`, `normalize`, `cross`, etc.) untouched (while FP64 `degrees` / `radians` lower to `FMul` via `libclc` / `ReplaceOpenCLBuiltinPass`). - Add `test/double_operators.cl` covering scalar and vector `double` arithmetic, negation, comparisons, and ternary selection (default and `-vec3-to-vec4`). - Add `test/NativeBuiltins/MathBuiltins/double_native_math.cl`, `double_mixed_float.cl` (capturing `fp64_double`, `fp64_v3double` where `OpTypeVector <double> 3` is emitted, and `fp64_v4double`), and `double_native_capable.cl`. ## Testing - Verified `lit.py --filter="(NativeBuiltins|double_operators|double_degrees_radians)"` passes `195/195` tests on both `-arch=spirv32` and `-arch=spirv64` (`3,788` unrelated tests excluded), including `--cl-native-math`, `--use-native-builtins`, and `-vec3-to-vec4` with `spirv-val --target-env vulkan1.0`.
6e90443 to
7319846
Compare
Thanks for catching that. I've reverted the docs/OpenCLCOnVulkan.md change. |
Fixes google#321. Follow-up to google#1753 resolving the items in google#321 (comment). ## Summary Fix FP64 generic-pointer `sincos`, `replaceCopysign` sign masks, and `replaceFract` clamping constant, and remove the stale google#321 note from `docs/OpenCLCOnVulkan.md`. ## Problem - `skipBuiltinsWithGenericPointer` returned `false` whenever `--use-native-builtins` contained the builtin, lowering generic-pointer FP64 `sincos` to `llvm.sin.f64` / `llvm.cos.f64` (`undefined reference to 'llvm.sincos.f64'`) instead of rewriting to the `libclc` implementation kept by `NativeMathPass`. - `ReplaceLLVMIntrinsicsPass::replaceCopysign` shifted a 32-bit `1` by `63` for `double`, producing wrong 64-bit sign masks and corrupting `copysign(double)` and `round(double)`. - `ReplaceOpenCLBuiltinPass::replaceFract` shifted a 32-bit `1` by `53` for `double`, evaluating `kJustUnderOneScalar` to `~2.33e-10` instead of `0x1.fffffffffffffp-1`. - `docs/OpenCLCOnVulkan.md` still contained the incomplete-FP64 note referencing issue 321. ## Change - Keep skipping FP64 `sincos` in `skipBuiltinsWithGenericPointer` (`lib/ReplaceOpenCLBuiltinPass.cpp`) under `--use-native-builtins=sincos`. - Use `APInt::getSignMask` and its complement in `ReplaceLLVMIntrinsicsPass::replaceCopysign` (`lib/ReplaceLLVMIntrinsicsPass.cpp`). - Use `1ULL << num_significand_bits` and `-static_cast<int>(num_significand_bits)` in `ReplaceOpenCLBuiltinPass::replaceFract` (`lib/ReplaceOpenCLBuiltinPass.cpp`). - Add FP64 tests (`sincos_double_native.cl`, `copysign_double{,4}.cl`, `double_round.cl`, `double_fract_private.cl`). - Remove the issue 321 note from `docs/OpenCLCOnVulkan.md`. ## Testing - Full `lit.py` suite passed `3988/3988` on both `-arch=spirv32` and `-arch=spirv64`. - `clang-format --dry-run --Werror lib/ReplaceOpenCLBuiltinPass.cpp lib/ReplaceLLVMIntrinsicsPass.cpp` passed.
Fixes google#321. Follow-up to google#1753 resolving the items in google#321 (comment). ## Summary Fix FP64 generic-pointer `sincos`, `replaceCopysign` sign masks, and `replaceFract` clamping constant, and remove the stale google#321 note from `docs/OpenCLCOnVulkan.md`. ## Problem - `skipBuiltinsWithGenericPointer` returned `false` whenever `--use-native-builtins` contained the builtin, lowering generic-pointer FP64 `sincos` to `llvm.sin.f64` / `llvm.cos.f64` (`undefined reference to 'llvm.sincos.f64'`) instead of rewriting to the `libclc` implementation kept by `NativeMathPass`. - `ReplaceLLVMIntrinsicsPass::replaceCopysign` shifted a 32-bit `1` by `63` for `double`, producing wrong 64-bit sign masks and corrupting `copysign(double)` and `round(double)`. - `ReplaceOpenCLBuiltinPass::replaceFract` shifted a 32-bit `1` by `53` for `double`, evaluating `kJustUnderOneScalar` to `~2.33e-10` instead of `0x1.fffffffffffffp-1`. - `docs/OpenCLCOnVulkan.md` still contained the incomplete-FP64 note referencing issue 321. ## Change - Remove the `UseNativeBuiltins` check and `builtin` parameter from `skipBuiltinsWithGenericPointer` (`lib/ReplaceOpenCLBuiltinPass.cpp`) so `NativeMathPass` governs all generic-pointer builtins uniformly. - Use `APInt::getSignMask` and its complement in `ReplaceLLVMIntrinsicsPass::replaceCopysign` (`lib/ReplaceLLVMIntrinsicsPass.cpp`). - Use `1ULL << num_significand_bits` and `-static_cast<int>(num_significand_bits)` in `ReplaceOpenCLBuiltinPass::replaceFract` (`lib/ReplaceOpenCLBuiltinPass.cpp`). - Add FP64 tests (`sincos_double_native.cl`, `copysign_double{,4}.cl`, `double_round.cl`, `double_fract_private.cl`). - Remove the issue 321 note from `docs/OpenCLCOnVulkan.md`. ## Testing - Targeted `lit.py` run covering `BuiltinsWithGenericPointer`, `AddressSpaceCast`, `NativeBuiltins`, `HalfStorage`, `PhysicalStorageBuffers`, and `MathBuiltins/{copysign,fract,round,sincos}` passed `329/329` on both `-arch=spirv32` and `-arch=spirv64` (earlier full `lit.py` run before removing the `UseNativeBuiltins` early return passed `3988/3988` on both). - `clang-format --dry-run --Werror lib/ReplaceOpenCLBuiltinPass.cpp lib/ReplaceLLVMIntrinsicsPass.cpp` passed.
Fixes #321. Follow-up to #1753 resolving the items in #321 (comment). ## Summary Fix FP64 generic-pointer `sincos`, `replaceCopysign` sign masks, and `replaceFract` clamping constant, and remove the stale #321 note from `docs/OpenCLCOnVulkan.md`. ## Problem - `skipBuiltinsWithGenericPointer` returned `false` whenever `--use-native-builtins` contained the builtin, lowering generic-pointer FP64 `sincos` to `llvm.sin.f64` / `llvm.cos.f64` (`undefined reference to 'llvm.sincos.f64'`) instead of rewriting to the `libclc` implementation kept by `NativeMathPass`. - `ReplaceLLVMIntrinsicsPass::replaceCopysign` shifted a 32-bit `1` by `63` for `double`, producing wrong 64-bit sign masks and corrupting `copysign(double)` and `round(double)`. - `ReplaceOpenCLBuiltinPass::replaceFract` shifted a 32-bit `1` by `53` for `double`, evaluating `kJustUnderOneScalar` to `~2.33e-10` instead of `0x1.fffffffffffffp-1`. - `docs/OpenCLCOnVulkan.md` still contained the incomplete-FP64 note referencing issue 321. ## Change - Remove the `UseNativeBuiltins` check and `builtin` parameter from `skipBuiltinsWithGenericPointer` (`lib/ReplaceOpenCLBuiltinPass.cpp`) so `NativeMathPass` governs all generic-pointer builtins uniformly. - Use `APInt::getSignMask` and its complement in `ReplaceLLVMIntrinsicsPass::replaceCopysign` (`lib/ReplaceLLVMIntrinsicsPass.cpp`). - Use `1ULL << num_significand_bits` and `-static_cast<int>(num_significand_bits)` in `ReplaceOpenCLBuiltinPass::replaceFract` (`lib/ReplaceOpenCLBuiltinPass.cpp`). - Add FP64 tests (`sincos_double_native.cl`, `copysign_double{,4}.cl`, `double_round.cl`, `double_fract_private.cl`). - Remove the issue 321 note from `docs/OpenCLCOnVulkan.md`. ## Testing - Targeted `lit.py` run covering `BuiltinsWithGenericPointer`, `AddressSpaceCast`, `NativeBuiltins`, `HalfStorage`, `PhysicalStorageBuffers`, and `MathBuiltins/{copysign,fract,round,sincos}` passed `329/329` on both `-arch=spirv32` and `-arch=spirv64` (earlier full `lit.py` run before removing the `UseNativeBuiltins` early return passed `3988/3988` on both). - `clang-format --dry-run --Werror lib/ReplaceOpenCLBuiltinPass.cpp lib/ReplaceLLVMIntrinsicsPass.cpp` passed.
Ref #321.
Series follow-up PR (4/4) for #321 following #1750, #1751, and #1752 (remaining pre-existing FP64 edge cases are tracked in #321).
Summary
Keep
libclcsoftware implementations for FP64 math builtins that lack 64-bitGLSL.std.450support in Vulkan SPIR-V under--cl-native-math/--use-native-builtins, add dedicateddoubleoperator tests, and remove the stale incomplete-FP64 note fromdocs/OpenCLCOnVulkan.md.Problem
In SPIR-V
GLSL.std.450, angle-conversion, transcendental, and power/logarithmic instructions (Radians,Degrees,Acos,Acosh,Asin,Asinh,Atan,Atanh,Atan2,Sin,Sinh,Cos,Cosh,Tan,Tanh,Exp,Exp2,Log,Log2,Pow) only support 16-bit and 32-bit floats. Under--cl-native-mathor--use-native-builtins,NativeMathPassdeleted thelibclcbodies ofdoublemath builtins regardless of type, either emitting invalid 64-bitGLSL.std.450instructions (spirv-valfailure) or lowering viaReplaceOpenCLBuiltinPassinto unloweredllvm.sincos(sincos,tanpi), which also broke transitivelibclccallers such aserf,erfc,lgamma,lgamma_r,tgamma, androotn(and relied on downstreamReplaceOpenCLBuiltinPass::replaceDegreesOrRadiansfor FP64degrees/radians). In addition, the64-Bit Floating-Point Typesdocumentation still carried the note pointing to issue 321, and there was no standalonedoubleoperator lit test.Change
lib/NativeMathPass.cpp, addis_unsupported_fp64_glsl_opandkeep_fp64_libclc_bodyto retainlibclcbodies (!F.isDeclaration() && F.getReturnType()->getScalarType()->isDoubleTy()) for:Builtins::getExtInstEnumto the 20 16/32-bit-onlyGLSL.std.450ops above (coveringradians,degrees,sin..powr, andacospi..atan2pi), andReplaceableBuiltinsmath lowerings that expand to them (exp10,expm1,log10,log1p,pown,cospi,sinpi,tanpi,sincos).have_native_impl) and the--use-native-builtinsunsupported-builtin error with!keep_libclc_body, leavingfloatnative math and 64-bit native-capable GLSL/IR builtins (sqrt,rsqrt,floor,ceil,trunc,rint,fma,fmin,fmax,mix,step,smoothstep,sign,ldexp,frexp,fract,length,distance,normalize,cross, etc.) untouched (while FP64degrees/radianslower toFMulvialibclc/ReplaceOpenCLBuiltinPass).test/double_operators.clcovering scalar and vectordoublearithmetic, negation, comparisons, and ternary selection (default and-vec3-to-vec4).test/NativeBuiltins/MathBuiltins/double_native_math.cl,double_mixed_float.cl(capturingfp64_double,fp64_v3doublewhereOpTypeVector <double> 3is emitted, andfp64_v4double), anddouble_native_capable.cl.docs/OpenCLCOnVulkan.md.Testing
lit.py --filter="(NativeBuiltins|double_operators|double_degrees_radians)"passes195/195tests on both-arch=spirv32and-arch=spirv64(3,788unrelated tests excluded), including--cl-native-math,--use-native-builtins, and-vec3-to-vec4withspirv-val --target-env vulkan1.0.