Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
23 changes: 21 additions & 2 deletions sycl/include/CL/sycl/detail/defines_elementary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@
#endif
#endif // __SYCL_FALLTHROUGH

// Stringify an argument to pass it in _Pragma directive below.
#ifndef __STRINGIFY
#define __STRINGIFY(x) #x

Comment thread
MrSidims marked this conversation as resolved.
// define __SYCL_WARNING convenience macro to report compiler warnings
#if defined(__GNUC__)
#define __SYCL_GCC_PRAGMA(x) _Pragma(#x)
#define __SYCL_WARNING(msg) __SYCL_GCC_PRAGMA(GCC warning msg)
#define __SYCL_WARNING(msg) _Pragma(__STRINGIFY(GCC warning msg))
#elif defined(_MSC_VER) && !defined(__clang__)
#define __SYCL_QUOTE1(x) #x
#define __SYCL_QUOTE(x) __SYCL_QUOTE1(x)
Expand All @@ -100,3 +103,19 @@
// clang emits "warning:" in the message pragma output
#define __SYCL_WARNING(msg) __pragma(message(msg))
#endif // __GNUC__

// Define __SYCL_UNROLL to add pragma/attribute unroll to a loop.
#ifndef __SYCL_UNROLL
#if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
#define __SYCL_UNROLL(x) _Pragma(__STRINGIFY(unroll x))
#elif defined(__clang__)
#define __SYCL_UNROLL(x) _Pragma(__STRINGIFY(unroll x))
#elif (defined(__GNUC__) && __GNUC__ >= 8) || \
(defined(__GNUG__) && __GNUG__ >= 8)
#define __SYCL_UNROLL(x) _Pragma(__STRINGIFY(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


#endif // __STRINGIFY