13
13
14
14
#include < CL/sycl/accessor.hpp>
15
15
#include < CL/sycl/atomic.hpp>
16
+ #include < CL/sycl/atomic_ref.hpp>
16
17
#include < CL/sycl/detail/tuple.hpp>
18
+ #include < CL/sycl/group_algorithm.hpp>
17
19
#include < CL/sycl/handler.hpp>
18
20
#include < CL/sycl/kernel.hpp>
19
21
#include < CL/sycl/known_identity.hpp>
20
22
#include < sycl/ext/oneapi/accessor_property_list.hpp>
21
- #include < sycl/ext/oneapi/group_algorithm.hpp>
22
23
23
24
#include < tuple>
24
25
@@ -222,8 +223,8 @@ template <class Reducer> class combiner {
222
223
auto reducer = static_cast <const Reducer *>(this );
223
224
for (size_t E = 0 ; E < Extent; ++E) {
224
225
auto AtomicRef =
225
- atomic_ref<T, memory_order::relaxed, getMemoryScope<Space>(), Space>(
226
- multi_ptr<T, Space>(ReduVarPtr)[E]);
226
+ sycl:: atomic_ref<T, memory_order::relaxed, getMemoryScope<Space>(),
227
+ Space>( multi_ptr<T, Space>(ReduVarPtr)[E]);
227
228
Functor (AtomicRef, reducer->getElement (E));
228
229
}
229
230
}
@@ -312,13 +313,15 @@ template <class Reducer> class combiner {
312
313
// / reduction.
313
314
template <typename T, class BinaryOperation , int Dims, size_t Extent,
314
315
class Algorithm , bool View>
315
- class reducer <T, BinaryOperation, Dims, Extent, Algorithm, View,
316
- enable_if_t <Dims == 0 && Extent == 1 && View == false &&
317
- !IsKnownIdentityOp<T, BinaryOperation>::value>>
316
+ class reducer <
317
+ T, BinaryOperation, Dims, Extent, Algorithm, View,
318
+ enable_if_t <Dims == 0 && Extent == 1 && View == false &&
319
+ !sycl::detail::IsKnownIdentityOp<T, BinaryOperation>::value>>
318
320
: public combiner<
319
321
reducer<T, BinaryOperation, Dims, Extent, Algorithm, View,
320
322
enable_if_t <Dims == 0 && Extent == 1 && View == false &&
321
- !IsKnownIdentityOp<T, BinaryOperation>::value>>> {
323
+ !sycl::detail::IsKnownIdentityOp<
324
+ T, BinaryOperation>::value>>> {
322
325
public:
323
326
reducer (const T &Identity, BinaryOperation BOp)
324
327
: MValue(Identity), MIdentity(Identity), MBinaryOp(BOp) {}
@@ -343,13 +346,15 @@ class reducer<T, BinaryOperation, Dims, Extent, Algorithm, View,
343
346
// / the identity field inside it and allows to add a default constructor.
344
347
template <typename T, class BinaryOperation , int Dims, size_t Extent,
345
348
class Algorithm , bool View>
346
- class reducer <T, BinaryOperation, Dims, Extent, Algorithm, View,
347
- enable_if_t <Dims == 0 && Extent == 1 && View == false &&
348
- IsKnownIdentityOp<T, BinaryOperation>::value>>
349
+ class reducer <
350
+ T, BinaryOperation, Dims, Extent, Algorithm, View,
351
+ enable_if_t <Dims == 0 && Extent == 1 && View == false &&
352
+ sycl::detail::IsKnownIdentityOp<T, BinaryOperation>::value>>
349
353
: public combiner<
350
354
reducer<T, BinaryOperation, Dims, Extent, Algorithm, View,
351
355
enable_if_t <Dims == 0 && Extent == 1 && View == false &&
352
- IsKnownIdentityOp<T, BinaryOperation>::value>>> {
356
+ sycl::detail::IsKnownIdentityOp<
357
+ T, BinaryOperation>::value>>> {
353
358
public:
354
359
reducer () : MValue(getIdentity()) {}
355
360
reducer (const T & /* Identity */ , BinaryOperation) : MValue(getIdentity()) {}
@@ -360,7 +365,7 @@ class reducer<T, BinaryOperation, Dims, Extent, Algorithm, View,
360
365
}
361
366
362
367
static T getIdentity () {
363
- return known_identity_impl<BinaryOperation, T>::value;
368
+ return sycl::detail:: known_identity_impl<BinaryOperation, T>::value;
364
369
}
365
370
366
371
T &getElement (size_t ) { return MValue; }
@@ -390,13 +395,14 @@ class reducer<T, BinaryOperation, Dims, Extent, Algorithm, View,
390
395
// / subscript operator.
391
396
template <typename T, class BinaryOperation , int Dims, size_t Extent,
392
397
class Algorithm , bool View>
393
- class reducer <T, BinaryOperation, Dims, Extent, Algorithm, View,
394
- enable_if_t <Dims == 1 && View == false &&
395
- !IsKnownIdentityOp<T, BinaryOperation>::value>>
396
- : public combiner<
397
- reducer<T, BinaryOperation, Dims, Extent, Algorithm, View,
398
- enable_if_t <Dims == 1 && View == false &&
399
- !IsKnownIdentityOp<T, BinaryOperation>::value>>> {
398
+ class reducer <
399
+ T, BinaryOperation, Dims, Extent, Algorithm, View,
400
+ enable_if_t <Dims == 1 && View == false &&
401
+ !sycl::detail::IsKnownIdentityOp<T, BinaryOperation>::value>>
402
+ : public combiner<reducer<T, BinaryOperation, Dims, Extent, Algorithm, View,
403
+ enable_if_t <Dims == 1 && View == false &&
404
+ !sycl::detail::IsKnownIdentityOp<
405
+ T, BinaryOperation>::value>>> {
400
406
public:
401
407
reducer (const T &Identity, BinaryOperation BOp)
402
408
: MValue(Identity), MIdentity(Identity), MBinaryOp(BOp) {}
@@ -420,13 +426,14 @@ class reducer<T, BinaryOperation, Dims, Extent, Algorithm, View,
420
426
// / in cases where the identity value is known.
421
427
template <typename T, class BinaryOperation , int Dims, size_t Extent,
422
428
class Algorithm , bool View>
423
- class reducer <T, BinaryOperation, Dims, Extent, Algorithm, View,
424
- enable_if_t <Dims == 1 && View == false &&
425
- IsKnownIdentityOp<T, BinaryOperation>::value>>
426
- : public combiner<
427
- reducer<T, BinaryOperation, Dims, Extent, Algorithm, View,
428
- enable_if_t <Dims == 1 && View == false &&
429
- IsKnownIdentityOp<T, BinaryOperation>::value>>> {
429
+ class reducer <
430
+ T, BinaryOperation, Dims, Extent, Algorithm, View,
431
+ enable_if_t <Dims == 1 && View == false &&
432
+ sycl::detail::IsKnownIdentityOp<T, BinaryOperation>::value>>
433
+ : public combiner<reducer<T, BinaryOperation, Dims, Extent, Algorithm, View,
434
+ enable_if_t <Dims == 1 && View == false &&
435
+ sycl::detail::IsKnownIdentityOp<
436
+ T, BinaryOperation>::value>>> {
430
437
public:
431
438
reducer () : MValue(getIdentity()) {}
432
439
reducer (const T & /* Identity */ , BinaryOperation) : MValue(getIdentity()) {}
@@ -439,7 +446,7 @@ class reducer<T, BinaryOperation, Dims, Extent, Algorithm, View,
439
446
}
440
447
441
448
static T getIdentity () {
442
- return known_identity_impl<BinaryOperation, T>::value;
449
+ return sycl::detail:: known_identity_impl<BinaryOperation, T>::value;
443
450
}
444
451
445
452
T &getElement (size_t E) { return MValue[E]; }
@@ -464,14 +471,14 @@ template <typename T, class BinaryOperation> class reduction_impl_common {
464
471
public:
465
472
// / Returns the statically known identity value.
466
473
template <typename _T = T, class _BinaryOperation = BinaryOperation>
467
- enable_if_t <IsKnownIdentityOp<_T, _BinaryOperation>::value,
474
+ enable_if_t <sycl::detail:: IsKnownIdentityOp<_T, _BinaryOperation>::value,
468
475
_T> constexpr getIdentity () {
469
- return known_identity_impl<_BinaryOperation, _T>::value;
476
+ return sycl::detail:: known_identity_impl<_BinaryOperation, _T>::value;
470
477
}
471
478
472
479
// / Returns the identity value given by user.
473
480
template <typename _T = T, class _BinaryOperation = BinaryOperation>
474
- enable_if_t <!IsKnownIdentityOp<_T, _BinaryOperation>::value, _T>
481
+ enable_if_t <!sycl::detail:: IsKnownIdentityOp<_T, _BinaryOperation>::value, _T>
475
482
getIdentity () {
476
483
return MIdentity;
477
484
}
@@ -752,8 +759,8 @@ class reduction_impl
752
759
// / SYCL-2020.
753
760
// / Constructs reduction_impl when the identity value is statically known.
754
761
template <typename _T, typename AllocatorT,
755
- std::enable_if_t <IsKnownIdentityOp<_T, BinaryOperation>::value> * =
756
- nullptr >
762
+ std::enable_if_t <sycl::detail::IsKnownIdentityOp<
763
+ _T, BinaryOperation>::value> * = nullptr >
757
764
reduction_impl (buffer<_T, 1 , AllocatorT> Buffer, handler &CGH,
758
765
bool InitializeToIdentity)
759
766
: algo(reducer_type::getIdentity(), BinaryOperation(),
@@ -766,9 +773,8 @@ class reduction_impl
766
773
}
767
774
768
775
// / Constructs reduction_impl when the identity value is statically known.
769
- template <
770
- typename _T = T,
771
- enable_if_t <IsKnownIdentityOp<_T, BinaryOperation>::value> * = nullptr >
776
+ template <typename _T = T, enable_if_t <sycl::detail::IsKnownIdentityOp<
777
+ _T, BinaryOperation>::value> * = nullptr >
772
778
reduction_impl (rw_accessor_type &Acc)
773
779
: algo(reducer_type::getIdentity(), BinaryOperation(), false ,
774
780
std::make_shared<rw_accessor_type>(Acc)) {
@@ -779,9 +785,8 @@ class reduction_impl
779
785
}
780
786
781
787
// / Constructs reduction_impl when the identity value is statically known.
782
- template <
783
- typename _T = T,
784
- enable_if_t <IsKnownIdentityOp<_T, BinaryOperation>::value> * = nullptr >
788
+ template <typename _T = T, enable_if_t <sycl::detail::IsKnownIdentityOp<
789
+ _T, BinaryOperation>::value> * = nullptr >
785
790
reduction_impl (dw_accessor_type &Acc)
786
791
: algo(reducer_type::getIdentity(), BinaryOperation(), true ,
787
792
std::make_shared<dw_accessor_type>(Acc)) {
@@ -796,7 +801,8 @@ class reduction_impl
796
801
// / and user still passed the identity value.
797
802
template <
798
803
typename _T, typename AllocatorT,
799
- enable_if_t <IsKnownIdentityOp<_T, BinaryOperation>::value> * = nullptr >
804
+ enable_if_t <sycl::detail::IsKnownIdentityOp<_T, BinaryOperation>::value>
805
+ * = nullptr >
800
806
reduction_impl (buffer<_T, 1 , AllocatorT> Buffer, handler &CGH,
801
807
const T & /* Identity*/ , BinaryOperation,
802
808
bool InitializeToIdentity)
@@ -822,9 +828,8 @@ class reduction_impl
822
828
823
829
// / Constructs reduction_impl when the identity value is statically known,
824
830
// / and user still passed the identity value.
825
- template <
826
- typename _T = T,
827
- enable_if_t <IsKnownIdentityOp<_T, BinaryOperation>::value> * = nullptr >
831
+ template <typename _T = T, enable_if_t <sycl::detail::IsKnownIdentityOp<
832
+ _T, BinaryOperation>::value> * = nullptr >
828
833
reduction_impl (rw_accessor_type &Acc, const T & /* Identity*/ , BinaryOperation)
829
834
: algo(reducer_type::getIdentity(), BinaryOperation(), false ,
830
835
std::make_shared<rw_accessor_type>(Acc)) {
@@ -847,9 +852,8 @@ class reduction_impl
847
852
848
853
// / Constructs reduction_impl when the identity value is statically known,
849
854
// / and user still passed the identity value.
850
- template <
851
- typename _T = T,
852
- enable_if_t <IsKnownIdentityOp<_T, BinaryOperation>::value> * = nullptr >
855
+ template <typename _T = T, enable_if_t <sycl::detail::IsKnownIdentityOp<
856
+ _T, BinaryOperation>::value> * = nullptr >
853
857
reduction_impl (dw_accessor_type &Acc, const T & /* Identity*/ , BinaryOperation)
854
858
: algo(reducer_type::getIdentity(), BinaryOperation(), true ,
855
859
std::make_shared<dw_accessor_type>(Acc)) {
@@ -874,7 +878,8 @@ class reduction_impl
874
878
// / Constructs reduction_impl when the identity value is NOT known statically.
875
879
template <
876
880
typename _T, typename AllocatorT,
877
- enable_if_t <!IsKnownIdentityOp<_T, BinaryOperation>::value> * = nullptr >
881
+ enable_if_t <!sycl::detail::IsKnownIdentityOp<_T, BinaryOperation>::value>
882
+ * = nullptr >
878
883
reduction_impl (buffer<_T, 1 , AllocatorT> Buffer, handler &CGH,
879
884
const T &Identity, BinaryOperation BOp,
880
885
bool InitializeToIdentity)
@@ -888,9 +893,8 @@ class reduction_impl
888
893
}
889
894
890
895
// / Constructs reduction_impl when the identity value is unknown.
891
- template <
892
- typename _T = T,
893
- enable_if_t <!IsKnownIdentityOp<_T, BinaryOperation>::value> * = nullptr >
896
+ template <typename _T = T, enable_if_t <!sycl::detail::IsKnownIdentityOp<
897
+ _T, BinaryOperation>::value> * = nullptr >
894
898
reduction_impl (rw_accessor_type &Acc, const T &Identity, BinaryOperation BOp)
895
899
: algo(Identity, BOp, false , std::make_shared<rw_accessor_type>(Acc)) {
896
900
if (Acc.size () != 1 )
@@ -900,9 +904,8 @@ class reduction_impl
900
904
}
901
905
902
906
// / Constructs reduction_impl when the identity value is unknown.
903
- template <
904
- typename _T = T,
905
- enable_if_t <!IsKnownIdentityOp<_T, BinaryOperation>::value> * = nullptr >
907
+ template <typename _T = T, enable_if_t <!sycl::detail::IsKnownIdentityOp<
908
+ _T, BinaryOperation>::value> * = nullptr >
906
909
reduction_impl (dw_accessor_type &Acc, const T &Identity, BinaryOperation BOp)
907
910
: algo(Identity, BOp, true , std::make_shared<dw_accessor_type>(Acc)) {
908
911
if (Acc.size () != 1 )
@@ -915,9 +918,8 @@ class reduction_impl
915
918
// / The \param VarPtr is a USM pointer to memory, to where the computed
916
919
// / reduction value is added using BinaryOperation, i.e. it is expected that
917
920
// / the memory is pre-initialized with some meaningful value.
918
- template <
919
- typename _T = T,
920
- enable_if_t <IsKnownIdentityOp<_T, BinaryOperation>::value> * = nullptr >
921
+ template <typename _T = T, enable_if_t <sycl::detail::IsKnownIdentityOp<
922
+ _T, BinaryOperation>::value> * = nullptr >
921
923
reduction_impl (T *VarPtr, bool InitializeToIdentity = false )
922
924
: algo(reducer_type::getIdentity(), BinaryOperation(),
923
925
InitializeToIdentity, VarPtr) {}
@@ -927,9 +929,8 @@ class reduction_impl
927
929
// / The \param VarPtr is a USM pointer to memory, to where the computed
928
930
// / reduction value is added using BinaryOperation, i.e. it is expected that
929
931
// / the memory is pre-initialized with some meaningful value.
930
- template <
931
- typename _T = T,
932
- enable_if_t <IsKnownIdentityOp<_T, BinaryOperation>::value> * = nullptr >
932
+ template <typename _T = T, enable_if_t <sycl::detail::IsKnownIdentityOp<
933
+ _T, BinaryOperation>::value> * = nullptr >
933
934
reduction_impl (T *VarPtr, const T &Identity, BinaryOperation,
934
935
bool InitializeToIdentity = false )
935
936
: algo(Identity, BinaryOperation(), InitializeToIdentity, VarPtr) {
@@ -950,35 +951,31 @@ class reduction_impl
950
951
// / The \param VarPtr is a USM pointer to memory, to where the computed
951
952
// / reduction value is added using BinaryOperation, i.e. it is expected that
952
953
// / the memory is pre-initialized with some meaningful value.
953
- template <
954
- typename _T = T,
955
- enable_if_t <!IsKnownIdentityOp<_T, BinaryOperation>::value> * = nullptr >
954
+ template <typename _T = T, enable_if_t <!sycl::detail::IsKnownIdentityOp<
955
+ _T, BinaryOperation>::value> * = nullptr >
956
956
reduction_impl (T *VarPtr, const T &Identity, BinaryOperation BOp,
957
957
bool InitializeToIdentity = false )
958
958
: algo(Identity, BOp, InitializeToIdentity, VarPtr) {}
959
959
960
960
// / Constructs reduction_impl when the identity value is statically known
961
- template <
962
- typename _T = T,
963
- enable_if_t <IsKnownIdentityOp<_T, BinaryOperation>::value> * = nullptr >
961
+ template <typename _T = T, enable_if_t <sycl::detail::IsKnownIdentityOp<
962
+ _T, BinaryOperation>::value> * = nullptr >
964
963
reduction_impl (span<_T, Extent> Span, bool InitializeToIdentity = false )
965
964
: algo(reducer_type::getIdentity(), BinaryOperation(),
966
965
InitializeToIdentity, Span.data()) {}
967
966
968
967
// / Constructs reduction_impl when the identity value is statically known
969
968
// / and user passed an identity value anyway
970
- template <
971
- typename _T = T,
972
- enable_if_t <IsKnownIdentityOp<_T, BinaryOperation>::value> * = nullptr >
969
+ template <typename _T = T, enable_if_t <sycl::detail::IsKnownIdentityOp<
970
+ _T, BinaryOperation>::value> * = nullptr >
973
971
reduction_impl (span<_T, Extent> Span, const T & /* Identity */ ,
974
972
BinaryOperation BOp, bool InitializeToIdentity = false )
975
973
: algo(reducer_type::getIdentity(), BOp, InitializeToIdentity,
976
974
Span.data()) {}
977
975
978
976
// / Constructs reduction_impl when the identity value is not statically known
979
- template <
980
- typename _T = T,
981
- enable_if_t <!IsKnownIdentityOp<_T, BinaryOperation>::value> * = nullptr >
977
+ template <typename _T = T, enable_if_t <!sycl::detail::IsKnownIdentityOp<
978
+ _T, BinaryOperation>::value> * = nullptr >
982
979
reduction_impl (span<T, Extent> Span, const T &Identity, BinaryOperation BOp,
983
980
bool InitializeToIdentity = false )
984
981
: algo(Identity, BOp, InitializeToIdentity, Span.data()) {}
@@ -1105,8 +1102,8 @@ void reduCGFuncForRangeFastReduce(handler &CGH, KernelType KernelFunc,
1105
1102
// Signal this work-group has finished after all values are reduced
1106
1103
if (LID == 0 ) {
1107
1104
auto NFinished =
1108
- atomic_ref<int , memory_order::relaxed, memory_scope::device,
1109
- access::address_space::global_space>(
1105
+ sycl:: atomic_ref<int , memory_order::relaxed, memory_scope::device,
1106
+ access::address_space::global_space>(
1110
1107
NWorkGroupsFinished[0 ]);
1111
1108
DoReducePartialSumsInLastWG[0 ] =
1112
1109
++NFinished == NWorkGroups && NWorkGroups > 1 ;
@@ -1204,8 +1201,8 @@ void reduCGFuncForRangeBasic(handler &CGH, KernelType KernelFunc,
1204
1201
// Signal this work-group has finished after all values are reduced
1205
1202
if (LID == 0 ) {
1206
1203
auto NFinished =
1207
- atomic_ref<int , memory_order::relaxed, memory_scope::device,
1208
- access::address_space::global_space>(
1204
+ sycl:: atomic_ref<int , memory_order::relaxed, memory_scope::device,
1205
+ access::address_space::global_space>(
1209
1206
NWorkGroupsFinished[0 ]);
1210
1207
DoReducePartialSumsInLastWG[0 ] =
1211
1208
++NFinished == NWorkGroups && NWorkGroups > 1 ;
@@ -1302,7 +1299,7 @@ void reduCGFuncForNDRangeBothFastReduceAndAtomics(
1302
1299
typename Reduction::binary_operation BOp;
1303
1300
for (int E = 0 ; E < NElements; ++E) {
1304
1301
Reducer.getElement (E) =
1305
- ext::oneapi::reduce (NDIt.get_group (), Reducer.getElement (E), BOp);
1302
+ reduce_over_group (NDIt.get_group (), Reducer.getElement (E), BOp);
1306
1303
}
1307
1304
if (NDIt.get_local_linear_id () == 0 )
1308
1305
Reducer.atomic_combine (Reduction::getOutPointer (Out));
@@ -1426,7 +1423,7 @@ void reduCGFuncForNDRangeFastReduceOnly(
1426
1423
for (int E = 0 ; E < NElements; ++E) {
1427
1424
typename Reduction::result_type PSum;
1428
1425
PSum = Reducer.getElement (E);
1429
- PSum = ext::oneapi::reduce (NDIt.get_group (), PSum, BOp);
1426
+ PSum = reduce_over_group (NDIt.get_group (), PSum, BOp);
1430
1427
if (NDIt.get_local_linear_id () == 0 ) {
1431
1428
if (IsUpdateOfUserVar)
1432
1429
PSum = BOp (Reduction::getOutPointer (Out)[E], PSum);
@@ -1556,7 +1553,7 @@ void reduAuxCGFuncFastReduceImpl(handler &CGH, bool UniformWG,
1556
1553
(UniformWG || (GID < NWorkItems))
1557
1554
? In[GID * NElements + E]
1558
1555
: Reduction::reducer_type::getIdentity ();
1559
- PSum = ext::oneapi::reduce (NDIt.get_group (), PSum, BOp);
1556
+ PSum = reduce_over_group (NDIt.get_group (), PSum, BOp);
1560
1557
if (NDIt.get_local_linear_id () == 0 ) {
1561
1558
if (IsUpdateOfUserVar)
1562
1559
PSum = BOp (Reduction::getOutPointer (Out)[E], PSum);
@@ -2587,7 +2584,7 @@ reduction(accessor<T, Dims, AccMode, access::target::device, IsPH> &Acc,
2587
2584
// / The identity value is not passed to this version as it is statically known.
2588
2585
template <typename T, class BinaryOperation , int Dims, access::mode AccMode,
2589
2586
access::placeholder IsPH>
2590
- std::enable_if_t <detail::IsKnownIdentityOp<T, BinaryOperation>::value,
2587
+ std::enable_if_t <sycl:: detail::IsKnownIdentityOp<T, BinaryOperation>::value,
2591
2588
detail::reduction_impl<
2592
2589
T, BinaryOperation, 0 , 1 ,
2593
2590
detail::default_reduction_algorithm<false , IsPH, Dims>>>
@@ -2615,7 +2612,7 @@ reduction(T *VarPtr, const T &Identity, BinaryOperation BOp) {
2615
2612
// / The identity value is not passed to this version as it is statically known.
2616
2613
template <typename T, class BinaryOperation >
2617
2614
std::enable_if_t <
2618
- detail::IsKnownIdentityOp<T, BinaryOperation>::value,
2615
+ sycl:: detail::IsKnownIdentityOp<T, BinaryOperation>::value,
2619
2616
detail::reduction_impl<T, BinaryOperation, 0 , 1 ,
2620
2617
detail::default_reduction_algorithm<
2621
2618
true , access::placeholder::false_t , 1 >>>
0 commit comments