-
Notifications
You must be signed in to change notification settings - Fork 795
[SYCL] Add SPIR-V atomic builtins declarations to clang/lib/Sema/SPIRVBuiltins.td #17471
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
Changes from 1 commit
8088b0a
0e45a71
6f69afe
ad33aa8
e630132
105d495
764b3f3
a4c12e5
bbafeca
3b087df
7dab59d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -232,37 +232,117 @@ extern __DPCPP_SYCL_EXTERNAL | |
| #define __SYCL_OpGroupAsyncCopyGlobalToLocal __spirv_GroupAsyncCopy | ||
| #define __SYCL_OpGroupAsyncCopyLocalToGlobal __spirv_GroupAsyncCopy | ||
|
|
||
| // Atomic SPIR-V builtins | ||
| #define __SPIRV_ATOMIC_LOAD(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicLoad(AS Type *P, int S, \ | ||
| int O); | ||
| #define __SPIRV_ATOMIC_STORE(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL void __spirv_AtomicStore(AS Type *P, int S, \ | ||
| int O, Type V); | ||
| #define __SPIRV_ATOMIC_EXCHANGE(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicExchange(AS Type *P, int S, \ | ||
| int O, Type V); | ||
| #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); | ||
| #define __SPIRV_ATOMIC_IADD(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicIAdd(AS Type *P, int S, \ | ||
| int O, Type V); | ||
| #define __SPIRV_ATOMIC_ISUB(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicISub(AS Type *P, int S, \ | ||
| int O, Type V); | ||
| #define __SPIRV_ATOMIC_FADD(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicFAddEXT(AS Type *P, int S, \ | ||
| int O, Type V); | ||
| #define __SPIRV_ATOMIC_SMIN(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicSMin(AS Type *P, int S, \ | ||
| int O, Type V); | ||
| #define __SPIRV_ATOMIC_UMIN(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicUMin(AS Type *P, int S, \ | ||
| int O, Type V); | ||
| #define __SPIRV_ATOMIC_FMIN(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicFMinEXT(AS Type *P, int S, \ | ||
| int O, Type V); | ||
| #define __SPIRV_ATOMIC_SMAX(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicSMax(AS Type *P, int S, \ | ||
| int O, Type V); | ||
| #define __SPIRV_ATOMIC_UMAX(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicUMax(AS Type *P, int S, \ | ||
| int O, Type V); | ||
| #define __SPIRV_ATOMIC_FMAX(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicFMaxEXT(AS Type *P, int S, \ | ||
| int O, Type V); | ||
| #define __SPIRV_ATOMIC_AND(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicAnd(AS Type *P, int S, \ | ||
| int O, Type V); | ||
| #define __SPIRV_ATOMIC_OR(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicOr(AS Type *P, int S, int O, \ | ||
| Type V); | ||
| #define __SPIRV_ATOMIC_XOR(AS, Type) \ | ||
| extern __DPCPP_SYCL_EXTERNAL Type __spirv_AtomicXor(AS Type *P, int S, \ | ||
| int O, Type V); | ||
|
|
||
| #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, __spv::Scope::Flag Memory, \ | ||
| __spv::MemorySemanticsMask::Flag Semantics, \ | ||
| T Value) { \ | ||
| __spirv_Atomic##Op(AS T *Ptr, int Memory, int Semantics, T Value) { \ | ||
| 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, __spv::Scope::Flag Memory, \ | ||
| __spv::MemorySemanticsMask::Flag Semantics, \ | ||
| T Value) { \ | ||
| __spirv_Atomic##Op(AS T *Ptr, int Memory, int Semantics, T Value) { \ | ||
| 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, __spv::Scope::Flag Memory, \ | ||
| __spv::MemorySemanticsMask::Flag Semantics, \ | ||
| T Value) { \ | ||
| __spirv_Atomic##Op(AS T *Ptr, int Memory, int Semantics, T Value) { \ | ||
| 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) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't remove this part and below unsigned int/long variants because when a test uses both long long type from this header and non-long long type from clang SPIRVBuiltins.td, there is build error Please advise how to proceed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's linked to this I think https://github.com/intel/llvm/pull/1384/files#diff-73b1c844b6929ccc37836285e2d87f89ead7074c6693a80e712f06bb54fa5cb2, I'll need to refresh my memory and come back to you as it is a bit old now.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll keep the declarations in sycl/include/sycl/__spirv/spirv_ops.hpp until there is a stable solution. I'll check it later. |
||
| __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) | ||
|
|
||
|
|
||
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.
For my education, why do we still need these?
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.
@aelovikov-intel it is related to long long type, please check comment: #17471 (comment)