-
Notifications
You must be signed in to change notification settings - Fork 823
[SYCL] Split spirv_ops.hpp into category headers #21849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| //==------- spirv_ops_atomic.hpp --- SPIRV atomic operations --------------==// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <sycl/__spirv/spirv_ops_builtin_decls.hpp> | ||
|
|
||
| #include <type_traits> | ||
|
|
||
| #ifdef __SYCL_DEVICE_ONLY__ | ||
|
|
||
| // Atomic SPIR-V builtins | ||
| // TODO: drop these forward-declarations. | ||
| // As of now, compiler does not forward-declare long long overloads for | ||
| // these and as such we can't drop anything from here. But ideally, we should | ||
| // rely on the compiler to generate those - that would allow to drop | ||
| // spirv_ops.hpp include from more files. | ||
| #define __SPIRV_ATOMIC_LOAD(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicLoad(AS Type *P, int S, \ | ||
| int O) noexcept; | ||
| #define __SPIRV_ATOMIC_STORE(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL void __spirv_AtomicStore( \ | ||
| AS Type *P, int S, int O, Type V) noexcept; | ||
| #define __SPIRV_ATOMIC_EXCHANGE(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicExchange( \ | ||
| AS Type *P, int S, int O, Type V) noexcept; | ||
| #define __SPIRV_ATOMIC_CMP_EXCHANGE(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicCompareExchange( \ | ||
| AS Type *P, int S, int E, int U, Type V, Type C) noexcept; | ||
| #define __SPIRV_ATOMIC_IADD(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicIAdd( \ | ||
| AS Type *P, int S, int O, Type V) noexcept; | ||
| #define __SPIRV_ATOMIC_ISUB(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicISub( \ | ||
| AS Type *P, int S, int O, Type V) noexcept; | ||
| #define __SPIRV_ATOMIC_FADD(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicFAddEXT( \ | ||
| AS Type *P, int S, int O, Type V) noexcept; | ||
| #define __SPIRV_ATOMIC_SMIN(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicSMin( \ | ||
| AS Type *P, int S, int O, Type V) noexcept; | ||
| #define __SPIRV_ATOMIC_UMIN(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicUMin( \ | ||
| AS Type *P, int S, int O, Type V) noexcept; | ||
| #define __SPIRV_ATOMIC_FMIN(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicFMinEXT( \ | ||
| AS Type *P, int S, int O, Type V) noexcept; | ||
| #define __SPIRV_ATOMIC_SMAX(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicSMax( \ | ||
| AS Type *P, int S, int O, Type V) noexcept; | ||
| #define __SPIRV_ATOMIC_UMAX(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicUMax( \ | ||
| AS Type *P, int S, int O, Type V) noexcept; | ||
| #define __SPIRV_ATOMIC_FMAX(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicFMaxEXT( \ | ||
| AS Type *P, int S, int O, Type V) noexcept; | ||
| #define __SPIRV_ATOMIC_AND(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicAnd(AS Type *P, int S, \ | ||
| int O, Type V) noexcept; | ||
| #define __SPIRV_ATOMIC_OR(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicOr(AS Type *P, int S, int O, \ | ||
| Type V) noexcept; | ||
| #define __SPIRV_ATOMIC_XOR(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicXor(AS Type *P, int S, \ | ||
| int O, Type V) noexcept; | ||
|
|
||
| #define __SPIRV_ATOMIC_FLOAT(AS, Type) \ | ||
| __SPIRV_ATOMIC_FADD(AS, Type) \ | ||
| __SPIRV_ATOMIC_FMIN(AS, Type) \ | ||
| __SPIRV_ATOMIC_FMAX(AS, Type) \ | ||
| __SPIRV_ATOMIC_LOAD(AS, Type) \ | ||
| __SPIRV_ATOMIC_STORE(AS, Type) \ | ||
| __SPIRV_ATOMIC_EXCHANGE(AS, Type) | ||
|
|
||
| #define __SPIRV_ATOMIC_BASE(AS, Type) \ | ||
| __SPIRV_ATOMIC_FLOAT(AS, Type) \ | ||
| __SPIRV_ATOMIC_CMP_EXCHANGE(AS, Type) \ | ||
| __SPIRV_ATOMIC_IADD(AS, Type) \ | ||
| __SPIRV_ATOMIC_ISUB(AS, Type) \ | ||
| __SPIRV_ATOMIC_AND(AS, Type) \ | ||
| __SPIRV_ATOMIC_OR(AS, Type) \ | ||
| __SPIRV_ATOMIC_XOR(AS, Type) | ||
|
|
||
| #define __SPIRV_ATOMIC_SIGNED(AS, Type) \ | ||
| __SPIRV_ATOMIC_BASE(AS, Type) \ | ||
| __SPIRV_ATOMIC_SMIN(AS, Type) \ | ||
| __SPIRV_ATOMIC_SMAX(AS, Type) | ||
|
|
||
| #define __SPIRV_ATOMIC_UNSIGNED(AS, Type) \ | ||
| __SPIRV_ATOMIC_BASE(AS, Type) \ | ||
| __SPIRV_ATOMIC_UMIN(AS, Type) \ | ||
| __SPIRV_ATOMIC_UMAX(AS, Type) | ||
|
|
||
| // Helper atomic operations which select correct signed/unsigned version | ||
| // of atomic min/max based on the type | ||
| #define __SPIRV_ATOMIC_MINMAX(AS, Op) \ | ||
| template <typename T> \ | ||
| typename std::enable_if_t< \ | ||
| std::is_integral<T>::value && std::is_signed<T>::value, T> \ | ||
| __spirv_Atomic##Op(AS T *Ptr, int Memory, int Semantics, T Value) noexcept { \ | ||
| return __spirv_AtomicS##Op(Ptr, Memory, Semantics, Value); \ | ||
| } \ | ||
| template <typename T> \ | ||
| typename std::enable_if_t< \ | ||
| std::is_integral<T>::value && !std::is_signed<T>::value, T> \ | ||
| __spirv_Atomic##Op(AS T *Ptr, int Memory, int Semantics, T Value) noexcept { \ | ||
| return __spirv_AtomicU##Op(Ptr, Memory, Semantics, Value); \ | ||
| } \ | ||
| template <typename T> \ | ||
| typename std::enable_if_t<std::is_floating_point<T>::value, T> \ | ||
| __spirv_Atomic##Op(AS T *Ptr, int Memory, int Semantics, T Value) noexcept { \ | ||
| return __spirv_AtomicF##Op##EXT(Ptr, Memory, Semantics, Value); \ | ||
| } | ||
|
|
||
| #define __SPIRV_ATOMICS(macro, Arg) \ | ||
| macro(__attribute__((opencl_global)), Arg) \ | ||
| macro(__attribute__((opencl_local)), Arg) macro(, Arg) | ||
|
|
||
| __SPIRV_ATOMICS(__SPIRV_ATOMIC_FLOAT, _Float16) | ||
| __SPIRV_ATOMICS(__SPIRV_ATOMIC_FLOAT, float) | ||
| __SPIRV_ATOMICS(__SPIRV_ATOMIC_FLOAT, double) | ||
| __SPIRV_ATOMICS(__SPIRV_ATOMIC_SIGNED, int) | ||
| __SPIRV_ATOMICS(__SPIRV_ATOMIC_SIGNED, long) | ||
| __SPIRV_ATOMICS(__SPIRV_ATOMIC_SIGNED, long long) | ||
| __SPIRV_ATOMICS(__SPIRV_ATOMIC_UNSIGNED, unsigned int) | ||
| __SPIRV_ATOMICS(__SPIRV_ATOMIC_UNSIGNED, unsigned long) | ||
| __SPIRV_ATOMICS(__SPIRV_ATOMIC_UNSIGNED, unsigned long long) | ||
| __SPIRV_ATOMICS(__SPIRV_ATOMIC_MINMAX, Min) | ||
| __SPIRV_ATOMICS(__SPIRV_ATOMIC_MINMAX, Max) | ||
|
|
||
| #undef __SPIRV_ATOMICS | ||
| #undef __SPIRV_ATOMIC_AND | ||
| #undef __SPIRV_ATOMIC_BASE | ||
| #undef __SPIRV_ATOMIC_CMP_EXCHANGE | ||
| #undef __SPIRV_ATOMIC_EXCHANGE | ||
| #undef __SPIRV_ATOMIC_FADD | ||
| #undef __SPIRV_ATOMIC_FLOAT | ||
| #undef __SPIRV_ATOMIC_FMAX | ||
| #undef __SPIRV_ATOMIC_FMIN | ||
| #undef __SPIRV_ATOMIC_IADD | ||
| #undef __SPIRV_ATOMIC_ISUB | ||
| #undef __SPIRV_ATOMIC_LOAD | ||
| #undef __SPIRV_ATOMIC_MINMAX | ||
| #undef __SPIRV_ATOMIC_OR | ||
| #undef __SPIRV_ATOMIC_SIGNED | ||
| #undef __SPIRV_ATOMIC_SMAX | ||
| #undef __SPIRV_ATOMIC_SMIN | ||
| #undef __SPIRV_ATOMIC_STORE | ||
| #undef __SPIRV_ATOMIC_UMAX | ||
| #undef __SPIRV_ATOMIC_UMIN | ||
| #undef __SPIRV_ATOMIC_UNSIGNED | ||
| #undef __SPIRV_ATOMIC_XOR | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //==-------- spirv_ops_base.hpp --- SPIRV operation common support --------==// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <sycl/__spirv/spirv_types.hpp> // for Scope, __ocl_event_t | ||
| #include <sycl/detail/defines_elementary.hpp> // for __DPCPP_SYCL_EXTERNAL | ||
| #include <sycl/detail/export.hpp> // for __SYCL_EXPORT | ||
|
|
||
| // Convergent attribute | ||
| #ifdef __SYCL_DEVICE_ONLY__ | ||
| #define __SYCL_CONVERGENT__ __attribute__((convergent)) | ||
| #else | ||
| #define __SYCL_CONVERGENT__ | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| //==--- spirv_ops_builtin_decls.hpp --- SPIRV built-in declaration guard --==// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <sycl/__spirv/spirv_ops_base.hpp> | ||
|
|
||
| #ifdef __SYCL_DEVICE_ONLY__ | ||
| #ifndef __SPIRV_BUILTIN_DECLARATIONS__ | ||
| #error \ | ||
| "SPIR-V built-ins are not available. Please set -fdeclare-spirv-builtins flag." | ||
| #endif | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| //==-------- spirv_ops_image.hpp --- SPIRV image operations ---------------==// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <sycl/__spirv/spirv_ops_builtin_decls.hpp> | ||
|
|
||
| #ifdef __SYCL_DEVICE_ONLY__ | ||
|
|
||
| template <typename RetT, typename ImageT> | ||
| extern __DPCPP_SYCL_EXTERNAL RetT __spirv_ImageQueryFormat(ImageT); | ||
|
|
||
| template <typename RetT, typename ImageT> | ||
| extern __DPCPP_SYCL_EXTERNAL RetT __spirv_ImageQueryOrder(ImageT); | ||
|
|
||
| template <typename RetT, typename ImageT> | ||
| extern __DPCPP_SYCL_EXTERNAL RetT __spirv_ImageQuerySize(ImageT); | ||
|
|
||
| template <typename ImageT, typename CoordT, typename ValT> | ||
| extern __DPCPP_SYCL_EXTERNAL void __spirv_ImageWrite(ImageT, CoordT, ValT); | ||
|
|
||
| template <class RetT, typename ImageT, typename TempArgT> | ||
| extern __DPCPP_SYCL_EXTERNAL RetT __spirv_ImageRead(ImageT, TempArgT); | ||
|
|
||
| template <class RetT, typename ImageT, typename TempArgT> | ||
| extern __DPCPP_SYCL_EXTERNAL RetT __spirv_ImageFetch(ImageT, TempArgT); | ||
|
|
||
| template <class RetT, typename ImageT, typename TempArgT> | ||
| extern __DPCPP_SYCL_EXTERNAL RetT __spirv_SampledImageFetch(ImageT, TempArgT); | ||
|
|
||
| template <class RetT, typename ImageT, typename TempArgT> | ||
| extern __DPCPP_SYCL_EXTERNAL RetT __spirv_ImageArrayFetch(ImageT, TempArgT, | ||
| int); | ||
|
|
||
| template <class RetT, typename ImageT, typename TempArgT> | ||
| extern __DPCPP_SYCL_EXTERNAL RetT __spirv_SampledImageArrayFetch(ImageT, | ||
| TempArgT, int); | ||
|
|
||
| template <class RetT, typename ImageT, typename TempArgT> | ||
| extern __DPCPP_SYCL_EXTERNAL RetT __spirv_SampledImageGather(ImageT, TempArgT, | ||
| unsigned); | ||
|
|
||
| template <class RetT, typename ImageT, typename TempArgT> | ||
| extern __DPCPP_SYCL_EXTERNAL RetT __spirv_ImageArrayRead(ImageT, TempArgT, int); | ||
|
|
||
| template <typename ImageT, typename CoordT, typename ValT> | ||
| extern __DPCPP_SYCL_EXTERNAL void __spirv_ImageArrayWrite(ImageT, CoordT, int, | ||
| ValT); | ||
|
|
||
| template <typename ImageT, typename SampledType> | ||
| extern __DPCPP_SYCL_EXTERNAL SampledType __spirv_SampledImage(ImageT, | ||
| __ocl_sampler_t); | ||
|
|
||
| template <typename SampledType, typename TempRetT, typename TempArgT> | ||
| extern __DPCPP_SYCL_EXTERNAL TempRetT | ||
| __spirv_ImageSampleExplicitLod(SampledType, TempArgT, int, float); | ||
|
|
||
| template <typename SampledType, typename TempRetT, typename TempArgT> | ||
| extern __DPCPP_SYCL_EXTERNAL TempRetT | ||
| __spirv_ImageSampleExplicitLod(SampledType, TempArgT, int, TempArgT, TempArgT); | ||
|
|
||
| template <typename SampledType, typename TempRetT, typename TempArgT> | ||
| extern __DPCPP_SYCL_EXTERNAL TempRetT __spirv_ImageSampleCubemap(SampledType, | ||
| TempArgT); | ||
|
|
||
| template <typename RetT, class HandleT> | ||
| extern __DPCPP_SYCL_EXTERNAL RetT __spirv_ConvertHandleToImageINTEL(HandleT); | ||
|
|
||
| template <typename RetT, class HandleT> | ||
| extern __DPCPP_SYCL_EXTERNAL RetT __spirv_ConvertHandleToSamplerINTEL(HandleT); | ||
|
|
||
| template <typename RetT, class HandleT> | ||
| extern __DPCPP_SYCL_EXTERNAL | ||
| RetT __spirv_ConvertHandleToSampledImageINTEL(HandleT); | ||
|
|
||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
long long? I expect https://github.com/intel/llvm/blob/sycl/clang/lib/Sema/SPIRVBuiltins.td#L1031-L1093 to automatically declare necessary functions for all the types exceptlong long.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment and suggestion, that makes sense.
Just to clarify the scope of this PR: this change is intended as a split of the
existing declarations in
spirv_ops.hppinto category-specific headers, not asa functional change to the atomic declaration set itself. The primary benefit from this
PR is the avoidance of the inclusion of utility (std::pair) and some of the parsing/expansion cost.
The declarations currently in
spirv_ops_atomic.hppwere moved over from theexisting umbrella header without changing their contents. For reference, they
come from the original spirv_ops.hpp
So, I agree, your point is complementary to this refactor relying on the
compiler-provided SPIR-V declarations for the non-
long longcases and keepingonly the missing declarations would likely be a better compile-time improvement
for this area.
That looks like a worthwhile follow-up cleanup on top of this
header split.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. Instead of splitting
spirv_ops.hpp, you can just remove all declarations which clang already provides. It's much better change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I want to be explicit about why I am still confused about the direction here.
The old umbrella spirv_ops.hpp costs about 45.8 ms to parse in the measurement
I took, and some of the heaviest transitive contributors on that path are exactly
the standard-library utility/type-traits machinery (30ms) that the split helps avoid
on narrower include paths.
So I agree your suggestion is a stronger optimization for the atomic slice
itself, but I do not understand it as making this split directionally wrong.
From my perspective, this PR still reduces unnecessary parsing for non-atomic
consumers, while your proposal reduces cost inside the atomic declarations.
Do you view this PR as moving in the wrong direction overall?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. From my perspective we should remove declarations for ALL consumer, not just "non-atomic".
This will also remove the "the standard-library utility/type-traits machinery (30ms) that the split helps avoid
on narrower include paths".
Are you up to exploring this option?
If not, I'm not against making the split, I just saying that we can do much better that limiting the scope for
__spirv_*functions declarations. I'll let @againull to decide.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that removing the redundant declarations Clang already provides is a worthwhile direction, and it may well deliver a larger win for this area than the split alone.
My hesitation is only that I do not think it fully addresses all of the current utility / type_traits cost in spirv_ops.hpp.
For example,
__spirv_IAddCarryand__spirv_ISubBorrowstill usestd::pair, and there are also type_traits-based helpers such as__spirv_ConvertPtrToUand the atomic min/max helper dispatch. So even after pruning the redundant atomic declarations, some broader refactoring would still be needed to remove those dependencies from all consumers.I’m happy to explore that as follow-up work (later), but for this PR I’d prefer to keep the scope to the header split, since it is part of a larger refactoring series already in progress.
@againull let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like removing all header declarations might require more effort/time, so I am not against the split.