Skip to content

Commit 6aa3ea7

Browse files
[SYCL] Rename detail::dim_loop -> detail::loop and make it constexpr-friendly (#9108)
Can be used like this now: ``` loop<2>([](auto i) { if constexpr (i == 0) std::cout << "constexpr 0\n"; std::cout << i << std::endl; }); ```
1 parent f0b71e1 commit 6aa3ea7

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
10841084
template <int Dims = Dimensions> size_t getLinearIndex(id<Dims> Id) const {
10851085

10861086
size_t Result = 0;
1087-
detail::dim_loop<Dims>([&, this](size_t I) {
1087+
detail::loop<Dims>([&, this](size_t I) {
10881088
Result = Result * getMemoryRange()[I] + Id[I];
10891089
// We've already adjusted for the accessor's offset in the __init, so
10901090
// don't include it here in case of device.
@@ -1147,7 +1147,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
11471147
void __init(ConcreteASPtrType Ptr, range<AdjustedDim> AccessRange,
11481148
range<AdjustedDim> MemRange, id<AdjustedDim> Offset) {
11491149
MData = Ptr;
1150-
detail::dim_loop<AdjustedDim>([&, this](size_t I) {
1150+
detail::loop<AdjustedDim>([&, this](size_t I) {
11511151
if constexpr (!(PropertyListT::template has_property<
11521152
sycl::ext::oneapi::property::no_offset>())) {
11531153
getOffset()[I] = Offset[I];
@@ -2252,7 +2252,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
22522252
#ifdef __SYCL_DEVICE_ONLY__
22532253
size_t getTotalOffset() const noexcept {
22542254
size_t TotalOffset = 0;
2255-
detail::dim_loop<Dimensions>([&, this](size_t I) {
2255+
detail::loop<Dimensions>([&, this](size_t I) {
22562256
TotalOffset = TotalOffset * impl.MemRange[I];
22572257
if constexpr (!(PropertyListT::template has_property<
22582258
sycl::ext::oneapi::property::no_offset>())) {
@@ -2515,7 +2515,7 @@ class __SYCL_SPECIAL_CLASS local_accessor_base :
25152515
void __init(ConcreteASPtrType Ptr, range<AdjustedDim> AccessRange,
25162516
range<AdjustedDim>, id<AdjustedDim>) {
25172517
MData = Ptr;
2518-
detail::dim_loop<AdjustedDim>(
2518+
detail::loop<AdjustedDim>(
25192519
[&, this](size_t I) { getSize()[I] = AccessRange[I]; });
25202520
}
25212521

@@ -2570,7 +2570,7 @@ class __SYCL_SPECIAL_CLASS local_accessor_base :
25702570
// Method which calculates linear offset for the ID using Range and Offset.
25712571
template <int Dims = AdjustedDim> size_t getLinearIndex(id<Dims> Id) const {
25722572
size_t Result = 0;
2573-
detail::dim_loop<Dims>(
2573+
detail::loop<Dims>(
25742574
[&, this](size_t I) { Result = Result * getSize()[I] + Id[I]; });
25752575
return Result;
25762576
}

sycl/include/sycl/detail/helpers.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ getSPIRVMemorySemanticsMask(const access::fence_space AccessSpace,
241241

242242
// To ensure loop unrolling is done when processing dimensions.
243243
template <size_t... Inds, class F>
244-
void dim_loop_impl(std::integer_sequence<size_t, Inds...>, F &&f) {
245-
(f(Inds), ...);
244+
void loop_impl(std::integer_sequence<size_t, Inds...>, F &&f) {
245+
(f(std::integral_constant<size_t, Inds>{}), ...);
246246
}
247247

248-
template <size_t count, class F> void dim_loop(F &&f) {
249-
dim_loop_impl(std::make_index_sequence<count>{}, std::forward<F>(f));
248+
template <size_t count, class F> void loop(F &&f) {
249+
loop_impl(std::make_index_sequence<count>{}, std::forward<F>(f));
250250
}
251251

252252
} // namespace detail

sycl/include/sycl/group_algorithm.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ reduce_over_group(Group g, sycl::vec<T, N> x, BinaryOperation binary_op) {
253253
"Result type of binary_op must match reduction accumulation type.");
254254
sycl::vec<T, N> result;
255255

256-
detail::dim_loop<N>(
256+
detail::loop<N>(
257257
[&](size_t s) { result[s] = reduce_over_group(g, x[s], binary_op); });
258258
return result;
259259
}

0 commit comments

Comments
 (0)