Repository navigation
Add vstorea_half generic-pointer support and FP64 tests - #1752
Conversation
rjodinchr
left a comment
There was a problem hiding this comment.
Why not implement the double overloads in libclc (opencl/lib/spirv/vulkan/shared/vstore_half.cl and vstore_half.inc), just like float?
libclc already has the double rounding helpers (__clc_rtz, __clc_rti, __clc_rtn, __clc_rtp, __clc_rte) in clc/lib/generic/shared/clc_vstore.cl. Since any half-rounded value is exactly representable as a float, the double definitions in vstore_half.cl could round the double, convert it to float, and call the existing vstore_half_N(floatN, ...) / vstorea_half_N(floatN, ...) helpers. That would avoid duplicating the IEEE-754 rounding logic in getVstoreHalfValue and avoid having to register all the user-facing vstore_half* builtins in BuiltinsMap.inc and special-case them in NativeMathPass / replaceVstoreHalf.
|
Agreed, implementing the However, the existing Would you prefer that I pursue the |
|
Yes, please proceed with the upstream |
|
Sounds good, thank you for confirming the direction!❤️ I'll work on the upstream |
|
Opened the upstream libclc PR for Vulkan |
…#242829) Implement `double` overloads for `vstore_half` and `vstorea_half` under `cl_khr_fp64`. Round each element with the Vulkan boundary checks, then forward it as `float` to the existing `vstore_half_N` and `vstorea_half_N` helpers. Prerequisite for google/clspv#1752; end-to-end tests will be added there since `libclc/test` currently targets only AMDGPU. I used AI assistance to prepare and review this patch. I reviewed the entire change and take full responsibility for this PR. Assisted-by: Antigravity Gemini 4 Hydrogen Extra reasoning Assisted-by: Claude Code Opus 5.5 Max reasoning
…storea_half (#242829) Implement `double` overloads for `vstore_half` and `vstorea_half` under `cl_khr_fp64`. Round each element with the Vulkan boundary checks, then forward it as `float` to the existing `vstore_half_N` and `vstorea_half_N` helpers. Prerequisite for google/clspv#1752; end-to-end tests will be added there since `libclc/test` currently targets only AMDGPU. I used AI assistance to prepare and review this patch. I reviewed the entire change and take full responsibility for this PR. Assisted-by: Antigravity Gemini 4 Hydrogen Extra reasoning Assisted-by: Claude Code Opus 5.5 Max reasoning
…storea_half (#242829) Implement `double` overloads for `vstore_half` and `vstorea_half` under `cl_khr_fp64`. Round each element with the Vulkan boundary checks, then forward it as `float` to the existing `vstore_half_N` and `vstorea_half_N` helpers. Prerequisite for google/clspv#1752; end-to-end tests will be added there since `libclc/test` currently targets only AMDGPU. I used AI assistance to prepare and review this patch. I reviewed the entire change and take full responsibility for this PR. Assisted-by: Antigravity Gemini 4 Hydrogen Extra reasoning Assisted-by: Claude Code Opus 5.5 Max reasoning
4ca37f2 to
055adf7
Compare
|
llvm/llvm-project#242829 has been merged upstream as Keeping this as a draft until |
|
You can rebase that PR once #1756 lands |
Thanks!❤️ |
|
Sorry, I forgot to rebase first so CI ran with the old |
Part of google#321 (3/4 of the final `google#321` FP64 completion series). ## Summary Extend `Builtins::BuiltinWithGenericPointer` to recognize `vstorea_half*`, and add lit tests covering FP64 `vstore_half` / `vstorea_half` support implemented upstream in `llvm/llvm-project@9fa789fd` (rolled into `deps.json` in google#1756). ## Problem 1. `Builtins::BuiltinWithGenericPointer` matched `vstore_half*` but omitted `vstorea_half(2|3|4|8|16)`. Calls to `vstorea_half*` with a generic pointer failed to retain concrete address-space `libclc` overloads in `GetEquivalentBuiltinsWithoutGenericPointer` and skip pre-lowering in `ReplaceOpenCLBuiltinPass`. 2. `clspv` lacked lit tests exercising `double` `vstore_half` / `vstorea_half` lowering across rounding modes, vector widths, storage options, and generic pointers. ## Change - Extend `Builtins::BuiltinWithGenericPointer` in `lib/Builtins.cpp` with `vstorea_half(2|3|4|8|16)(_rte|_rtz|_rtp|_rtn)?` using `StringRef::starts_with` prefiltering (still excluding non-OpenCL scalar `vstorea_half`). - Add generic-pointer regression coverage in `test/BuiltinsWithGenericPointer/` (`vstorea_half_print.cl`, `vstore_half_double.cl`, and `vstorea_half*` negative cases in `issue-1343.cl`). - Add FP64 `vstore_half` / `vstorea_half` lit tests in `test/HalfStorage/` (`vstore_half_double.cl`, `vstore_half_double_vectors.cl`, `vstore_half8_double.cl`, and `vstore_half_double_rounding.cl`). ## Testing - Added tests covering scalar and vector widths `2`/`3`/`4`/`8` (`-no-16bit-storage=ssbo`, `-vec3-to-vec4`, `--long-vector`, `-O0`), `global`/`local`/`private`/`generic` (`CL2.0`, `CL3.0`, `CLC++`), and IEEE-754 double-rounding/edge cases (`±0`, `+Inf`, `NaN`, saturation), validated with `spirv-val`. - Rebased onto `main` (google#1756, `deps.json` at `944a108b`) and verified `lit.py --filter="(BuiltinsWithGenericPointer|HalfStorage)"` passes `70/70` tests on both `-arch=spirv32` and `-arch=spirv64` (with `libclc` `vstore_half.{cl,inc}` from `944a108b`; the initial revision also passed full `ninja check-spirv` and `ninja check-spirv-64` `3978/3978` against `llvm/llvm-project@9fa789fd`).
055adf7 to
51aabf7
Compare
Fixes google#321. Final PR (4/4) of the `google#321` FP64 completion series following google#1750, google#1751, and google#1752. ## 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, and remove the stale incomplete-FP64 note from `docs/OpenCLCOnVulkan.md`. ## Problem In SPIR-V `GLSL.std.450`, transcendental and power/logarithmic instructions (`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`. In addition, the `64-Bit Floating-Point Types` documentation still carried the note pointing to issue 321, and 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 18 16/32-bit-only `GLSL.std.450` ops above (covering `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 builtins (`sqrt`, `rsqrt`, `floor`, `ceil`, `trunc`, `rint`, `fma`, `fmin`, `fmax`, `mix`, `step`, `smoothstep`, `sign`, `ldexp`, `frexp`, `fract`, `length`, `distance`, `normalize`, `cross`, `degrees`, `radians`, etc.) untouched. - 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`, and `double_native_capable.cl`. - Remove the obsolete incomplete-FP64 note referencing issue 321 in `docs/OpenCLCOnVulkan.md`. ## Testing - Verified `double_operators.cl`, `double_native_math.cl`, `double_mixed_float.cl`, and `double_native_capable.cl` across scalar and vector `double` (`-vec3-to-vec4`, `--cl-native-math`, and `--use-native-builtins`) with `spirv-val --target-env vulkan1.0` (both `-arch=spirv32` and `-arch=spirv64`). - Rebased onto `main` (google#1752, `58067020`) and verified `lit.py --filter="(NativeBuiltins|double_operators)"` passes `193/193` tests on both `-arch=spirv32` and `-arch=spirv64` (`3,790` unrelated tests excluded; the pre-rebase revision also passed `ninja check-spirv` and `ninja check-spirv-64` with `3969/3969`, and `3982/3982` when stacked with google#1750–google#1752).
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, and remove the stale incomplete-FP64 note from `docs/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-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, the `64-Bit Floating-Point Types` documentation still carried the note pointing to issue 321, and 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`. - Remove the obsolete incomplete-FP64 note referencing issue 321 in `docs/OpenCLCOnVulkan.md`. ## 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`.
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`.
…ocs (#1753) 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 `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, and remove the stale incomplete-FP64 note from `docs/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-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, the `64-Bit Floating-Point Types` documentation still carried the note pointing to issue 321, and 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`. - Remove the obsolete incomplete-FP64 note referencing issue 321 in `docs/OpenCLCOnVulkan.md`. ## 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`.
Part of #321 (3/4 of the final
#321FP64 completion series).Summary
Extend
Builtins::BuiltinWithGenericPointerto recognizevstorea_half*, and add lit tests covering FP64vstore_half/vstorea_halfsupport implemented upstream inllvm/llvm-project@9fa789fd(rolled intodeps.jsonin #1756).Problem
Builtins::BuiltinWithGenericPointermatchedvstore_half*but omittedvstorea_half(2|3|4|8|16). Calls tovstorea_half*with a generic pointer failed to retain concrete address-spacelibclcoverloads inGetEquivalentBuiltinsWithoutGenericPointerand skip pre-lowering inReplaceOpenCLBuiltinPass.clspvlacked lit tests exercisingdoublevstore_half/vstorea_halflowering across rounding modes, vector widths, storage options, and generic pointers.Change
Builtins::BuiltinWithGenericPointerinlib/Builtins.cppwithvstorea_half(2|3|4|8|16)(_rte|_rtz|_rtp|_rtn)?usingStringRef::starts_withprefiltering (still excluding non-OpenCL scalarvstorea_half).test/BuiltinsWithGenericPointer/(vstorea_half_print.cl,vstore_half_double.cl, andvstorea_half*negative cases inissue-1343.cl).vstore_half/vstorea_halflit tests intest/HalfStorage/(vstore_half_double.cl,vstore_half_double_vectors.cl,vstore_half8_double.cl, andvstore_half_double_rounding.cl).Testing
2/3/4/8(-no-16bit-storage=ssbo,-vec3-to-vec4,--long-vector,-O0),global/local/private/generic(CL2.0,CL3.0,CLC++), and IEEE-754 double-rounding/edge cases (±0,+Inf,NaN, saturation), validated withspirv-val.main(Update LLVM #1756,deps.jsonat944a108b) and verifiedlit.py --filter="(BuiltinsWithGenericPointer|HalfStorage)"passes70/70tests on both-arch=spirv32and-arch=spirv64(withlibclcvstore_half.{cl,inc}from944a108b; the initial revision also passed fullninja check-spirvandninja check-spirv-643978/3978againstllvm/llvm-project@9fa789fd).