Skip to content

Commit a04f47b

Browse files
steffenlarsencallumfare
authored andcommitted
[SYCL][NFC] Use reducer-access helper function instead of deduction guide (intel#8411)
The use of deduction guides in the `ReducerAccess` helper class causes problems when building with a compiler that does not support them. This commit changes the implementation to use a helper function instead. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent c50e30c commit a04f47b

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

sycl/include/sycl/reduction.hpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,11 @@ template <typename ReducerT> class ReducerAccess {
200200
ReducerT &MReducerRef;
201201
};
202202

203-
// Deduction guide to simplify the use of ReducerAccess.
204-
template <typename ReducerT>
205-
ReducerAccess(ReducerT &) -> ReducerAccess<ReducerT>;
203+
// Helper function to simplify the use of ReducerAccess. This avoids the need
204+
// for potentially unsupported deduction guides.
205+
template <typename ReducerT> auto getReducerAccess(ReducerT &Reducer) {
206+
return ReducerAccess<ReducerT>{Reducer};
207+
}
206208

207209
/// Use CRTP to avoid redefining shorthand operators in terms of combine
208210
///
@@ -283,7 +285,7 @@ template <class Reducer> class combiner {
283285
auto AtomicRef = sycl::atomic_ref<T, memory_order::relaxed,
284286
getMemoryScope<Space>(), Space>(
285287
address_space_cast<Space, access::decorated::no>(ReduVarPtr)[E]);
286-
Functor(std::move(AtomicRef), ReducerAccess{*reducer}.getElement(E));
288+
Functor(std::move(AtomicRef), getReducerAccess(*reducer).getElement(E));
287289
}
288290
}
289291

