From 1e994a8c3cf3066410615b54b7a5b6208d27cea7 Mon Sep 17 00:00:00 2001 From: mdimakov Date: Mon, 24 May 2021 13:20:04 +0300 Subject: [PATCH 01/10] [SYCL] Added check for sycl version for empty cg Signed-off-by: mdimakov --- sycl/include/CL/sycl/handler.hpp | 13 +++++++++++++ sycl/source/handler.cpp | 19 ++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/sycl/include/CL/sycl/handler.hpp b/sycl/include/CL/sycl/handler.hpp index 4804d63c0123f..912c7affd464e 100644 --- a/sycl/include/CL/sycl/handler.hpp +++ b/sycl/include/CL/sycl/handler.hpp @@ -40,6 +40,19 @@ #define __SYCL_NONCONST_FUNCTOR__ #endif +#ifdef SYCL_LANGUAGE_VERSION +#define SYCL_STD_VERSION SYCL_LANGUAGE_VERSION +#else +#define SYCL_STD_VERSION 201707 +#endif + +enum Sycl_std_versions { + version_older_2020, + version_2020 +}; +const Sycl_std_versions sycl_ver = + SYCL_STD_VERSION < 202000 ? version_older_2020 : version_2020; + template diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index c7c1f6c06ab2c..7eae88e254dbd 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -202,17 +202,26 @@ event handler::finalize() { std::move(MRequirements), std::move(MEvents), MCGType, MCodeLoc)); break; case detail::CG::NONE: - throw runtime_error("Command group submitted without a kernel or a " + if (sycl_ver == version_older_2020) + throw runtime_error("Command group submitted without a kernel or a " "explicit memory operation.", PI_INVALID_OPERATION); + break; } - if (!CommandGroup) - throw sycl::runtime_error( + detail::EventImplPtr Event; + + if (!CommandGroup) { + if (getType() != detail::CG::NONE) + throw sycl::runtime_error( "Internal Error. Command group cannot be constructed.", PI_INVALID_OPERATION); - - detail::EventImplPtr Event = detail::Scheduler::getInstance().addCG( + else + // if no runtime error was throws it is empty cg from sycl2020 + Event = std::make_shared(); + } + else + Event = detail::Scheduler::getInstance().addCG( std::move(CommandGroup), std::move(MQueue)); MLastEvent = detail::createSyclObjFromImpl(Event); From f3ba4dec44e9ace76ee67106464fd0d91bfb6b0b Mon Sep 17 00:00:00 2001 From: mdimakov Date: Tue, 25 May 2021 14:19:41 +0300 Subject: [PATCH 02/10] Working draft --- sycl/include/CL/sycl/handler.hpp | 9 ++++----- sycl/source/handler.cpp | 2 ++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sycl/include/CL/sycl/handler.hpp b/sycl/include/CL/sycl/handler.hpp index 912c7affd464e..3cde329ecedda 100644 --- a/sycl/include/CL/sycl/handler.hpp +++ b/sycl/include/CL/sycl/handler.hpp @@ -40,18 +40,17 @@ #define __SYCL_NONCONST_FUNCTOR__ #endif -#ifdef SYCL_LANGUAGE_VERSION -#define SYCL_STD_VERSION SYCL_LANGUAGE_VERSION +#if SYCL_LANGUAGE_VERSION +#define __SYCL_STD_VERSION__ SYCL_LANGUAGE_VERSION #else -#define SYCL_STD_VERSION 201707 +#define __SYCL_STD_VERSION__ 201707 #endif enum Sycl_std_versions { version_older_2020, version_2020 }; -const Sycl_std_versions sycl_ver = - SYCL_STD_VERSION < 202000 ? version_older_2020 : version_2020; +extern Sycl_std_versions sycl_ver; template #include +Sycl_std_versions sycl_ver; + __SYCL_INLINE_NAMESPACE(cl) { namespace sycl { From bbc05609225bf94559def02758e71bca2c6bbd10 Mon Sep 17 00:00:00 2001 From: mdimakov Date: Wed, 26 May 2021 13:40:31 +0300 Subject: [PATCH 03/10] Exception was removed from empty cg Signed-off-by: mdimakov --- sycl/include/CL/sycl/handler.hpp | 12 ------------ sycl/source/handler.cpp | 12 +++++------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/sycl/include/CL/sycl/handler.hpp b/sycl/include/CL/sycl/handler.hpp index 3cde329ecedda..4804d63c0123f 100644 --- a/sycl/include/CL/sycl/handler.hpp +++ b/sycl/include/CL/sycl/handler.hpp @@ -40,18 +40,6 @@ #define __SYCL_NONCONST_FUNCTOR__ #endif -#if SYCL_LANGUAGE_VERSION -#define __SYCL_STD_VERSION__ SYCL_LANGUAGE_VERSION -#else -#define __SYCL_STD_VERSION__ 201707 -#endif - -enum Sycl_std_versions { - version_older_2020, - version_2020 -}; -extern Sycl_std_versions sycl_ver; - template diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 56f7d3e3a9606..8ba56c77eaebd 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -20,8 +20,6 @@ #include #include -Sycl_std_versions sycl_ver; - __SYCL_INLINE_NAMESPACE(cl) { namespace sycl { @@ -204,10 +202,10 @@ event handler::finalize() { std::move(MRequirements), std::move(MEvents), MCGType, MCodeLoc)); break; case detail::CG::NONE: - if (sycl_ver == version_older_2020) - throw runtime_error("Command group submitted without a kernel or a " - "explicit memory operation.", - PI_INVALID_OPERATION); + if (detail::pi::trace(detail::pi::TraceLevel::PI_TRACE_ALL)) { + std::cout << "The empty command group is supported by sycl2020" + << std::endl; + } break; } @@ -219,7 +217,7 @@ event handler::finalize() { "Internal Error. Command group cannot be constructed.", PI_INVALID_OPERATION); else - // if no runtime error was throws it is empty cg from sycl2020 + // empty cg is supported by sycl2020 Event = std::make_shared(); } else From 08ffa1c6f9a9c0798135054add23947a89949d1e Mon Sep 17 00:00:00 2001 From: mdimakov Date: Wed, 26 May 2021 13:48:42 +0300 Subject: [PATCH 04/10] Clang-format fix --- sycl/source/handler.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 8ba56c77eaebd..3aeb125dc651c 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -214,15 +214,14 @@ event handler::finalize() { if (!CommandGroup) { if (getType() != detail::CG::NONE) throw sycl::runtime_error( - "Internal Error. Command group cannot be constructed.", - PI_INVALID_OPERATION); + "Internal Error. Command group cannot be constructed.", + PI_INVALID_OPERATION); else // empty cg is supported by sycl2020 Event = std::make_shared(); - } - else - Event = detail::Scheduler::getInstance().addCG( - std::move(CommandGroup), std::move(MQueue)); + } else + Event = detail::Scheduler::getInstance().addCG(std::move(CommandGroup), + std::move(MQueue)); MLastEvent = detail::createSyclObjFromImpl(Event); return MLastEvent; From 5d5186500f0da5b14e41f7d2cd2196d0ad2fefd9 Mon Sep 17 00:00:00 2001 From: mdimakov Date: Wed, 26 May 2021 14:51:03 +0300 Subject: [PATCH 05/10] Fixed test accordingly to sycl2020 --- sycl/test/basic_tests/event_async_exception.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sycl/test/basic_tests/event_async_exception.cpp b/sycl/test/basic_tests/event_async_exception.cpp index 1f39ebd20e5fb..2291493ede0d9 100644 --- a/sycl/test/basic_tests/event_async_exception.cpp +++ b/sycl/test/basic_tests/event_async_exception.cpp @@ -28,12 +28,12 @@ int main() { queue q(asyncHandler); try { - // Submit a CG with no kernel or memory operation to trigger an async error + // Submit a CG with no kernel or memory operation no trigger an async error event e = q.submit([&](handler &cgh) {}); e.wait_and_throw(); - return 1; - } catch (runtime_error e) { return 0; + } catch (runtime_error e) { + return 1; } } From b77c9a3df511e35d9d242a468eb98d2d9ac96eea Mon Sep 17 00:00:00 2001 From: mdimakov Date: Wed, 26 May 2021 20:56:52 +0300 Subject: [PATCH 06/10] Addressed review comments --- sycl/source/handler.cpp | 26 +++++++++---------- .../basic_tests/event_async_exception.cpp | 3 ++- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 3aeb125dc651c..a31457548826f 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -203,25 +203,23 @@ event handler::finalize() { break; case detail::CG::NONE: if (detail::pi::trace(detail::pi::TraceLevel::PI_TRACE_ALL)) { - std::cout << "The empty command group is supported by sycl2020" + std::cout << "An empty command group is supported by SYCL 2020." << std::endl; } - break; + detail::EventImplPtr Event = + std::make_shared(); + MLastEvent = detail::createSyclObjFromImpl(Event); + return MLastEvent; } - detail::EventImplPtr Event; - if (!CommandGroup) { - if (getType() != detail::CG::NONE) - throw sycl::runtime_error( - "Internal Error. Command group cannot be constructed.", - PI_INVALID_OPERATION); - else - // empty cg is supported by sycl2020 - Event = std::make_shared(); - } else - Event = detail::Scheduler::getInstance().addCG(std::move(CommandGroup), - std::move(MQueue)); + throw sycl::runtime_error( + "Internal Error. Command group cannot be constructed.", + PI_INVALID_OPERATION); + } + + detail::EventImplPtr Event = detail::Scheduler::getInstance().addCG( + std::move(CommandGroup), std::move(MQueue)); MLastEvent = detail::createSyclObjFromImpl(Event); return MLastEvent; diff --git a/sycl/test/basic_tests/event_async_exception.cpp b/sycl/test/basic_tests/event_async_exception.cpp index 2291493ede0d9..819a25710ffd5 100644 --- a/sycl/test/basic_tests/event_async_exception.cpp +++ b/sycl/test/basic_tests/event_async_exception.cpp @@ -28,7 +28,8 @@ int main() { queue q(asyncHandler); try { - // Submit a CG with no kernel or memory operation no trigger an async error + // Check that submitting a CG with no kernel or memory operation doesn't produce + // an async exception event e = q.submit([&](handler &cgh) {}); e.wait_and_throw(); From e42b77d4e1609f791f8b423ff05ae712e48dd022 Mon Sep 17 00:00:00 2001 From: mdimakov Date: Wed, 26 May 2021 21:01:24 +0300 Subject: [PATCH 07/10] Clang-format fix --- sycl/source/handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index a31457548826f..18ba8b21d5492 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -206,7 +206,7 @@ event handler::finalize() { std::cout << "An empty command group is supported by SYCL 2020." << std::endl; } - detail::EventImplPtr Event = + detail::EventImplPtr Event = std::make_shared(); MLastEvent = detail::createSyclObjFromImpl(Event); return MLastEvent; From bc4179dfbe53496a50439a3ac2a0befc91dfc533 Mon Sep 17 00:00:00 2001 From: maximdimakov <73662441+maximdimakov@users.noreply.github.com> Date: Mon, 31 May 2021 12:47:26 +0300 Subject: [PATCH 08/10] Addressed review comments Co-authored-by: Romanov Vlad <17316488+romanovvlad@users.noreply.github.com> --- sycl/source/handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 18ba8b21d5492..39838ca25efe3 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -203,7 +203,7 @@ event handler::finalize() { break; case detail::CG::NONE: if (detail::pi::trace(detail::pi::TraceLevel::PI_TRACE_ALL)) { - std::cout << "An empty command group is supported by SYCL 2020." + std::cout << "WARNING: An empty command group is submitted." << std::endl; } detail::EventImplPtr Event = From 69c1091eaf58adc1b0ecec8e6192be6c24dcdd45 Mon Sep 17 00:00:00 2001 From: mdimakov Date: Mon, 31 May 2021 12:52:18 +0300 Subject: [PATCH 09/10] Clang-format fix --- sycl/source/handler.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 18ba8b21d5492..802169ebcf206 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -203,8 +203,7 @@ event handler::finalize() { break; case detail::CG::NONE: if (detail::pi::trace(detail::pi::TraceLevel::PI_TRACE_ALL)) { - std::cout << "An empty command group is supported by SYCL 2020." - << std::endl; + std::cout << "WARNING: An empty command group is submitted." << std::endl; } detail::EventImplPtr Event = std::make_shared(); From e910192622e395e77ad644f1077e7f33e69ba29b Mon Sep 17 00:00:00 2001 From: mdimakov Date: Wed, 2 Jun 2021 09:54:30 +0300 Subject: [PATCH 10/10] Address review comment --- sycl/source/handler.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index 802169ebcf206..4a875a5d411f5 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -211,11 +211,10 @@ event handler::finalize() { return MLastEvent; } - if (!CommandGroup) { + if (!CommandGroup) throw sycl::runtime_error( "Internal Error. Command group cannot be constructed.", PI_INVALID_OPERATION); - } detail::EventImplPtr Event = detail::Scheduler::getInstance().addCG( std::move(CommandGroup), std::move(MQueue));