From d560cf77a7b7aff8a90499339cf23ffb4772a64e Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Mon, 16 Aug 2021 14:37:09 +0300 Subject: [PATCH 01/11] [NFC][SYCL] Add pragma unroll in accessor.hpp It shall improve performance on various targets in case if we have 3 dimensional calculations within nested loops. Signed-off-by: Dmitry Sidorov --- sycl/include/CL/sycl/accessor.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/sycl/include/CL/sycl/accessor.hpp b/sycl/include/CL/sycl/accessor.hpp index d54c43b6a4811..ffd9e2bc40c9f 100755 --- a/sycl/include/CL/sycl/accessor.hpp +++ b/sycl/include/CL/sycl/accessor.hpp @@ -834,6 +834,7 @@ class accessor : #endif // __SYCL_DEVICE_ONLY__ size_t Result = 0; +#pragma unroll for (int I = 0; I < Dims; ++I) Result = Result * getMemoryRange()[I] + getOffset()[I] + Id[I]; return Result; From 3cdd2a48d4347088f0d77d469866db35b4caf7fd Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Wed, 18 Aug 2021 21:36:28 +0300 Subject: [PATCH 02/11] unroll multiverse Signed-off-by: Dmitry Sidorov --- sycl/include/CL/sycl/accessor.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sycl/include/CL/sycl/accessor.hpp b/sycl/include/CL/sycl/accessor.hpp index ffd9e2bc40c9f..f315e8ee66dba 100755 --- a/sycl/include/CL/sycl/accessor.hpp +++ b/sycl/include/CL/sycl/accessor.hpp @@ -834,7 +834,14 @@ class accessor : #endif // __SYCL_DEVICE_ONLY__ size_t Result = 0; -#pragma unroll + // Unroll the following loop for both host and device code +#if defined (__clang__) || defined (__INTEL_COMPILER) + #pragma unroll +#elif defined (__GNUC__) || defined (__GNUG__) + #pragma GCC unroll 3 +#elif defined (_MSC_VER) + // MSVC pragma loop don't have unroll option +#endif // switch over the compilers is over for (int I = 0; I < Dims; ++I) Result = Result * getMemoryRange()[I] + getOffset()[I] + Id[I]; return Result; From 309995ef4289f9b5254aee1e4367491a8cc00a1b Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Wed, 18 Aug 2021 21:41:07 +0300 Subject: [PATCH 03/11] Clang-format + grammar Signed-off-by: Dmitry Sidorov --- sycl/include/CL/sycl/accessor.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sycl/include/CL/sycl/accessor.hpp b/sycl/include/CL/sycl/accessor.hpp index f315e8ee66dba..14384cd75b0c5 100755 --- a/sycl/include/CL/sycl/accessor.hpp +++ b/sycl/include/CL/sycl/accessor.hpp @@ -835,12 +835,12 @@ class accessor : size_t Result = 0; // Unroll the following loop for both host and device code -#if defined (__clang__) || defined (__INTEL_COMPILER) - #pragma unroll -#elif defined (__GNUC__) || defined (__GNUG__) - #pragma GCC unroll 3 -#elif defined (_MSC_VER) - // MSVC pragma loop don't have unroll option +#if defined(__clang__) || defined(__INTEL_COMPILER) +#pragma unroll +#elif defined(__GNUC__) || defined(__GNUG__) +#pragma GCC unroll 3 +#elif defined(_MSC_VER) + // MSVC pragma loop doesn't have unroll option #endif // switch over the compilers is over for (int I = 0; I < Dims; ++I) Result = Result * getMemoryRange()[I] + getOffset()[I] + Id[I]; From 9074026388683cdf762678c8e4e9f61750da6708 Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Thu, 19 Aug 2021 11:04:25 +0300 Subject: [PATCH 04/11] Add GCC version check Signed-off-by: Dmitry Sidorov --- sycl/include/CL/sycl/accessor.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sycl/include/CL/sycl/accessor.hpp b/sycl/include/CL/sycl/accessor.hpp index 14384cd75b0c5..f62d6d65084d0 100755 --- a/sycl/include/CL/sycl/accessor.hpp +++ b/sycl/include/CL/sycl/accessor.hpp @@ -837,7 +837,8 @@ class accessor : // Unroll the following loop for both host and device code #if defined(__clang__) || defined(__INTEL_COMPILER) #pragma unroll -#elif defined(__GNUC__) || defined(__GNUG__) +#elif (defined(__GNUC__) && __GNUC__ >= 8) || \ + (defined(__GNUG__) && __GNUG__ >= 8) #pragma GCC unroll 3 #elif defined(_MSC_VER) // MSVC pragma loop doesn't have unroll option From 418dbe8efcfc541315db704fdc28963887ac48ed Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Thu, 19 Aug 2021 11:36:47 +0300 Subject: [PATCH 05/11] Move to defines_elementary.hpp Signed-off-by: Dmitry Sidorov --- sycl/include/CL/sycl/accessor.hpp | 9 +-------- sycl/include/CL/sycl/detail/defines_elementary.hpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/sycl/include/CL/sycl/accessor.hpp b/sycl/include/CL/sycl/accessor.hpp index f62d6d65084d0..5bad3b36e1ede 100755 --- a/sycl/include/CL/sycl/accessor.hpp +++ b/sycl/include/CL/sycl/accessor.hpp @@ -835,14 +835,7 @@ class accessor : size_t Result = 0; // Unroll the following loop for both host and device code -#if defined(__clang__) || defined(__INTEL_COMPILER) -#pragma unroll -#elif (defined(__GNUC__) && __GNUC__ >= 8) || \ - (defined(__GNUG__) && __GNUG__ >= 8) -#pragma GCC unroll 3 -#elif defined(_MSC_VER) - // MSVC pragma loop doesn't have unroll option -#endif // switch over the compilers is over + __SYCL_UNROLL(3) for (int I = 0; I < Dims; ++I) Result = Result * getMemoryRange()[I] + getOffset()[I] + Id[I]; return Result; diff --git a/sycl/include/CL/sycl/detail/defines_elementary.hpp b/sycl/include/CL/sycl/detail/defines_elementary.hpp index f7168c35dfcde..2218f3d800f14 100644 --- a/sycl/include/CL/sycl/detail/defines_elementary.hpp +++ b/sycl/include/CL/sycl/detail/defines_elementary.hpp @@ -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 +#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 From 699c560989d69f76d6a23ed24e92b10fb8e6afe2 Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Thu, 19 Aug 2021 12:11:14 +0300 Subject: [PATCH 06/11] Fix clang-format Signed-off-by: Dmitry Sidorov --- sycl/include/CL/sycl/detail/defines_elementary.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sycl/include/CL/sycl/detail/defines_elementary.hpp b/sycl/include/CL/sycl/detail/defines_elementary.hpp index 2218f3d800f14..e7aee85bddf95 100644 --- a/sycl/include/CL/sycl/detail/defines_elementary.hpp +++ b/sycl/include/CL/sycl/detail/defines_elementary.hpp @@ -104,10 +104,10 @@ // defined __SYCL_UNROLL to add pragma/attribute unroll to a loop #ifndef __SYCL_UNROLL #if defined(__clang__) || defined(__INTEL_COMPILER) -#define __SYCL_UNROLL(x) _Pragma(unroll (x)) -#elif (defined(__GNUC__) && __GNUC__ >= 8) || \ +#define __SYCL_UNROLL(x) _Pragma(unroll(x)) +#elif (defined(__GNUC__) && __GNUC__ >= 8) || \ (defined(__GNUG__) && __GNUG__ >= 8) -#define __SYCL_UNROLL(x) _Pragma(GCC unroll (x)) +#define __SYCL_UNROLL(x) _Pragma(GCC unroll(x)) #else #define __SYCL_UNROLL(x) #endif // compiler switch From 04aabf70582592d1ce8452998be16d2d6ffe866f Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Thu, 19 Aug 2021 13:46:59 +0300 Subject: [PATCH 07/11] This should work (or at least it worked on compiler explorer) Signed-off-by: Dmitry Sidorov --- sycl/include/CL/sycl/detail/defines_elementary.hpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sycl/include/CL/sycl/detail/defines_elementary.hpp b/sycl/include/CL/sycl/detail/defines_elementary.hpp index e7aee85bddf95..8b01fa6b6ed6b 100644 --- a/sycl/include/CL/sycl/detail/defines_elementary.hpp +++ b/sycl/include/CL/sycl/detail/defines_elementary.hpp @@ -103,11 +103,16 @@ // defined __SYCL_UNROLL to add pragma/attribute unroll to a loop #ifndef __SYCL_UNROLL -#if defined(__clang__) || defined(__INTEL_COMPILER) -#define __SYCL_UNROLL(x) _Pragma(unroll(x)) +#if defined(__clang__) +#define STRINGIFY(x) #x +#define __SYCL_UNROLL(x) _Pragma(STRINGIFY(unroll_count x)) +#elif defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER) +#define STRINGIFY(x) #x +#define __SYCL_UNROLL(x) _Pragma(STRINGIFY(unroll x)) #elif (defined(__GNUC__) && __GNUC__ >= 8) || \ (defined(__GNUG__) && __GNUG__ >= 8) -#define __SYCL_UNROLL(x) _Pragma(GCC unroll(x)) +#define STRINGIFY(x) #x +#define __SYCL_UNROLL(x) _Pragma(STRINGIFY(GCC unroll x)) #else #define __SYCL_UNROLL(x) #endif // compiler switch From 63623fe6370e2e46d737d9afe7edf538d52774a0 Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Thu, 19 Aug 2021 14:05:58 +0300 Subject: [PATCH 08/11] Move STRINGIFY Signed-off-by: Dmitry Sidorov --- sycl/include/CL/sycl/detail/defines_elementary.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sycl/include/CL/sycl/detail/defines_elementary.hpp b/sycl/include/CL/sycl/detail/defines_elementary.hpp index 8b01fa6b6ed6b..72b21f525ffd3 100644 --- a/sycl/include/CL/sycl/detail/defines_elementary.hpp +++ b/sycl/include/CL/sycl/detail/defines_elementary.hpp @@ -8,6 +8,9 @@ #pragma once +#ifndef STRINGIFY +#define STRINGIFY(x) #x + #ifndef __SYCL_DISABLE_NAMESPACE_INLINE__ #define __SYCL_INLINE_NAMESPACE(X) inline namespace X #else @@ -89,8 +92,7 @@ // 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) @@ -104,16 +106,15 @@ // defined __SYCL_UNROLL to add pragma/attribute unroll to a loop #ifndef __SYCL_UNROLL #if defined(__clang__) -#define STRINGIFY(x) #x #define __SYCL_UNROLL(x) _Pragma(STRINGIFY(unroll_count x)) #elif defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER) -#define STRINGIFY(x) #x #define __SYCL_UNROLL(x) _Pragma(STRINGIFY(unroll x)) #elif (defined(__GNUC__) && __GNUC__ >= 8) || \ (defined(__GNUG__) && __GNUG__ >= 8) -#define STRINGIFY(x) #x #define __SYCL_UNROLL(x) _Pragma(STRINGIFY(GCC unroll x)) #else #define __SYCL_UNROLL(x) #endif // compiler switch #endif // __SYCL_UNROLL + +#endif // STRINGIFY From 8419b4868dbcb75ed88bc90145e2c32f30d1a517 Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Thu, 19 Aug 2021 20:46:50 +0300 Subject: [PATCH 09/11] Apply suggestions Signed-off-by: Dmitry Sidorov --- .../CL/sycl/detail/defines_elementary.hpp | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/sycl/include/CL/sycl/detail/defines_elementary.hpp b/sycl/include/CL/sycl/detail/defines_elementary.hpp index 72b21f525ffd3..7d96c546b910b 100644 --- a/sycl/include/CL/sycl/detail/defines_elementary.hpp +++ b/sycl/include/CL/sycl/detail/defines_elementary.hpp @@ -8,9 +8,6 @@ #pragma once -#ifndef STRINGIFY -#define STRINGIFY(x) #x - #ifndef __SYCL_DISABLE_NAMESPACE_INLINE__ #define __SYCL_INLINE_NAMESPACE(X) inline namespace X #else @@ -90,9 +87,13 @@ #endif #endif // __SYCL_FALLTHROUGH +// Stringify an argument to pass it in _Pragma directive below. +#ifndef __STRINGIFY +#define __STRINGIFY(x) #x + // define __SYCL_WARNING convenience macro to report compiler warnings #if defined(__GNUC__) -#define __SYCL_WARNING(msg) _Pragma(STRINGIFY(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) @@ -103,18 +104,18 @@ #define __SYCL_WARNING(msg) __pragma(message(msg)) #endif // __GNUC__ -// defined __SYCL_UNROLL to add pragma/attribute unroll to a loop +// Define __SYCL_UNROLL to add pragma/attribute unroll to a loop. #ifndef __SYCL_UNROLL -#if defined(__clang__) -#define __SYCL_UNROLL(x) _Pragma(STRINGIFY(unroll_count x)) -#elif defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER) -#define __SYCL_UNROLL(x) _Pragma(STRINGIFY(unroll x)) +#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)) +#define __SYCL_UNROLL(x) _Pragma(__STRINGIFY(GCC unroll x)) #else #define __SYCL_UNROLL(x) #endif // compiler switch #endif // __SYCL_UNROLL -#endif // STRINGIFY +#endif // __STRINGIFY From e9d4e642cb1f977af4c96bd87c2e24a617538c4b Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Tue, 24 Aug 2021 17:21:19 +0300 Subject: [PATCH 10/11] __STRINGIFY -> __SYCL_STRINGIFY and propagate it Signed-off-by: Dmitry Sidorov --- sycl/include/CL/sycl/detail/common.hpp | 8 +++----- .../include/CL/sycl/detail/defines_elementary.hpp | 15 +++++++-------- sycl/source/detail/config.cpp | 5 +++-- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/sycl/include/CL/sycl/detail/common.hpp b/sycl/include/CL/sycl/detail/common.hpp index 8cb2e3ab384a0..c4592a475b1cd 100644 --- a/sycl/include/CL/sycl/detail/common.hpp +++ b/sycl/include/CL/sycl/detail/common.hpp @@ -10,15 +10,13 @@ #include #include +#include #include #include #include #include -#define __SYCL_STRINGIFY_LINE_HELP(s) #s -#define __SYCL_STRINGIFY_LINE(s) __SYCL_STRINGIFY_LINE_HELP(s) - // Default signature enables the passing of user code location information to // public methods as a default argument. If the end-user wants to disable the // code location information, they must compile the code with @@ -106,8 +104,8 @@ static inline std::string codeToString(cl_int code) { #define __SYCL_OCL_ERROR_REPORT \ "Native API failed. " /*__FILE__*/ \ /* TODO: replace __FILE__ to report only relative path*/ \ - /* ":" __SYCL_STRINGIFY_LINE(__LINE__) ": " */ \ - "Native API returns: " + /* ":" __SYCL_STRINGIFY(__LINE__) ": " */ \ + "Native API returns: " #ifndef __SYCL_SUPPRESS_OCL_ERROR_REPORT #include diff --git a/sycl/include/CL/sycl/detail/defines_elementary.hpp b/sycl/include/CL/sycl/detail/defines_elementary.hpp index 7d96c546b910b..ac967fec2edea 100644 --- a/sycl/include/CL/sycl/detail/defines_elementary.hpp +++ b/sycl/include/CL/sycl/detail/defines_elementary.hpp @@ -88,12 +88,13 @@ #endif // __SYCL_FALLTHROUGH // Stringify an argument to pass it in _Pragma directive below. -#ifndef __STRINGIFY -#define __STRINGIFY(x) #x +#ifndef __SYCL_STRINGIFY +#define __SYCL_STRINGIFY(x) #x +#endif // __SYCL_STRINGIFY // define __SYCL_WARNING convenience macro to report compiler warnings #if defined(__GNUC__) -#define __SYCL_WARNING(msg) _Pragma(__STRINGIFY(GCC warning msg)) +#define __SYCL_WARNING(msg) _Pragma(__SYCL_STRINGIFY(GCC warning msg)) #elif defined(_MSC_VER) && !defined(__clang__) #define __SYCL_QUOTE1(x) #x #define __SYCL_QUOTE(x) __SYCL_QUOTE1(x) @@ -107,15 +108,13 @@ // 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)) +#define __SYCL_UNROLL(x) _Pragma(__SYCL_STRINGIFY(unroll x)) #elif defined(__clang__) -#define __SYCL_UNROLL(x) _Pragma(__STRINGIFY(unroll x)) +#define __SYCL_UNROLL(x) _Pragma(__SYCL_STRINGIFY(unroll x)) #elif (defined(__GNUC__) && __GNUC__ >= 8) || \ (defined(__GNUG__) && __GNUG__ >= 8) -#define __SYCL_UNROLL(x) _Pragma(__STRINGIFY(GCC unroll x)) +#define __SYCL_UNROLL(x) _Pragma(__SYCL_STRINGIFY(GCC unroll x)) #else #define __SYCL_UNROLL(x) #endif // compiler switch #endif // __SYCL_UNROLL - -#endif // __STRINGIFY diff --git a/sycl/source/detail/config.cpp b/sycl/source/detail/config.cpp index 9a9f4963803c1..bf784398bd154 100644 --- a/sycl/source/detail/config.cpp +++ b/sycl/source/detail/config.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include +#include #include #include @@ -27,9 +28,9 @@ namespace detail { const char *SYCLConfigBase::MValueFromFile = nullptr; \ char SYCLConfigBase::MStorage[MaxSize + 1]; \ const char *const SYCLConfigBase::MCompileTimeDef = \ - getStrOrNullptr(__SYCL_STRINGIFY_LINE(CompileTimeDef)); \ + getStrOrNullptr(__SYCL_STRINGIFY(CompileTimeDef)); \ const char *const SYCLConfigBase::MConfigName = \ - __SYCL_STRINGIFY_LINE(Name); + __SYCL_STRINGIFY(Name); #include "detail/config.def" #undef CONFIG From 2d80f2d045bc0f339d065a3d069d4a0a5aca95c8 Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Tue, 24 Aug 2021 17:28:01 +0300 Subject: [PATCH 11/11] clang-format Signed-off-by: Dmitry Sidorov --- sycl/source/detail/config.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sycl/source/detail/config.cpp b/sycl/source/detail/config.cpp index bf784398bd154..8dab8a598149a 100644 --- a/sycl/source/detail/config.cpp +++ b/sycl/source/detail/config.cpp @@ -29,8 +29,7 @@ namespace detail { char SYCLConfigBase::MStorage[MaxSize + 1]; \ const char *const SYCLConfigBase::MCompileTimeDef = \ getStrOrNullptr(__SYCL_STRINGIFY(CompileTimeDef)); \ - const char *const SYCLConfigBase::MConfigName = \ - __SYCL_STRINGIFY(Name); + const char *const SYCLConfigBase::MConfigName = __SYCL_STRINGIFY(Name); #include "detail/config.def" #undef CONFIG