Skip to content

Commit b07cc12

Browse files
[SYCL] Unroll local accessor index calculation (#8755)
Aligns local accessor index calculation with the other accessors.
1 parent e09ff58 commit b07cc12

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,8 +2523,8 @@ class __SYCL_SPECIAL_CLASS local_accessor_base :
25232523
// Method which calculates linear offset for the ID using Range and Offset.
25242524
template <int Dims = AdjustedDim> size_t getLinearIndex(id<Dims> Id) const {
25252525
size_t Result = 0;
2526-
for (int I = 0; I < Dims; ++I)
2527-
Result = Result * getSize()[I] + Id[I];
2526+
detail::dim_loop<Dims>(
2527+
[&, this](size_t I) { Result = Result * getSize()[I] + Id[I]; });
25282528
return Result;
25292529
}
25302530

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clangxx -fsycl-device-only -fno-sycl-early-optimizations -S -emit-llvm -D__SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__ -o - %s | FileCheck %s
2+
#include <sycl/sycl.hpp>
3+
4+
// Check that accessor index calculation is unrolled in headers.
5+
// CHECK-NOT: llvm.loop
6+
// CHECK-NOT: br i1
7+
using namespace sycl;
8+
int main() {
9+
queue Q;
10+
range<3> Range{8, 8, 8};
11+
buffer<int, 3> Buf(Range);
12+
Q.submit([&](handler &Cgh) {
13+
auto Acc = Buf.get_access<access::mode::write>(Cgh);
14+
local_accessor<int, 3> LocAcc(Range, Cgh);
15+
Cgh.parallel_for(Range, [=](item<3> It) { LocAcc[It] = Acc[It]; });
16+
});
17+
}

0 commit comments

Comments
 (0)