Skip to content

[SYCL] Unroll local accessor index calculation #8755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sycl/include/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2522,8 +2522,8 @@ class __SYCL_SPECIAL_CLASS local_accessor_base :
// Method which calculates linear offset for the ID using Range and Offset.
template <int Dims = AdjustedDim> size_t getLinearIndex(id<Dims> Id) const {
size_t Result = 0;
for (int I = 0; I < Dims; ++I)
Result = Result * getSize()[I] + Id[I];
detail::dim_loop<Dims>(
[&, this](size_t I) { Result = Result * getSize()[I] + Id[I]; });
return Result;
}

Expand Down
17 changes: 17 additions & 0 deletions sycl/test/check_device_code/accessor_index.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %clangxx -fsycl-device-only -fno-sycl-early-optimizations -S -emit-llvm -D__SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__ -o - %s | FileCheck %s
#include <sycl/sycl.hpp>

// Check that accessor index calculation is unrolled in headers.
// CHECK-NOT: llvm.loop
// CHECK-NOT: br i1
using namespace sycl;
int main() {
queue Q;
range<3> Range{8, 8, 8};
buffer<int, 3> Buf(Range);
Q.submit([&](handler &Cgh) {
auto Acc = Buf.get_access<access::mode::write>(Cgh);
local_accessor<int, 3> LocAcc(Range, Cgh);
Cgh.parallel_for(Range, [=](item<3> It) { LocAcc[It] = Acc[It]; });
});
}