Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions sycl/include/CL/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,8 @@ class accessor :
#endif // __SYCL_DEVICE_ONLY__

size_t Result = 0;
// Unroll the following loop for both host and device code
__SYCL_UNROLL(3)
for (int I = 0; I < Dims; ++I)
Result = Result * getMemoryRange()[I] + getOffset()[I] + Id[I];
return Result;
Expand Down
12 changes: 12 additions & 0 deletions sycl/include/CL/sycl/detail/defines_elementary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,15 @@
// clang emits "warning:" in the message pragma output
#define __SYCL_WARNING(msg) __pragma(message(msg))
#endif // __GNUC__

// defined __SYCL_UNROLL to add pragma/attribute unroll to a loop
Comment thread
MrSidims marked this conversation as resolved.
Outdated
#ifndef __SYCL_UNROLL
#if defined(__clang__) || defined(__INTEL_COMPILER)
#define __SYCL_UNROLL(x) _Pragma(unroll (x))
#elif (defined(__GNUC__) && __GNUC__ >= 8) || \
(defined(__GNUG__) && __GNUG__ >= 8)
#define __SYCL_UNROLL(x) _Pragma(GCC unroll (x))
#else
#define __SYCL_UNROLL(x)
#endif // compiler switch
#endif // __SYCL_UNROLL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While looking at this I wonder why just using a metaprogrammed loop instead is not better than this pragmatic spaghetti plate.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also works with one-iteration loops, unlike this pragma-based solution: #6560