Skip to content

Commit fc78218

Browse files
[NFC][SYCL][Reduction] Use C++17 fold expressions (#7208)
...instead of std::tuple tricks.
1 parent 8585116 commit fc78218

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

sycl/include/sycl/reduction.hpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,15 +1653,13 @@ void initReduLocalAccs(bool Pow2WG, size_t LID, size_t WGSize,
16531653
const std::tuple<ReducerT...> &Reducers,
16541654
ReduTupleT<ResultT...> Identities,
16551655
std::index_sequence<Is...>) {
1656-
std::tie(std::get<Is>(LocalAccs)[LID]...) =
1657-
std::make_tuple(std::get<Is>(Reducers).MValue...);
1656+
((std::get<Is>(LocalAccs)[LID] = std::get<Is>(Reducers).MValue), ...);
16581657

16591658
// For work-groups, which size is not power of two, local accessors have
16601659
// an additional element with index WGSize that is used by the tree-reduction
16611660
// algorithm. Initialize those additional elements with identity values here.
16621661
if (!Pow2WG)
1663-
std::tie(std::get<Is>(LocalAccs)[WGSize]...) =
1664-
std::make_tuple(std::get<Is>(Identities)...);
1662+
((std::get<Is>(LocalAccs)[WGSize] = std::get<Is>(Identities)), ...);
16651663
}
16661664

16671665
template <typename... LocalAccT, typename... InputAccT, typename... ResultT,
@@ -1679,28 +1677,26 @@ void initReduLocalAccs(bool UniformPow2WG, size_t LID, size_t GID,
16791677
// give any impact into the final partial sums during the tree-reduction
16801678
// algorithm work.
16811679
if (UniformPow2WG || GID < NWorkItems)
1682-
std::tie(std::get<Is>(LocalAccs)[LID]...) =
1683-
std::make_tuple(std::get<Is>(InputAccs)[GID]...);
1680+
((std::get<Is>(LocalAccs)[LID] = std::get<Is>(InputAccs)[GID]), ...);
16841681
else
1685-
std::tie(std::get<Is>(LocalAccs)[LID]...) =
1686-
std::make_tuple(std::get<Is>(Identities)...);
1682+
((std::get<Is>(LocalAccs)[LID] = std::get<Is>(Identities)), ...);
16871683

16881684
// For work-groups, which size is not power of two, local accessors have
16891685
// an additional element with index WGSize that is used by the tree-reduction
16901686
// algorithm. Initialize those additional elements with identity values here.
16911687
if (!UniformPow2WG)
1692-
std::tie(std::get<Is>(LocalAccs)[WGSize]...) =
1693-
std::make_tuple(std::get<Is>(Identities)...);
1688+
((std::get<Is>(LocalAccs)[WGSize] = std::get<Is>(Identities)), ...);
16941689
}
16951690

16961691
template <typename... LocalAccT, typename... BOPsT, size_t... Is>
16971692
void reduceReduLocalAccs(size_t IndexA, size_t IndexB,
16981693
ReduTupleT<LocalAccT...> LocalAccs,
16991694
ReduTupleT<BOPsT...> BOPs,
17001695
std::index_sequence<Is...>) {
1701-
std::tie(std::get<Is>(LocalAccs)[IndexA]...) =
1702-
std::make_tuple((std::get<Is>(BOPs)(std::get<Is>(LocalAccs)[IndexA],
1703-
std::get<Is>(LocalAccs)[IndexB]))...);
1696+
auto ProcessOne = [=](auto &LocalAcc, auto &BOp) {
1697+
LocalAcc[IndexA] = BOp(LocalAcc[IndexA], LocalAcc[IndexB]);
1698+
};
1699+
(ProcessOne(std::get<Is>(LocalAccs), std::get<Is>(BOPs)), ...);
17041700
}
17051701

17061702
template <typename... Reductions, typename... OutAccT, typename... LocalAccT,
@@ -1713,23 +1709,23 @@ void writeReduSumsToOutAccs(
17131709
std::index_sequence<Is...>) {
17141710
// Add the initial value of user's variable to the final result.
17151711
if (IsOneWG)
1716-
std::tie(std::get<Is>(LocalAccs)[0]...) = std::make_tuple(std::get<Is>(
1717-
BOPs)(std::get<Is>(LocalAccs)[0], IsInitializeToIdentity[Is]
1718-
? std::get<Is>(IdentityVals)
1719-
: std::get<Is>(OutAccs)[0])...);
1712+
((std::get<Is>(LocalAccs)[0] = std::get<Is>(BOPs)(
1713+
std::get<Is>(LocalAccs)[0], IsInitializeToIdentity[Is]
1714+
? std::get<Is>(IdentityVals)
1715+
: std::get<Is>(OutAccs)[0])),
1716+
...);
17201717

17211718
if (Pow2WG) {
17221719
// The partial sums for the work-group are stored in 0-th elements of local
17231720
// accessors. Simply write those sums to output accessors.
1724-
std::tie(std::get<Is>(OutAccs)[OutAccIndex]...) =
1725-
std::make_tuple(std::get<Is>(LocalAccs)[0]...);
1721+
((std::get<Is>(OutAccs)[OutAccIndex] = std::get<Is>(LocalAccs)[0]), ...);
17261722
} else {
17271723
// Each of local accessors keeps two partial sums: in 0-th and WGsize-th
17281724
// elements. Combine them into final partial sums and write to output
17291725
// accessors.
1730-
std::tie(std::get<Is>(OutAccs)[OutAccIndex]...) =
1731-
std::make_tuple(std::get<Is>(BOPs)(std::get<Is>(LocalAccs)[0],
1732-
std::get<Is>(LocalAccs)[WGSize])...);
1726+
((std::get<Is>(OutAccs)[OutAccIndex] = std::get<Is>(BOPs)(
1727+
std::get<Is>(LocalAccs)[0], std::get<Is>(LocalAccs)[WGSize])),
1728+
...);
17331729
}
17341730
}
17351731

0 commit comments

Comments
 (0)