11
11
#include " CL/sycl/ONEAPI/accessor_property_list.hpp"
12
12
#include < CL/sycl/ONEAPI/group_algorithm.hpp>
13
13
#include < CL/sycl/accessor.hpp>
14
+ #include < CL/sycl/atomic.hpp>
14
15
#include < CL/sycl/handler.hpp>
15
16
#include < CL/sycl/kernel.hpp>
16
17
@@ -71,7 +72,8 @@ using IsReduBitAND =
71
72
72
73
template <typename T, class BinaryOperation >
73
74
using IsReduOptForFastAtomicFetch =
74
- bool_constant<is_sgeninteger<T>::value && IsValidAtomicType<T>::value &&
75
+ bool_constant<is_sgeninteger<T>::value &&
76
+ sycl::detail::IsValidAtomicType<T>::value &&
75
77
(IsReduPlus<T, BinaryOperation>::value ||
76
78
IsReduMinimum<T, BinaryOperation>::value ||
77
79
IsReduMaximum<T, BinaryOperation>::value ||
@@ -81,7 +83,9 @@ using IsReduOptForFastAtomicFetch =
81
83
82
84
template <typename T, class BinaryOperation >
83
85
using IsReduOptForFastReduce =
84
- bool_constant<(is_sgeninteger<T>::value || is_sgenfloat<T>::value) &&
86
+ bool_constant<((is_sgeninteger<T>::value &&
87
+ (sizeof (T) == 32 || sizeof (T) == 64 )) ||
88
+ is_sgenfloat<T>::value) &&
85
89
(IsReduPlus<T, BinaryOperation>::value ||
86
90
IsReduMinimum<T, BinaryOperation>::value ||
87
91
IsReduMaximum<T, BinaryOperation>::value)>;
@@ -322,7 +326,7 @@ class reducer<T, BinaryOperation,
322
326
// / Atomic ADD operation: *ReduVarPtr += MValue;
323
327
template <typename _T = T, class _BinaryOperation = BinaryOperation>
324
328
enable_if_t <std::is_same<typename remove_AS<_T>::type, T>::value &&
325
- (is_geninteger32bit<T>::value || is_geninteger64bit<T >::value) &&
329
+ IsReduOptForFastAtomicFetch<T, _BinaryOperation >::value &&
326
330
IsReduPlus<T, _BinaryOperation>::value>
327
331
atomic_combine (_T *ReduVarPtr) const {
328
332
atomic<T, access::address_space::global_space>(global_ptr<T>(ReduVarPtr))
@@ -332,7 +336,7 @@ class reducer<T, BinaryOperation,
332
336
// / Atomic BITWISE OR operation: *ReduVarPtr |= MValue;
333
337
template <typename _T = T, class _BinaryOperation = BinaryOperation>
334
338
enable_if_t <std::is_same<typename remove_AS<_T>::type, T>::value &&
335
- (is_geninteger32bit<T>::value || is_geninteger64bit<T >::value) &&
339
+ IsReduOptForFastAtomicFetch<T, _BinaryOperation >::value &&
336
340
IsReduBitOR<T, _BinaryOperation>::value>
337
341
atomic_combine (_T *ReduVarPtr) const {
338
342
atomic<T, access::address_space::global_space>(global_ptr<T>(ReduVarPtr))
@@ -342,7 +346,7 @@ class reducer<T, BinaryOperation,
342
346
// / Atomic BITWISE XOR operation: *ReduVarPtr ^= MValue;
343
347
template <typename _T = T, class _BinaryOperation = BinaryOperation>
344
348
enable_if_t <std::is_same<typename remove_AS<_T>::type, T>::value &&
345
- (is_geninteger32bit<T>::value || is_geninteger64bit<T >::value) &&
349
+ IsReduOptForFastAtomicFetch<T, _BinaryOperation >::value &&
346
350
IsReduBitXOR<T, _BinaryOperation>::value>
347
351
atomic_combine (_T *ReduVarPtr) const {
348
352
atomic<T, access::address_space::global_space>(global_ptr<T>(ReduVarPtr))
@@ -352,7 +356,7 @@ class reducer<T, BinaryOperation,
352
356
// / Atomic BITWISE AND operation: *ReduVarPtr &= MValue;
353
357
template <typename _T = T, class _BinaryOperation = BinaryOperation>
354
358
enable_if_t <std::is_same<typename remove_AS<_T>::type, T>::value &&
355
- (is_geninteger32bit<T>::value || is_geninteger64bit<T >::value) &&
359
+ IsReduOptForFastAtomicFetch<T, _BinaryOperation >::value &&
356
360
IsReduBitAND<T, _BinaryOperation>::value>
357
361
atomic_combine (_T *ReduVarPtr) const {
358
362
atomic<T, access::address_space::global_space>(global_ptr<T>(ReduVarPtr))
@@ -362,7 +366,7 @@ class reducer<T, BinaryOperation,
362
366
// / Atomic MIN operation: *ReduVarPtr = ONEAPI::minimum(*ReduVarPtr, MValue);
363
367
template <typename _T = T, class _BinaryOperation = BinaryOperation>
364
368
enable_if_t <std::is_same<typename remove_AS<_T>::type, T>::value &&
365
- (is_geninteger32bit<T>::value || is_geninteger64bit<T >::value) &&
369
+ IsReduOptForFastAtomicFetch<T, _BinaryOperation >::value &&
366
370
IsReduMinimum<T, _BinaryOperation>::value>
367
371
atomic_combine (_T *ReduVarPtr) const {
368
372
atomic<T, access::address_space::global_space>(global_ptr<T>(ReduVarPtr))
@@ -372,7 +376,7 @@ class reducer<T, BinaryOperation,
372
376
// / Atomic MAX operation: *ReduVarPtr = ONEAPI::maximum(*ReduVarPtr, MValue);
373
377
template <typename _T = T, class _BinaryOperation = BinaryOperation>
374
378
enable_if_t <std::is_same<typename remove_AS<_T>::type, T>::value &&
375
- (is_geninteger32bit<T>::value || is_geninteger64bit<T >::value) &&
379
+ IsReduOptForFastAtomicFetch<T, _BinaryOperation >::value &&
376
380
IsReduMaximum<T, _BinaryOperation>::value>
377
381
atomic_combine (_T *ReduVarPtr) const {
378
382
atomic<T, access::address_space::global_space>(global_ptr<T>(ReduVarPtr))
@@ -1619,10 +1623,8 @@ reduction(T *VarPtr, BinaryOperation) {
1619
1623
access::mode::read_write>(VarPtr);
1620
1624
}
1621
1625
1622
- } // namespace ONEAPI
1623
-
1624
1626
template <typename BinaryOperation, typename AccumulatorT>
1625
- struct has_known_identity : ONEAPI:: detail::has_known_identity_impl<
1627
+ struct has_known_identity : detail::has_known_identity_impl<
1626
1628
typename std::decay<BinaryOperation>::type,
1627
1629
typename std::decay<AccumulatorT>::type> {};
1628
1630
#if __cplusplus >= 201703L
@@ -1632,14 +1634,36 @@ inline constexpr bool has_known_identity_v =
1632
1634
#endif
1633
1635
1634
1636
template <typename BinaryOperation, typename AccumulatorT>
1635
- struct known_identity : ONEAPI::detail::known_identity_impl<
1636
- typename std::decay<BinaryOperation>::type,
1637
- typename std::decay<AccumulatorT>::type> {};
1637
+ struct known_identity
1638
+ : detail::known_identity_impl< typename std::decay<BinaryOperation>::type,
1639
+ typename std::decay<AccumulatorT>::type> {};
1638
1640
#if __cplusplus >= 201703L
1639
1641
template <typename BinaryOperation, typename AccumulatorT>
1640
1642
inline constexpr AccumulatorT known_identity_v =
1641
1643
known_identity<BinaryOperation, AccumulatorT>::value;
1642
1644
#endif
1645
+ } // namespace ONEAPI
1646
+
1647
+ // Currently, the type traits defined below correspond to SYCL 1.2.1 ONEAPI
1648
+ // reduction extension. That may be changed later when SYCL 2020 reductions
1649
+ // are implemented.
1650
+ #if SYCL_LANGUAGE_VERSION >= 202001
1651
+ template <typename BinaryOperation, typename AccumulatorT>
1652
+ struct has_known_identity
1653
+ : ONEAPI::has_known_identity<BinaryOperation, AccumulatorT> {};
1654
+
1655
+ template <typename BinaryOperation, typename AccumulatorT>
1656
+ inline constexpr bool has_known_identity_v =
1657
+ has_known_identity<BinaryOperation, AccumulatorT>::value;
1658
+
1659
+ template <typename BinaryOperation, typename AccumulatorT>
1660
+ struct known_identity : ONEAPI::known_identity<BinaryOperation, AccumulatorT> {
1661
+ };
1662
+
1663
+ template <typename BinaryOperation, typename AccumulatorT>
1664
+ inline constexpr AccumulatorT known_identity_v =
1665
+ known_identity<BinaryOperation, AccumulatorT>::value;
1666
+ #endif // SYCL_LANGUAGE_VERSION >= 202001
1643
1667
1644
1668
} // namespace sycl
1645
1669
} // __SYCL_INLINE_NAMESPACE(cl)
0 commit comments