From 8ac7b4770a4094d2c0da867da7da8b4f33133eb7 Mon Sep 17 00:00:00 2001 From: Sergey Kanaev Date: Wed, 17 Mar 2021 20:36:39 +0300 Subject: [PATCH 1/8] [SYCL] Fix build when DISABLE_SYCL_INSTRUMENTATION_METADATA is defined Signed-off-by: Sergey Kanaev --- sycl/include/CL/sycl/queue.hpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sycl/include/CL/sycl/queue.hpp b/sycl/include/CL/sycl/queue.hpp index a1c49a05043be..1d8952cb3aa3f 100644 --- a/sycl/include/CL/sycl/queue.hpp +++ b/sycl/include/CL/sycl/queue.hpp @@ -236,7 +236,11 @@ class __SYCL_EXPORT queue { #ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA const detail::code_location &CodeLoc = {}; #endif - return submit([=](handler &CGH) { CGH.barrier(); }, CodeLoc); + return submit([=](handler &CGH) { CGH.barrier(); } +#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA + , CodeLoc +#endif + ); } /// Prevents any commands submitted afterward to this queue from executing @@ -258,7 +262,11 @@ class __SYCL_EXPORT queue { #ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA const detail::code_location &CodeLoc = {}; #endif - return submit([=](handler &CGH) { CGH.barrier(WaitList); }, CodeLoc); + return submit([=](handler &CGH) { CGH.barrier(WaitList); } +#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA + , CodeLoc +#endif + ); } /// Performs a blocking wait for the completion of all enqueued tasks in the From b9f69262e3b83cf2eb700c3fddf845a27bc2a7a2 Mon Sep 17 00:00:00 2001 From: Sergey Kanaev Date: Fri, 19 Mar 2021 12:27:47 +0300 Subject: [PATCH 2/8] Address review comment Signed-off-by: Sergey Kanaev --- sycl/include/CL/sycl/queue.hpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/sycl/include/CL/sycl/queue.hpp b/sycl/include/CL/sycl/queue.hpp index 1d8952cb3aa3f..df5924dd94a09 100644 --- a/sycl/include/CL/sycl/queue.hpp +++ b/sycl/include/CL/sycl/queue.hpp @@ -233,9 +233,6 @@ class __SYCL_EXPORT queue { const detail::code_location &CodeLoc = detail::code_location::current() #endif ) { -#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA - const detail::code_location &CodeLoc = {}; -#endif return submit([=](handler &CGH) { CGH.barrier(); } #ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA , CodeLoc @@ -259,9 +256,6 @@ class __SYCL_EXPORT queue { const detail::code_location &CodeLoc = detail::code_location::current() #endif ) { -#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA - const detail::code_location &CodeLoc = {}; -#endif return submit([=](handler &CGH) { CGH.barrier(WaitList); } #ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA , CodeLoc From e43c0a3fd48452ef7226bdef3ca7658d9a75287d Mon Sep 17 00:00:00 2001 From: Sergey Kanaev Date: Tue, 23 Mar 2021 15:26:21 +0300 Subject: [PATCH 3/8] [NFC] [SYCL] Make code a bit cleaner when using DISABLE_SYCL_INSTRUMENTATION_METADATA Signed-off-by: Sergey Kanaev --- sycl/include/CL/sycl/queue.hpp | 135 ++++++++++++--------------------- 1 file changed, 50 insertions(+), 85 deletions(-) diff --git a/sycl/include/CL/sycl/queue.hpp b/sycl/include/CL/sycl/queue.hpp index df5924dd94a09..e23fd119d7f1e 100644 --- a/sycl/include/CL/sycl/queue.hpp +++ b/sycl/include/CL/sycl/queue.hpp @@ -22,6 +22,39 @@ #include +// having _TWO_ mid-param #ifdefs makes the functions very difficult to read. +// Here we simplify the &CodeLoc declaration to be _CODELOCPARAM(&CodeLoc) and +// _CODELOCARG(&CodeLoc) Similarly, the KernelFunc param is simplified to be +// _KERNELFUNCPARAM(KernelFunc) Once the queue kernel functions are defined, +// these macros are #undef immediately. + +// replace _CODELOCPARAM(&CodeLoc) with nothing +// or : , const detail::code_location &CodeLoc = +// detail::code_location::current() +// replace _CODELOCARG(&CodeLoc) with nothing +// or : const detail::code_location &CodeLoc = {} + +#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA +#define _CODELOCPARAM(a) \ + , const detail::code_location a = detail::code_location::current() + +#define _CODELOCARG(a) +#define _CODELOCFW(a) , a +#else +#define _CODELOCPARAM(a) + +#define _CODELOCARG(a) const detail::code_location a = {} +#define _CODELOCFW(a) +#endif + +// replace _KERNELFUNCPARAM(KernelFunc) with KernelType KernelFunc +// or const KernelType &KernelFunc +#ifdef __SYCL_NONCONST_FUNCTOR__ +#define _KERNELFUNCPARAM(a) KernelType a +#else +#define _KERNELFUNCPARAM(a) const KernelType &a +#endif + __SYCL_INLINE_NAMESPACE(cl) { namespace sycl { @@ -184,15 +217,9 @@ class __SYCL_EXPORT queue { /// \return a SYCL event object for the submitted command group. template event - submit(T CGF -#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA - , - const detail::code_location &CodeLoc = detail::code_location::current() -#endif - ) { -#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA - const detail::code_location &CodeLoc = {}; -#endif + submit(T CGF _CODELOCPARAM(&CodeLoc)) { + _CODELOCARG(&CodeLoc); + return submit_impl(CGF, CodeLoc); } @@ -209,15 +236,9 @@ class __SYCL_EXPORT queue { /// group is being enqueued on. template event - submit(T CGF, queue &SecondaryQueue -#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA - , - const detail::code_location &CodeLoc = detail::code_location::current() -#endif - ) { -#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA - const detail::code_location &CodeLoc = {}; -#endif + submit(T CGF, queue &SecondaryQueue _CODELOCPARAM(&CodeLoc)) { + _CODELOCARG(&CodeLoc); + return submit_impl(CGF, SecondaryQueue, CodeLoc); } @@ -228,16 +249,8 @@ class __SYCL_EXPORT queue { /// \param CodeLoc is the code location of the submit call (default argument) /// \return a SYCL event object, which corresponds to the queue the command /// group is being enqueued on. - event submit_barrier( -#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA - const detail::code_location &CodeLoc = detail::code_location::current() -#endif - ) { - return submit([=](handler &CGH) { CGH.barrier(); } -#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA - , CodeLoc -#endif - ); + event submit_barrier(_CODELOCPARAM(&CodeLoc)) { + return submit([=](handler &CGH) { CGH.barrier(); } _CODELOCFW(CodeLoc)); } /// Prevents any commands submitted afterward to this queue from executing @@ -249,18 +262,10 @@ class __SYCL_EXPORT queue { /// \param CodeLoc is the code location of the submit call (default argument) /// \return a SYCL event object, which corresponds to the queue the command /// group is being enqueued on. - event submit_barrier( - const vector_class &WaitList -#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA - , - const detail::code_location &CodeLoc = detail::code_location::current() -#endif - ) { + event submit_barrier(const vector_class &WaitList + _CODELOCPARAM(&CodeLoc)) { return submit([=](handler &CGH) { CGH.barrier(WaitList); } -#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA - , CodeLoc -#endif - ); + _CODELOCFW(CodeLoc)); } /// Performs a blocking wait for the completion of all enqueued tasks in the @@ -268,14 +273,9 @@ class __SYCL_EXPORT queue { /// /// Synchronous errors will be reported through SYCL exceptions. /// @param CodeLoc is the code location of the submit call (default argument) - void wait( -#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA - const detail::code_location &CodeLoc = detail::code_location::current() -#endif - ) { -#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA - const detail::code_location &CodeLoc = {}; -#endif + void wait(_CODELOCPARAM(&CodeLoc)) { + _CODELOCARG(&CodeLoc) + wait_proxy(CodeLoc); } @@ -287,14 +287,9 @@ class __SYCL_EXPORT queue { /// construction. If no async_handler was provided then asynchronous /// exceptions will be lost. /// @param CodeLoc is the code location of the submit call (default argument) - void wait_and_throw( -#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA - const detail::code_location &CodeLoc = detail::code_location::current() -#endif - ) { -#ifdef DISABLE_SYCL_INSTRUMENTATION_METADATA - const detail::code_location &CodeLoc = {}; -#endif + void wait_and_throw(_CODELOCPARAM(&CodeLoc)) { + _CODELOCARG(&CodeLoc); + wait_and_throw_proxy(CodeLoc); } @@ -373,36 +368,6 @@ class __SYCL_EXPORT queue { return submit([=](handler &CGH) { CGH.prefetch(Ptr, Count); }); } - // having _TWO_ mid-param #ifdefs makes the functions very difficult to read. - // Here we simplify the &CodeLoc declaration to be _CODELOCPARAM(&CodeLoc) and - // _CODELOCARG(&CodeLoc) Similarly, the KernelFunc param is simplified to be - // _KERNELFUNCPARAM(KernelFunc) Once the queue kernel functions are defined, - // these macros are #undef immediately. - - // replace _CODELOCPARAM(&CodeLoc) with nothing - // or : , const detail::code_location &CodeLoc = - // detail::code_location::current() - // replace _CODELOCARG(&CodeLoc) with nothing - // or : const detail::code_location &CodeLoc = {} - -#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA -#define _CODELOCPARAM(a) \ - , const detail::code_location a = detail::code_location::current() - -#define _CODELOCARG(a) -#else -#define _CODELOCPARAM(a) - -#define _CODELOCARG(a) const detail::code_location a = {} -#endif -// replace _KERNELFUNCPARAM(KernelFunc) with KernelType KernelFunc -// or const KernelType &KernelFunc -#ifdef __SYCL_NONCONST_FUNCTOR__ -#define _KERNELFUNCPARAM(a) KernelType a -#else -#define _KERNELFUNCPARAM(a) const KernelType &a -#endif - /// single_task version with a kernel represented as a lambda. /// /// \param KernelFunc is the Kernel functor or lambda From c93c2f79d5676406b7b9f329d5d0a4b30c3acbd2 Mon Sep 17 00:00:00 2001 From: Sergey Kanaev Date: Tue, 23 Mar 2021 15:35:46 +0300 Subject: [PATCH 4/8] Address style issue Signed-off-by: Sergey Kanaev --- sycl/include/CL/sycl/queue.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sycl/include/CL/sycl/queue.hpp b/sycl/include/CL/sycl/queue.hpp index d9f6867481871..0f7fbd8dad727 100644 --- a/sycl/include/CL/sycl/queue.hpp +++ b/sycl/include/CL/sycl/queue.hpp @@ -262,9 +262,8 @@ class __SYCL_EXPORT queue { /// \param CodeLoc is the code location of the submit call (default argument) /// \return a SYCL event object, which corresponds to the queue the command /// group is being enqueued on. - event submit_barrier( - const vector_class &WaitList - _CODELOCPARAM(&CodeLoc)) { + event + submit_barrier(const vector_class &WaitList _CODELOCPARAM(&CodeLoc)) { return submit([=](handler &CGH) { CGH.barrier(WaitList); } _CODELOCFW(CodeLoc)); } From 7a5daf676dc6544b20eca0e572f05cd5570350c7 Mon Sep 17 00:00:00 2001 From: Sergey Kanaev Date: Tue, 23 Mar 2021 15:37:03 +0300 Subject: [PATCH 5/8] Address comment Signed-off-by: Sergey Kanaev --- sycl/include/CL/sycl/queue.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/sycl/include/CL/sycl/queue.hpp b/sycl/include/CL/sycl/queue.hpp index 0f7fbd8dad727..2f06d76e7dcf7 100644 --- a/sycl/include/CL/sycl/queue.hpp +++ b/sycl/include/CL/sycl/queue.hpp @@ -710,6 +710,7 @@ class __SYCL_EXPORT queue { // Clean up CODELOC and KERNELFUNC macros. #undef _CODELOCPARAM #undef _CODELOCARG +#undef _CODELOCFW #undef _KERNELFUNCPARAM /// Returns whether the queue is in order or OoO From ff0fccc07b86afbd06d0997c35b3231f39a1ed0f Mon Sep 17 00:00:00 2001 From: Sergey Kanaev Date: Tue, 23 Mar 2021 15:47:09 +0300 Subject: [PATCH 6/8] Address style issue Signed-off-by: Sergey Kanaev --- sycl/include/CL/sycl/queue.hpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/sycl/include/CL/sycl/queue.hpp b/sycl/include/CL/sycl/queue.hpp index 2f06d76e7dcf7..ca4020ecb70af 100644 --- a/sycl/include/CL/sycl/queue.hpp +++ b/sycl/include/CL/sycl/queue.hpp @@ -215,9 +215,7 @@ class __SYCL_EXPORT queue { /// \param CGF is a function object containing command group. /// \param CodeLoc is the code location of the submit call (default argument) /// \return a SYCL event object for the submitted command group. - template - event - submit(T CGF _CODELOCPARAM(&CodeLoc)) { + template event submit(T CGF _CODELOCPARAM(&CodeLoc)) { _CODELOCARG(&CodeLoc); return submit_impl(CGF, CodeLoc); @@ -235,8 +233,7 @@ class __SYCL_EXPORT queue { /// \return a SYCL event object, which corresponds to the queue the command /// group is being enqueued on. template - event - submit(T CGF, queue &SecondaryQueue _CODELOCPARAM(&CodeLoc)) { + event submit(T CGF, queue &SecondaryQueue _CODELOCPARAM(&CodeLoc)) { _CODELOCARG(&CodeLoc); return submit_impl(CGF, SecondaryQueue, CodeLoc); @@ -264,8 +261,8 @@ class __SYCL_EXPORT queue { /// group is being enqueued on. event submit_barrier(const vector_class &WaitList _CODELOCPARAM(&CodeLoc)) { - return submit([=](handler &CGH) { CGH.barrier(WaitList); } - _CODELOCFW(CodeLoc)); + return submit( + [=](handler &CGH) { CGH.barrier(WaitList); } _CODELOCFW(CodeLoc)); } /// Performs a blocking wait for the completion of all enqueued tasks in the From f7adad853ea36010d119b0c2fec9ce3c11377bb8 Mon Sep 17 00:00:00 2001 From: Sergey Kanaev Date: Tue, 23 Mar 2021 15:51:06 +0300 Subject: [PATCH 7/8] Address build issue Signed-off-by: Sergey Kanaev --- sycl/include/CL/sycl/queue.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sycl/include/CL/sycl/queue.hpp b/sycl/include/CL/sycl/queue.hpp index ca4020ecb70af..2a325b3135b22 100644 --- a/sycl/include/CL/sycl/queue.hpp +++ b/sycl/include/CL/sycl/queue.hpp @@ -35,6 +35,8 @@ // or : const detail::code_location &CodeLoc = {} #ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA +#define _CODELOCONLYPARAM(a) \ + const detail::code_location a = detail::code_location::current() #define _CODELOCPARAM(a) \ , const detail::code_location a = detail::code_location::current() @@ -246,7 +248,7 @@ class __SYCL_EXPORT queue { /// \param CodeLoc is the code location of the submit call (default argument) /// \return a SYCL event object, which corresponds to the queue the command /// group is being enqueued on. - event submit_barrier(_CODELOCPARAM(&CodeLoc)) { + event submit_barrier(_CODELOCONLYPARAM(&CodeLoc)) { return submit([=](handler &CGH) { CGH.barrier(); } _CODELOCFW(CodeLoc)); } @@ -270,7 +272,7 @@ class __SYCL_EXPORT queue { /// /// Synchronous errors will be reported through SYCL exceptions. /// @param CodeLoc is the code location of the submit call (default argument) - void wait(_CODELOCPARAM(&CodeLoc)) { + void wait(_CODELOCONLYPARAM(&CodeLoc)) { _CODELOCARG(&CodeLoc) wait_proxy(CodeLoc); @@ -284,7 +286,7 @@ class __SYCL_EXPORT queue { /// construction. If no async_handler was provided then asynchronous /// exceptions will be lost. /// @param CodeLoc is the code location of the submit call (default argument) - void wait_and_throw(_CODELOCPARAM(&CodeLoc)) { + void wait_and_throw(_CODELOCONLYPARAM(&CodeLoc)) { _CODELOCARG(&CodeLoc); wait_and_throw_proxy(CodeLoc); @@ -706,6 +708,7 @@ class __SYCL_EXPORT queue { // Clean up CODELOC and KERNELFUNC macros. #undef _CODELOCPARAM +#undef _CODELOCONLYPARAM #undef _CODELOCARG #undef _CODELOCFW #undef _KERNELFUNCPARAM From 8d986a3486283afd8324f585ba6a638518449713 Mon Sep 17 00:00:00 2001 From: Sergey Kanaev Date: Thu, 25 Mar 2021 13:52:16 +0300 Subject: [PATCH 8/8] Address review comment Signed-off-by: Sergey Kanaev --- sycl/include/CL/sycl/queue.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/sycl/include/CL/sycl/queue.hpp b/sycl/include/CL/sycl/queue.hpp index 2a325b3135b22..2e01a1fecb1b2 100644 --- a/sycl/include/CL/sycl/queue.hpp +++ b/sycl/include/CL/sycl/queue.hpp @@ -43,6 +43,7 @@ #define _CODELOCARG(a) #define _CODELOCFW(a) , a #else +#define _CODELOCONLYPARAM(a) #define _CODELOCPARAM(a) #define _CODELOCARG(a) const detail::code_location a = {}