@@ -956,7 +958,7 @@ struct NDRangeReduction<reduction::strategy::local_atomic_and_atomic_cross_wg> {
956958
// Work-group cooperates to initialize multiple reduction variables
957959
auto LID = NDId.get_local_id(0);
958960
for (size_t E = LID; E < NElements; E += NDId.get_local_range(0)) {
959-
GroupSum[E] = ReducerAccess(Reducer).getIdentity();
961+
GroupSum[E] = getReducerAccess(Reducer).getIdentity();
960962
}
961963
workGroupBarrier();
962964

@@ -969,7 +971,7 @@ struct NDRangeReduction<reduction::strategy::local_atomic_and_atomic_cross_wg> {
969971
workGroupBarrier();
970972
if (LID == 0) {
971973
for (size_t E = 0; E < NElements; ++E) {
972-
ReducerAccess{Reducer}.getElement(E) = GroupSum[E];
974+
getReducerAccess(Reducer).getElement(E) = GroupSum[E];
973975
}
974976
Reducer.template atomic_combine(&Out[0]);
975977
}
@@ -1019,7 +1021,7 @@ struct NDRangeReduction<
10191021
// reduce_over_group is only defined for each T, not for span<T, ...>
10201022
size_t LID = NDId.get_local_id(0);
10211023
for (int E = 0; E < NElements; ++E) {
1022-
auto &RedElem = ReducerAccess{Reducer}.getElement(E);
1024+
auto &RedElem = getReducerAccess(Reducer).getElement(E);
10231025
RedElem = reduce_over_group(Group, RedElem, BOp);
10241026
if (LID == 0) {
10251027
if (NWorkGroups == 1) {
@@ -1030,7 +1032,7 @@ struct NDRangeReduction<
10301032
Out[E] = RedElem;
10311033
} else {
10321034
PartialSums[NDId.get_group_linear_id() * NElements + E] =
1033-
ReducerAccess{Reducer}.getElement(E);
1035+
getReducerAccess(Reducer).getElement(E);
10341036
}
10351037
}
10361038
}
@@ -1053,7 +1055,7 @@ struct NDRangeReduction<
10531055
// Reduce each result separately
10541056
// TODO: Opportunity to parallelize across elements.
10551057
for (int E = 0; E < NElements; ++E) {
1056-
auto LocalSum = ReducerAccess{Reducer}.getIdentity();
1058+
auto LocalSum = getReducerAccess(Reducer).getIdentity();
10571059
for (size_t I = LID; I < NWorkGroups; I += WGSize)
10581060
LocalSum = BOp(LocalSum, PartialSums[I * NElements + E]);
10591061
auto Result = reduce_over_group(Group, LocalSum, BOp);
@@ -1143,7 +1145,7 @@ template <> struct NDRangeReduction<reduction::strategy::range_basic> {
11431145
for (int E = 0; E < NElements; ++E) {
11441146

11451147
// Copy the element to local memory to prepare it for tree-reduction.
1146-
LocalReds[LID] = ReducerAccess{Reducer}.getElement(E);
1148+
LocalReds[LID] = getReducerAccess(Reducer).getElement(E);
11471149

11481150
doTreeReduction(WGSize, LID, false, Identity, LocalReds, BOp,
11491151
[&]() { workGroupBarrier(); });
@@ -1218,8 +1220,8 @@ struct NDRangeReduction<reduction::strategy::group_reduce_and_atomic_cross_wg> {
12181220

12191221
typename Reduction::binary_operation BOp;
12201222
for (int E = 0; E < NElements; ++E) {
1221-
ReducerAccess{Reducer}.getElement(E) = reduce_over_group(
1222-
NDIt.get_group(), ReducerAccess{Reducer}.getElement(E), BOp);
1223+
getReducerAccess(Reducer).getElement(E) = reduce_over_group(
1224+
NDIt.get_group(), getReducerAccess(Reducer).getElement(E), BOp);
12231225
}
12241226
if (NDIt.get_local_linear_id() == 0)
12251227
Reducer.atomic_combine(&Out[0]);
@@ -1267,15 +1269,15 @@ struct NDRangeReduction<
12671269
for (int E = 0; E < NElements; ++E) {
12681270

12691271
// Copy the element to local memory to prepare it for tree-reduction.
1270-
LocalReds[LID] = ReducerAccess{Reducer}.getElement(E);
1272+
LocalReds[LID] = getReducerAccess(Reducer).getElement(E);
12711273

12721274
typename Reduction::binary_operation BOp;
12731275
doTreeReduction(WGSize, LID, IsPow2WG,
1274-
ReducerAccess{Reducer}.getIdentity(), LocalReds, BOp,
1275-
[&]() { NDIt.barrier(); });
1276+
getReducerAccess(Reducer).getIdentity(), LocalReds,
1277+
BOp, [&]() { NDIt.barrier(); });
12761278

12771279
if (LID == 0) {
1278-
ReducerAccess{Reducer}.getElement(E) =
1280+
getReducerAccess(Reducer).getElement(E) =
12791281
IsPow2WG ? LocalReds[0] : BOp(LocalReds[0], LocalReds[WGSize]);
12801282
}
12811283

@@ -1343,7 +1345,7 @@ struct NDRangeReduction<
13431345
typename Reduction::binary_operation BOp;
13441346
for (int E = 0; E < NElements; ++E) {
13451347
typename Reduction::result_type PSum;
1346-
PSum = ReducerAccess{Reducer}.getElement(E);
1348+
PSum = getReducerAccess(Reducer).getElement(E);
13471349
PSum = reduce_over_group(NDIt.get_group(), PSum, BOp);
13481350
if (NDIt.get_local_linear_id() == 0) {
13491351
if (IsUpdateOfUserVar)
@@ -1482,7 +1484,7 @@ template <> struct NDRangeReduction<reduction::strategy::basic> {
14821484
for (int E = 0; E < NElements; ++E) {
14831485

14841486
// Copy the element to local memory to prepare it for tree-reduction.
1485-
LocalReds[LID] = ReducerAccess{Reducer}.getElement(E);
1487+
LocalReds[LID] = getReducerAccess(Reducer).getElement(E);
14861488

14871489
doTreeReduction(WGSize, LID, IsPow2WG, ReduIdentity, LocalReds, BOp,
14881490
[&]() { NDIt.barrier(); });
@@ -1756,7 +1758,7 @@ void reduCGFuncImplScalar(
17561758
size_t LID = NDIt.get_local_linear_id();
17571759

17581760
((std::get<Is>(LocalAccsTuple)[LID] =
1759-
ReducerAccess{std::get<Is>(ReducersTuple)}.getElement(0)),
1761+
getReducerAccess(std::get<Is>(ReducersTuple)).getElement(0)),
17601762
...);
17611763

17621764
// For work-groups, which size is not power of two, local accessors have
@@ -1807,7 +1809,7 @@ void reduCGFuncImplArrayHelper(bool Pow2WG, bool IsOneWG, nd_item<Dims> NDIt,
18071809
for (size_t E = 0; E < NElements; ++E) {
18081810

18091811
// Copy the element to local memory to prepare it for tree-reduction.
1810-
LocalReds[LID] = ReducerAccess{Reducer}.getElement(E);
1812+
LocalReds[LID] = getReducerAccess(Reducer).getElement(E);
18111813

18121814
doTreeReduction(WGSize, LID, Pow2WG, Identity, LocalReds, BOp,
18131815
[&]() { NDIt.barrier(); });

0 commit comments

Comments
 (0)