From 809af697e1c1e637d04e3d7f8f31f263ed86d618 Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Mon, 24 Feb 2020 22:18:33 -0800 Subject: [PATCH 01/25] [SYCL] fix the enum variable conflict with user define [CORC-7433] Enum variables were too commonly used by users. This kind of conflicts cannot be avoided 100%, but we can minimize the chance by using the prefix SYCL_ Signed-off-by: Byoungro So --- sycl/include/CL/sycl/detail/scheduler/commands.hpp | 4 ++-- sycl/source/detail/scheduler/commands.cpp | 4 ++-- sycl/source/detail/scheduler/graph_processor.cpp | 6 +++--- sycl/source/detail/scheduler/scheduler.cpp | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sycl/include/CL/sycl/detail/scheduler/commands.hpp b/sycl/include/CL/sycl/detail/scheduler/commands.hpp index 016816615560e..e251001c96742 100644 --- a/sycl/include/CL/sycl/detail/scheduler/commands.hpp +++ b/sycl/include/CL/sycl/detail/scheduler/commands.hpp @@ -38,8 +38,8 @@ enum BlockingT { NON_BLOCKING = 0, BLOCKING }; // The struct represents the result of command enqueueing struct EnqueueResultT { - enum ResultT { SUCCESS, BLOCKED, FAILED }; - EnqueueResultT(ResultT Result = SUCCESS, Command *Cmd = nullptr, + enum ResultT { SYCL_SUCCESS, SYCL_BLOCKED, SYCL_FAILED }; + EnqueueResultT(ResultT Result = SYCL_SUCCESS, Command *Cmd = nullptr, cl_int ErrCode = CL_SUCCESS) : MResult(Result), MCmd(Cmd), MErrCode(ErrCode) {} // Indicates result of enqueueing diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index 6e1b8d246364b..67b49632c585a 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -172,7 +172,7 @@ bool Command::enqueue(EnqueueResultT &EnqueueResult, BlockingT Blocking) { if (MIsBlockable && !MCanEnqueue) { // Exit if enqueue type is not blocking if (!Blocking) { - EnqueueResult = EnqueueResultT(EnqueueResultT::BLOCKED, this); + EnqueueResult = EnqueueResultT(EnqueueResultT::SYCL_BLOCKED, this); return false; } static bool ThrowOnBlock = getenv("SYCL_THROW_ON_BLOCK") != nullptr; @@ -196,7 +196,7 @@ bool Command::enqueue(EnqueueResultT &EnqueueResult, BlockingT Blocking) { cl_int Res = enqueueImp(); if (CL_SUCCESS != Res) - EnqueueResult = EnqueueResultT(EnqueueResultT::FAILED, this, Res); + EnqueueResult = EnqueueResultT(EnqueueResultT::SYCL_FAILED, this, Res); else // Consider the command is successfully enqueued if return code is // CL_SUCCESS diff --git a/sycl/source/detail/scheduler/graph_processor.cpp b/sycl/source/detail/scheduler/graph_processor.cpp index e9ccb51f2b57c..422e4f67b437c 100644 --- a/sycl/source/detail/scheduler/graph_processor.cpp +++ b/sycl/source/detail/scheduler/graph_processor.cpp @@ -41,7 +41,7 @@ void Scheduler::GraphProcessor::waitForEvent(EventImplPtr Event) { assert(Cmd && "Event has no associated command?"); EnqueueResultT Res; bool Enqueued = enqueueCommand(Cmd, Res, BLOCKING); - if (!Enqueued && EnqueueResultT::FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) // TODO: Reschedule commands. throw runtime_error("Enqueue process failed."); @@ -66,12 +66,12 @@ bool Scheduler::GraphProcessor::enqueueCommand(Command *Cmd, enqueueCommand(Dep.MDepCommand, EnqueueResult, Blocking); if (!Enqueued) switch (EnqueueResult.MResult) { - case EnqueueResultT::FAILED: + case EnqueueResultT::SYCL_FAILED: default: // Exit immediately if a command fails to avoid enqueueing commands // result of which will be discarded. return false; - case EnqueueResultT::BLOCKED: + case EnqueueResultT::SYCL_BLOCKED: // If some dependency is blocked from enqueueing remember that, but // try to enqueue other dependencies(that can be ready for // enqueueing). diff --git a/sycl/source/detail/scheduler/scheduler.cpp b/sycl/source/detail/scheduler/scheduler.cpp index b4f8c3af47174..613fca99c32c4 100644 --- a/sycl/source/detail/scheduler/scheduler.cpp +++ b/sycl/source/detail/scheduler/scheduler.cpp @@ -24,14 +24,14 @@ void Scheduler::waitForRecordToFinish(MemObjRecord *Record) { for (Command *Cmd : Record->MReadLeaves) { EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(Cmd, Res); - if (!Enqueued && EnqueueResultT::FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) throw runtime_error("Enqueue process failed."); GraphProcessor::waitForEvent(Cmd->getEvent()); } for (Command *Cmd : Record->MWriteLeaves) { EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(Cmd, Res); - if (!Enqueued && EnqueueResultT::FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) throw runtime_error("Enqueue process failed."); GraphProcessor::waitForEvent(Cmd->getEvent()); } @@ -39,7 +39,7 @@ void Scheduler::waitForRecordToFinish(MemObjRecord *Record) { Command *ReleaseCmd = AllocaCmd->getReleaseCmd(); EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(ReleaseCmd, Res); - if (!Enqueued && EnqueueResultT::FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) throw runtime_error("Enqueue process failed."); GraphProcessor::waitForEvent(ReleaseCmd->getEvent()); } @@ -64,7 +64,7 @@ EventImplPtr Scheduler::addCG(std::unique_ptr CommandGroup, // TODO: Check if lazy mode. EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(NewCmd, Res); - if (!Enqueued && EnqueueResultT::FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) throw runtime_error("Enqueue process failed."); } @@ -85,7 +85,7 @@ EventImplPtr Scheduler::addCopyBack(Requirement *Req) { try { EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(NewCmd, Res); - if (!Enqueued && EnqueueResultT::FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) throw runtime_error("Enqueue process failed."); } catch (...) { NewCmd->getQueue()->reportAsyncException(std::current_exception()); @@ -144,7 +144,7 @@ EventImplPtr Scheduler::addHostAccessor(Requirement *Req) { return nullptr; EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(NewCmd, Res); - if (!Enqueued && EnqueueResultT::FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) throw runtime_error("Enqueue process failed."); return NewCmd->getEvent(); } @@ -156,7 +156,7 @@ void Scheduler::releaseHostAccessor(Requirement *Req) { for (Command *Cmd : Leaves) { EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(Cmd, Res); - if (!Enqueued && EnqueueResultT::FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) throw runtime_error("Enqueue process failed."); } }; From 4862f8bfbbfe1c8a0937b1881147765cbe640b0b Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Tue, 25 Feb 2020 15:59:01 -0800 Subject: [PATCH 02/25] [SYCL] added a regression test for macro conflict Signed-off-by: Byoungro So --- sycl/test/regression/macro_conflict.cpp | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 sycl/test/regression/macro_conflict.cpp diff --git a/sycl/test/regression/macro_conflict.cpp b/sycl/test/regression/macro_conflict.cpp new file mode 100644 index 0000000000000..0772901cfb356 --- /dev/null +++ b/sycl/test/regression/macro_conflict.cpp @@ -0,0 +1,26 @@ +// RUN: %clangxx -fsycl %s -o %t.out +// RUN: %ACC_RUN_PLACEHOLDER %t.out + +// expected-no-diagnostics +// +//==-------------- macro_conflict.cpp --------------------------------------==// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// This test checks if the user-defined macros SUCCESS, FAIL, BLOCKED are +// defined in global namespace by sycl.hpp +//===----------------------------------------------------------------------===// + +#define SUCCESS 0 +#define FAIL 1 +#define BLOCKED 2 + +#include + +int main() { + printf("hello world!\n"); + return 0; +} From 11ad1edced66009ab4701105a7bc67e1e9c67fbd Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Tue, 25 Feb 2020 18:07:56 -0800 Subject: [PATCH 03/25] fixed the clang format check issue Signed-off-by: Byoungro So --- sycl/test/regression/macro_conflict.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sycl/test/regression/macro_conflict.cpp b/sycl/test/regression/macro_conflict.cpp index 0772901cfb356..7a7de8614687c 100644 --- a/sycl/test/regression/macro_conflict.cpp +++ b/sycl/test/regression/macro_conflict.cpp @@ -1,6 +1,5 @@ -// RUN: %clangxx -fsycl %s -o %t.out +// RUN: %clangxx -fsycl %s -o %t.out // RUN: %ACC_RUN_PLACEHOLDER %t.out - // expected-no-diagnostics // //==-------------- macro_conflict.cpp --------------------------------------==// From 2a61c01cadfb14a25ff378b4d7b0d31da7dfc883 Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Wed, 26 Feb 2020 08:25:24 -0800 Subject: [PATCH 04/25] fixed regression test compiler option Signed-off-by: Byoungro So --- sycl/test/regression/macro_conflict.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/sycl/test/regression/macro_conflict.cpp b/sycl/test/regression/macro_conflict.cpp index 7a7de8614687c..080bb215f8d86 100644 --- a/sycl/test/regression/macro_conflict.cpp +++ b/sycl/test/regression/macro_conflict.cpp @@ -1,13 +1,6 @@ -// RUN: %clangxx -fsycl %s -o %t.out -// RUN: %ACC_RUN_PLACEHOLDER %t.out +// RUN: %clangxx -fsyntax-only -Xjclang -verify %s -o %t.out // expected-no-diagnostics // -//==-------------- macro_conflict.cpp --------------------------------------==// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// //===----------------------------------------------------------------------===// // This test checks if the user-defined macros SUCCESS, FAIL, BLOCKED are // defined in global namespace by sycl.hpp From 6dec0f210a596530b9a0456480f57a8a1a7eb596 Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Wed, 26 Feb 2020 08:33:08 -0800 Subject: [PATCH 05/25] fixed a typo Signed-off-by: Byoungro So --- sycl/test/regression/macro_conflict.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/test/regression/macro_conflict.cpp b/sycl/test/regression/macro_conflict.cpp index 080bb215f8d86..eefeab08b8ca9 100644 --- a/sycl/test/regression/macro_conflict.cpp +++ b/sycl/test/regression/macro_conflict.cpp @@ -1,4 +1,4 @@ -// RUN: %clangxx -fsyntax-only -Xjclang -verify %s -o %t.out +// RUN: %clangxx -fsyntax-only -Xclang -verify %s -o %t.out // expected-no-diagnostics // //===----------------------------------------------------------------------===// From 4fc8330a67cbbd1d37b460063d2cf6f756a17ae7 Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Wed, 26 Feb 2020 14:39:06 -0800 Subject: [PATCH 06/25] Update sycl/source/detail/scheduler/commands.hpp Signed-off-by : Byoungro So Co-Authored-By: Alexey Bader --- sycl/source/detail/scheduler/commands.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/source/detail/scheduler/commands.hpp b/sycl/source/detail/scheduler/commands.hpp index d713b75cabbc8..0950ec1f5354a 100644 --- a/sycl/source/detail/scheduler/commands.hpp +++ b/sycl/source/detail/scheduler/commands.hpp @@ -38,7 +38,7 @@ enum BlockingT { NON_BLOCKING = 0, BLOCKING }; // The struct represents the result of command enqueueing struct EnqueueResultT { - enum ResultT { SYCL_SUCCESS, SYCL_BLOCKED, SYCL_FAILED }; + enum ResultT { SYCL_ENQUEUE_SUCCESS, SYCL_ENQUEUE_BLOCKED, SYCL_ENQUEUE_FAILED }; EnqueueResultT(ResultT Result = SYCL_SUCCESS, Command *Cmd = nullptr, cl_int ErrCode = CL_SUCCESS) : MResult(Result), MCmd(Cmd), MErrCode(ErrCode) {} From 85d75cf5ae7af29b246e48fd235e5eb4f41bee9a Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Wed, 26 Feb 2020 14:39:25 -0800 Subject: [PATCH 07/25] Update sycl/test/regression/macro_conflict.cpp Signed-off-by: Byoungro So Co-Authored-By: Alexey Bader --- sycl/test/regression/macro_conflict.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/test/regression/macro_conflict.cpp b/sycl/test/regression/macro_conflict.cpp index eefeab08b8ca9..2c7435e48e3be 100644 --- a/sycl/test/regression/macro_conflict.cpp +++ b/sycl/test/regression/macro_conflict.cpp @@ -3,7 +3,7 @@ // //===----------------------------------------------------------------------===// // This test checks if the user-defined macros SUCCESS, FAIL, BLOCKED are -// defined in global namespace by sycl.hpp +// conflicting with the symbols defined in SYCL header files. //===----------------------------------------------------------------------===// #define SUCCESS 0 From 50d283b48ef0f31569bccc4fecf382b362780b99 Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Wed, 26 Feb 2020 15:43:09 -0800 Subject: [PATCH 08/25] changed the enum variable per Alexey's request Signed-off-by: Byoungro So --- sycl/source/detail/scheduler/commands.cpp | 4 ++-- sycl/source/detail/scheduler/commands.hpp | 2 +- sycl/source/detail/scheduler/graph_processor.cpp | 6 +++--- sycl/source/detail/scheduler/scheduler.cpp | 14 +++++++------- sycl/test/regression/macro_conflict.cpp | 2 -- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index b1969542fa2e9..d28ba6a2b2d00 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -172,7 +172,7 @@ bool Command::enqueue(EnqueueResultT &EnqueueResult, BlockingT Blocking) { if (MIsBlockable && !MCanEnqueue) { // Exit if enqueue type is not blocking if (!Blocking) { - EnqueueResult = EnqueueResultT(EnqueueResultT::SYCL_BLOCKED, this); + EnqueueResult = EnqueueResultT(EnqueueResultT::SYCL_ENQUEUE_BLOCKED, this); return false; } static bool ThrowOnBlock = getenv("SYCL_THROW_ON_BLOCK") != nullptr; @@ -196,7 +196,7 @@ bool Command::enqueue(EnqueueResultT &EnqueueResult, BlockingT Blocking) { cl_int Res = enqueueImp(); if (CL_SUCCESS != Res) - EnqueueResult = EnqueueResultT(EnqueueResultT::SYCL_FAILED, this, Res); + EnqueueResult = EnqueueResultT(EnqueueResultT::SYCL_ENQUEUE_FAILED, this, Res); else // Consider the command is successfully enqueued if return code is // CL_SUCCESS diff --git a/sycl/source/detail/scheduler/commands.hpp b/sycl/source/detail/scheduler/commands.hpp index 0950ec1f5354a..3056b82e22832 100644 --- a/sycl/source/detail/scheduler/commands.hpp +++ b/sycl/source/detail/scheduler/commands.hpp @@ -39,7 +39,7 @@ enum BlockingT { NON_BLOCKING = 0, BLOCKING }; // The struct represents the result of command enqueueing struct EnqueueResultT { enum ResultT { SYCL_ENQUEUE_SUCCESS, SYCL_ENQUEUE_BLOCKED, SYCL_ENQUEUE_FAILED }; - EnqueueResultT(ResultT Result = SYCL_SUCCESS, Command *Cmd = nullptr, + EnqueueResultT(ResultT Result = SYCL_ENQUEUE_SUCCESS, Command *Cmd = nullptr, cl_int ErrCode = CL_SUCCESS) : MResult(Result), MCmd(Cmd), MErrCode(ErrCode) {} // Indicates result of enqueueing diff --git a/sycl/source/detail/scheduler/graph_processor.cpp b/sycl/source/detail/scheduler/graph_processor.cpp index 5e7b5729943be..031828e6c21f1 100644 --- a/sycl/source/detail/scheduler/graph_processor.cpp +++ b/sycl/source/detail/scheduler/graph_processor.cpp @@ -41,7 +41,7 @@ void Scheduler::GraphProcessor::waitForEvent(EventImplPtr Event) { assert(Cmd && "Event has no associated command?"); EnqueueResultT Res; bool Enqueued = enqueueCommand(Cmd, Res, BLOCKING); - if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) // TODO: Reschedule commands. throw runtime_error("Enqueue process failed."); @@ -66,12 +66,12 @@ bool Scheduler::GraphProcessor::enqueueCommand(Command *Cmd, enqueueCommand(Dep.MDepCommand, EnqueueResult, Blocking); if (!Enqueued) switch (EnqueueResult.MResult) { - case EnqueueResultT::SYCL_FAILED: + case EnqueueResultT::SYCL_ENQUEUE_FAILED: default: // Exit immediately if a command fails to avoid enqueueing commands // result of which will be discarded. return false; - case EnqueueResultT::SYCL_BLOCKED: + case EnqueueResultT::SYCL_ENQUEUE_BLOCKED: // If some dependency is blocked from enqueueing remember that, but // try to enqueue other dependencies(that can be ready for // enqueueing). diff --git a/sycl/source/detail/scheduler/scheduler.cpp b/sycl/source/detail/scheduler/scheduler.cpp index 65b3e8152c33e..5ac580bd5d921 100644 --- a/sycl/source/detail/scheduler/scheduler.cpp +++ b/sycl/source/detail/scheduler/scheduler.cpp @@ -30,14 +30,14 @@ void Scheduler::waitForRecordToFinish(MemObjRecord *Record) { for (Command *Cmd : Record->MReadLeaves) { EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(Cmd, Res); - if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) throw runtime_error("Enqueue process failed."); GraphProcessor::waitForEvent(Cmd->getEvent()); } for (Command *Cmd : Record->MWriteLeaves) { EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(Cmd, Res); - if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) throw runtime_error("Enqueue process failed."); GraphProcessor::waitForEvent(Cmd->getEvent()); } @@ -45,7 +45,7 @@ void Scheduler::waitForRecordToFinish(MemObjRecord *Record) { Command *ReleaseCmd = AllocaCmd->getReleaseCmd(); EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(ReleaseCmd, Res); - if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) throw runtime_error("Enqueue process failed."); GraphProcessor::waitForEvent(ReleaseCmd->getEvent()); } @@ -70,7 +70,7 @@ EventImplPtr Scheduler::addCG(std::unique_ptr CommandGroup, // TODO: Check if lazy mode. EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(NewCmd, Res); - if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) throw runtime_error("Enqueue process failed."); } @@ -91,7 +91,7 @@ EventImplPtr Scheduler::addCopyBack(Requirement *Req) { try { EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(NewCmd, Res); - if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) throw runtime_error("Enqueue process failed."); } catch (...) { NewCmd->getQueue()->reportAsyncException(std::current_exception()); @@ -151,7 +151,7 @@ EventImplPtr Scheduler::addHostAccessor(Requirement *Req, return nullptr; EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(NewCmd, Res); - if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) throw runtime_error("Enqueue process failed."); return NewCmd->getEvent(); } @@ -163,7 +163,7 @@ void Scheduler::releaseHostAccessor(Requirement *Req) { for (Command *Cmd : Leaves) { EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(Cmd, Res); - if (!Enqueued && EnqueueResultT::SYCL_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) throw runtime_error("Enqueue process failed."); } }; diff --git a/sycl/test/regression/macro_conflict.cpp b/sycl/test/regression/macro_conflict.cpp index 2c7435e48e3be..b9785031f4ad8 100644 --- a/sycl/test/regression/macro_conflict.cpp +++ b/sycl/test/regression/macro_conflict.cpp @@ -7,8 +7,6 @@ //===----------------------------------------------------------------------===// #define SUCCESS 0 -#define FAIL 1 -#define BLOCKED 2 #include From 8414e8b203ca688b6d7e38a72e1f1681b8d975a1 Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Wed, 26 Feb 2020 15:52:58 -0800 Subject: [PATCH 09/25] fixed clang-format error Signed-off-by: Byoungro So --- sycl/source/detail/scheduler/commands.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index d28ba6a2b2d00..746dc75e6e8eb 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -172,7 +172,8 @@ bool Command::enqueue(EnqueueResultT &EnqueueResult, BlockingT Blocking) { if (MIsBlockable && !MCanEnqueue) { // Exit if enqueue type is not blocking if (!Blocking) { - EnqueueResult = EnqueueResultT(EnqueueResultT::SYCL_ENQUEUE_BLOCKED, this); + EnqueueResult = + EnqueueResultT(EnqueueResultT::SYCL_ENQUEUE_BLOCKED, this); return false; } static bool ThrowOnBlock = getenv("SYCL_THROW_ON_BLOCK") != nullptr; @@ -196,7 +197,8 @@ bool Command::enqueue(EnqueueResultT &EnqueueResult, BlockingT Blocking) { cl_int Res = enqueueImp(); if (CL_SUCCESS != Res) - EnqueueResult = EnqueueResultT(EnqueueResultT::SYCL_ENQUEUE_FAILED, this, Res); + EnqueueResult = + EnqueueResultT(EnqueueResultT::SYCL_ENQUEUE_FAILED, this, Res); else // Consider the command is successfully enqueued if return code is // CL_SUCCESS From c93c0f852df61c9dc4663dcb654d8a6e50895e8b Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Wed, 26 Feb 2020 16:01:27 -0800 Subject: [PATCH 10/25] second attempt to fix the format error Signed-off-by: Byoungro So --- sycl/source/detail/scheduler/commands.cpp | 2 +- sycl/source/detail/scheduler/commands.hpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index 746dc75e6e8eb..9e3bd96a4fbff 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -173,7 +173,7 @@ bool Command::enqueue(EnqueueResultT &EnqueueResult, BlockingT Blocking) { // Exit if enqueue type is not blocking if (!Blocking) { EnqueueResult = - EnqueueResultT(EnqueueResultT::SYCL_ENQUEUE_BLOCKED, this); + EnqueueResultT(EnqueueResultT::SYCL_ENQUEUE_BLOCKED, this); return false; } static bool ThrowOnBlock = getenv("SYCL_THROW_ON_BLOCK") != nullptr; diff --git a/sycl/source/detail/scheduler/commands.hpp b/sycl/source/detail/scheduler/commands.hpp index 3056b82e22832..05f46e135744b 100644 --- a/sycl/source/detail/scheduler/commands.hpp +++ b/sycl/source/detail/scheduler/commands.hpp @@ -38,7 +38,11 @@ enum BlockingT { NON_BLOCKING = 0, BLOCKING }; // The struct represents the result of command enqueueing struct EnqueueResultT { - enum ResultT { SYCL_ENQUEUE_SUCCESS, SYCL_ENQUEUE_BLOCKED, SYCL_ENQUEUE_FAILED }; + enum ResultT { + SYCL_ENQUEUE_SUCCESS, + SYCL_ENQUEUE_BLOCKED, + SYCL_ENQUEUE_FAILED + }; EnqueueResultT(ResultT Result = SYCL_ENQUEUE_SUCCESS, Command *Cmd = nullptr, cl_int ErrCode = CL_SUCCESS) : MResult(Result), MCmd(Cmd), MErrCode(ErrCode) {} From 45d6f9993f91f01da92e7e9079f259ff457e7c1a Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Thu, 27 Feb 2020 13:04:29 -0800 Subject: [PATCH 11/25] removed main() to avoid runtime check per reviewer's request Signed-off-by: Byoungro So --- sycl/test/regression/macro_conflict.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/sycl/test/regression/macro_conflict.cpp b/sycl/test/regression/macro_conflict.cpp index b9785031f4ad8..0de9441709ef7 100644 --- a/sycl/test/regression/macro_conflict.cpp +++ b/sycl/test/regression/macro_conflict.cpp @@ -2,15 +2,11 @@ // expected-no-diagnostics // //===----------------------------------------------------------------------===// -// This test checks if the user-defined macros SUCCESS, FAIL, BLOCKED are +// This test checks if the user-defined macros SUCCESS is // conflicting with the symbols defined in SYCL header files. +// This test only checks compilation errorr, so the main function is omitted. //===----------------------------------------------------------------------===// #define SUCCESS 0 #include - -int main() { - printf("hello world!\n"); - return 0; -} From 5eda19056965363979cbf39f5b4c2bf37ac52020 Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Fri, 28 Feb 2020 12:25:30 -0800 Subject: [PATCH 12/25] fixed a typo. Signed-off-by: Byoungro So --- sycl/test/regression/macro_conflict.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/test/regression/macro_conflict.cpp b/sycl/test/regression/macro_conflict.cpp index 0de9441709ef7..6e20ab56ded58 100644 --- a/sycl/test/regression/macro_conflict.cpp +++ b/sycl/test/regression/macro_conflict.cpp @@ -4,7 +4,7 @@ //===----------------------------------------------------------------------===// // This test checks if the user-defined macros SUCCESS is // conflicting with the symbols defined in SYCL header files. -// This test only checks compilation errorr, so the main function is omitted. +// This test only checks compilation error, so the main function is omitted. //===----------------------------------------------------------------------===// #define SUCCESS 0 From 65bccf4791eccc9db54e87ff6e3a92eeb015be00 Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Fri, 28 Feb 2020 16:39:30 -0800 Subject: [PATCH 13/25] changed enum variables to conform to guideline Signed-off-by: Byoungro So --- sycl/source/detail/scheduler/commands.cpp | 4 ++-- sycl/source/detail/scheduler/commands.hpp | 8 ++++---- sycl/source/detail/scheduler/graph_processor.cpp | 6 +++--- sycl/source/detail/scheduler/scheduler.cpp | 14 +++++++------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index 9e3bd96a4fbff..4b5ef6c7ac7a4 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -173,7 +173,7 @@ bool Command::enqueue(EnqueueResultT &EnqueueResult, BlockingT Blocking) { // Exit if enqueue type is not blocking if (!Blocking) { EnqueueResult = - EnqueueResultT(EnqueueResultT::SYCL_ENQUEUE_BLOCKED, this); + EnqueueResultT(EnqueueResultT::SyclEnqueueBlocked, this); return false; } static bool ThrowOnBlock = getenv("SYCL_THROW_ON_BLOCK") != nullptr; @@ -198,7 +198,7 @@ bool Command::enqueue(EnqueueResultT &EnqueueResult, BlockingT Blocking) { if (CL_SUCCESS != Res) EnqueueResult = - EnqueueResultT(EnqueueResultT::SYCL_ENQUEUE_FAILED, this, Res); + EnqueueResultT(EnqueueResultT::SyclEnqueueFailed, this, Res); else // Consider the command is successfully enqueued if return code is // CL_SUCCESS diff --git a/sycl/source/detail/scheduler/commands.hpp b/sycl/source/detail/scheduler/commands.hpp index 05f46e135744b..2f6e047526c94 100644 --- a/sycl/source/detail/scheduler/commands.hpp +++ b/sycl/source/detail/scheduler/commands.hpp @@ -39,11 +39,11 @@ enum BlockingT { NON_BLOCKING = 0, BLOCKING }; // The struct represents the result of command enqueueing struct EnqueueResultT { enum ResultT { - SYCL_ENQUEUE_SUCCESS, - SYCL_ENQUEUE_BLOCKED, - SYCL_ENQUEUE_FAILED + SyclEnqueueSuccess, + SyclEnqueueBlocked, + SyclEnqueueFailed }; - EnqueueResultT(ResultT Result = SYCL_ENQUEUE_SUCCESS, Command *Cmd = nullptr, + EnqueueResultT(ResultT Result = SyclEnqueueSuccess, Command *Cmd = nullptr, cl_int ErrCode = CL_SUCCESS) : MResult(Result), MCmd(Cmd), MErrCode(ErrCode) {} // Indicates result of enqueueing diff --git a/sycl/source/detail/scheduler/graph_processor.cpp b/sycl/source/detail/scheduler/graph_processor.cpp index 031828e6c21f1..903f4ac43294a 100644 --- a/sycl/source/detail/scheduler/graph_processor.cpp +++ b/sycl/source/detail/scheduler/graph_processor.cpp @@ -41,7 +41,7 @@ void Scheduler::GraphProcessor::waitForEvent(EventImplPtr Event) { assert(Cmd && "Event has no associated command?"); EnqueueResultT Res; bool Enqueued = enqueueCommand(Cmd, Res, BLOCKING); - if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SyclEnqueueFailed == Res.MResult) // TODO: Reschedule commands. throw runtime_error("Enqueue process failed."); @@ -66,12 +66,12 @@ bool Scheduler::GraphProcessor::enqueueCommand(Command *Cmd, enqueueCommand(Dep.MDepCommand, EnqueueResult, Blocking); if (!Enqueued) switch (EnqueueResult.MResult) { - case EnqueueResultT::SYCL_ENQUEUE_FAILED: + case EnqueueResultT::SyclEnqueueFailed: default: // Exit immediately if a command fails to avoid enqueueing commands // result of which will be discarded. return false; - case EnqueueResultT::SYCL_ENQUEUE_BLOCKED: + case EnqueueResultT::SyclEnqueueBlocked: // If some dependency is blocked from enqueueing remember that, but // try to enqueue other dependencies(that can be ready for // enqueueing). diff --git a/sycl/source/detail/scheduler/scheduler.cpp b/sycl/source/detail/scheduler/scheduler.cpp index 5ac580bd5d921..1a87ec99ee252 100644 --- a/sycl/source/detail/scheduler/scheduler.cpp +++ b/sycl/source/detail/scheduler/scheduler.cpp @@ -30,14 +30,14 @@ void Scheduler::waitForRecordToFinish(MemObjRecord *Record) { for (Command *Cmd : Record->MReadLeaves) { EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(Cmd, Res); - if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SyclEnqueueFailed == Res.MResult) throw runtime_error("Enqueue process failed."); GraphProcessor::waitForEvent(Cmd->getEvent()); } for (Command *Cmd : Record->MWriteLeaves) { EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(Cmd, Res); - if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SyclEnqueueFailed == Res.MResult) throw runtime_error("Enqueue process failed."); GraphProcessor::waitForEvent(Cmd->getEvent()); } @@ -45,7 +45,7 @@ void Scheduler::waitForRecordToFinish(MemObjRecord *Record) { Command *ReleaseCmd = AllocaCmd->getReleaseCmd(); EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(ReleaseCmd, Res); - if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SyclEnqueueFailed == Res.MResult) throw runtime_error("Enqueue process failed."); GraphProcessor::waitForEvent(ReleaseCmd->getEvent()); } @@ -70,7 +70,7 @@ EventImplPtr Scheduler::addCG(std::unique_ptr CommandGroup, // TODO: Check if lazy mode. EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(NewCmd, Res); - if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SyclEnqueueFailed == Res.MResult) throw runtime_error("Enqueue process failed."); } @@ -91,7 +91,7 @@ EventImplPtr Scheduler::addCopyBack(Requirement *Req) { try { EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(NewCmd, Res); - if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SyclEnqueueFailed == Res.MResult) throw runtime_error("Enqueue process failed."); } catch (...) { NewCmd->getQueue()->reportAsyncException(std::current_exception()); @@ -151,7 +151,7 @@ EventImplPtr Scheduler::addHostAccessor(Requirement *Req, return nullptr; EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(NewCmd, Res); - if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SyclEnqueueFailed == Res.MResult) throw runtime_error("Enqueue process failed."); return NewCmd->getEvent(); } @@ -163,7 +163,7 @@ void Scheduler::releaseHostAccessor(Requirement *Req) { for (Command *Cmd : Leaves) { EnqueueResultT Res; bool Enqueued = GraphProcessor::enqueueCommand(Cmd, Res); - if (!Enqueued && EnqueueResultT::SYCL_ENQUEUE_FAILED == Res.MResult) + if (!Enqueued && EnqueueResultT::SyclEnqueueFailed == Res.MResult) throw runtime_error("Enqueue process failed."); } }; From 043f1b8aa2e4cfeae0602eff4c04ec81a70a1cb0 Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Fri, 28 Feb 2020 16:54:18 -0800 Subject: [PATCH 14/25] fixed the clang format issue Signed-off-by: Byoungro So --- sycl/source/detail/scheduler/commands.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index 4b5ef6c7ac7a4..3b97de5673a92 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -172,8 +172,7 @@ bool Command::enqueue(EnqueueResultT &EnqueueResult, BlockingT Blocking) { if (MIsBlockable && !MCanEnqueue) { // Exit if enqueue type is not blocking if (!Blocking) { - EnqueueResult = - EnqueueResultT(EnqueueResultT::SyclEnqueueBlocked, this); + EnqueueResult = EnqueueResultT(EnqueueResultT::SyclEnqueueBlocked, this); return false; } static bool ThrowOnBlock = getenv("SYCL_THROW_ON_BLOCK") != nullptr; From 8bbcbd0506103dc7acc214f0c5da9cf3abd5b515 Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Fri, 28 Feb 2020 17:02:12 -0800 Subject: [PATCH 15/25] fix clang format issue Signed-off-by: Byoungro So --- sycl/source/detail/scheduler/commands.hpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sycl/source/detail/scheduler/commands.hpp b/sycl/source/detail/scheduler/commands.hpp index 2f6e047526c94..315e0e366fd98 100644 --- a/sycl/source/detail/scheduler/commands.hpp +++ b/sycl/source/detail/scheduler/commands.hpp @@ -38,11 +38,7 @@ enum BlockingT { NON_BLOCKING = 0, BLOCKING }; // The struct represents the result of command enqueueing struct EnqueueResultT { - enum ResultT { - SyclEnqueueSuccess, - SyclEnqueueBlocked, - SyclEnqueueFailed - }; + enum ResultT { SyclEnqueueSuccess, SyclEnqueueBlocked, SyclEnqueueFailed }; EnqueueResultT(ResultT Result = SyclEnqueueSuccess, Command *Cmd = nullptr, cl_int ErrCode = CL_SUCCESS) : MResult(Result), MCmd(Cmd), MErrCode(ErrCode) {} From 7ad8d198fb1a0bb8b20595fa1cafccf10d230a6f Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Fri, 28 Feb 2020 20:22:48 -0800 Subject: [PATCH 16/25] fixed LIT test failure Signed-off-by: Byoungro So --- sycl/test/scheduler/BlockedCommands.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sycl/test/scheduler/BlockedCommands.cpp b/sycl/test/scheduler/BlockedCommands.cpp index 0cba98584a8c1..32421527f1562 100644 --- a/sycl/test/scheduler/BlockedCommands.cpp +++ b/sycl/test/scheduler/BlockedCommands.cpp @@ -54,7 +54,7 @@ int main() { return 1; } - if (detail::EnqueueResultT::BLOCKED != Res.MResult) { + if (detail::EnqueueResultT::SyclEnqueueBlocked != Res.MResult) { std::cerr << "Result of enqueueing blocked command should be BLOCKED" << std::endl; return 1; @@ -73,7 +73,7 @@ int main() { return 1; } - if (detail::EnqueueResultT::FAILED != Res.MResult) { + if (detail::EnqueueResultT::SyclEnqueueFailed != Res.MResult) { std::cerr << "The command is expected to fail to enqueue." << std::endl; return 1; } @@ -96,7 +96,7 @@ int main() { bool Enqueued = TestScheduler::enqueueCommand(&FakeCmd, Res, detail::BLOCKING); - if (!Enqueued || detail::EnqueueResultT::SUCCESS != Res.MResult) { + if (!Enqueued || detail::EnqueueResultT::SyclEnqueueSuccess != Res.MResult) { std::cerr << "The command is expected to be successfully enqueued." << std::endl; return 1; From f73a2d983b689c67c772ae7432527961b4851fec Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Fri, 28 Feb 2020 20:27:31 -0800 Subject: [PATCH 17/25] fixed the clang format issue Signed-off-by: Byoungro So --- sycl/test/scheduler/BlockedCommands.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sycl/test/scheduler/BlockedCommands.cpp b/sycl/test/scheduler/BlockedCommands.cpp index 32421527f1562..bdcbd300fb2cd 100644 --- a/sycl/test/scheduler/BlockedCommands.cpp +++ b/sycl/test/scheduler/BlockedCommands.cpp @@ -96,7 +96,8 @@ int main() { bool Enqueued = TestScheduler::enqueueCommand(&FakeCmd, Res, detail::BLOCKING); - if (!Enqueued || detail::EnqueueResultT::SyclEnqueueSuccess != Res.MResult) { + if (!Enqueued || + detail::EnqueueResultT::SyclEnqueueSuccess != Res.MResult) { std::cerr << "The command is expected to be successfully enqueued." << std::endl; return 1; From c86049c0caeecff41a3952d88904d50c21e8ff9e Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Fri, 28 Feb 2020 20:39:53 -0800 Subject: [PATCH 18/25] fixed format Signed-off-by: Byoungro So --- sycl/test/scheduler/BlockedCommands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/test/scheduler/BlockedCommands.cpp b/sycl/test/scheduler/BlockedCommands.cpp index bdcbd300fb2cd..8f10f355785fe 100644 --- a/sycl/test/scheduler/BlockedCommands.cpp +++ b/sycl/test/scheduler/BlockedCommands.cpp @@ -97,7 +97,7 @@ int main() { TestScheduler::enqueueCommand(&FakeCmd, Res, detail::BLOCKING); if (!Enqueued || - detail::EnqueueResultT::SyclEnqueueSuccess != Res.MResult) { + detail::EnqueueResultT::SyclEnqueueSuccess != Res.MResult) { std::cerr << "The command is expected to be successfully enqueued." << std::endl; return 1; From 016c9f5839a5780716677f84dbea57921d1dfb4c Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Tue, 3 Mar 2020 22:42:37 -0800 Subject: [PATCH 19/25] [SYCL] fixed USM malloc_shared and free to handle zero byte Signed-off-by: Byoungro So --- sycl/source/detail/usm/usm_impl.cpp | 6 +++ sycl/test/regression/usm_malloc_shared.cpp | 50 ++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 sycl/test/regression/usm_malloc_shared.cpp diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index e6cb56c936cd6..25a158cbeed88 100644 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -27,6 +27,8 @@ namespace usm { void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt, alloc Kind) { void *RetVal = nullptr; + if (Size == 0) + return nullptr; if (Ctxt.is_host()) { if (!Alignment) { // worst case default @@ -72,6 +74,8 @@ void *alignedAllocHost(size_t Alignment, size_t Size, const context &Ctxt, void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt, const device &Dev, alloc Kind) { void *RetVal = nullptr; + if (Size == 0) + return nullptr; if (Ctxt.is_host()) { if (Kind == alloc::unknown) { RetVal = nullptr; @@ -126,6 +130,8 @@ void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt, } void free(void *Ptr, const context &Ctxt) { + if (Ptr == nullptr) + return; if (Ctxt.is_host()) { // need to use alignedFree here for Windows detail::OSUtil::alignedFree(Ptr); diff --git a/sycl/test/regression/usm_malloc_shared.cpp b/sycl/test/regression/usm_malloc_shared.cpp new file mode 100644 index 0000000000000..6955a080a861f --- /dev/null +++ b/sycl/test/regression/usm_malloc_shared.cpp @@ -0,0 +1,50 @@ +// RUN: %clangxx -fsycl %s -o %t.out +// RUN: env SYCL_DEVICE_TYPE=CPU %t.out +// RUN: env SYCL_DEVICE_TYPE=GPU %t.out +// RUN: env SYCL_DEVICE_TYPE=HOST %t.out + + +//==-------------- usm_free.cpp - SYCL USM free malloc_shared and free test -------------==// +// +// This test checks if users will successfully allocate 160, 0, and -16 bytes of shared +// memory, and also test user can call free() without worrying about nullptr or invalid +// memory descriptor returned from malloc. +//==-------------------------------------------------------------------------------------==// + +#include +#include +#include +using namespace cl::sycl; + +int main(int argc, char * argv[]) { + auto exception_handler = [](cl::sycl::exception_list exceptions) { + for (std::exception_ptr const &e : exceptions) { + try { + std::rethrow_exception(e); + } + catch (cl::sycl::exception const &e) { + std::cout << "Caught asynchronous SYCL " + "exception:\n" + << e.what() << std::endl; + } + } + }; + + queue myQueue(default_selector{}, exception_handler); + std::cout << "Device: " << myQueue.get_device().get_info() + << std::endl; + + double *ia = (double *)malloc_shared(160, myQueue); + double *ja = (double *)malloc_shared(0, myQueue); + double *result = (double *)malloc_shared(-16, myQueue); + + std::cout << "ia : " << ia << " ja: " << ja << " result : " << result << std::endl; + + // followings should not throws CL_INVALID_VALUE + free(ia, myQueue); + free(nullptr); + free(ja, myQueue); + free(result, myQueue); + + return 0; +} From d27268a0017b9c2a6bde42dba82010c0d832302a Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Thu, 5 Mar 2020 09:21:02 -0800 Subject: [PATCH 20/25] reformat clang-format Signed-off-by: Byoungro So --- sycl/test/regression/usm_malloc_shared.cpp | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/sycl/test/regression/usm_malloc_shared.cpp b/sycl/test/regression/usm_malloc_shared.cpp index 6955a080a861f..757ca6cd7972c 100644 --- a/sycl/test/regression/usm_malloc_shared.cpp +++ b/sycl/test/regression/usm_malloc_shared.cpp @@ -3,12 +3,12 @@ // RUN: env SYCL_DEVICE_TYPE=GPU %t.out // RUN: env SYCL_DEVICE_TYPE=HOST %t.out - -//==-------------- usm_free.cpp - SYCL USM free malloc_shared and free test -------------==// +//==-------------- usm_free.cpp - SYCL USM free malloc_shared and free test +//-------------==// // -// This test checks if users will successfully allocate 160, 0, and -16 bytes of shared -// memory, and also test user can call free() without worrying about nullptr or invalid -// memory descriptor returned from malloc. +// This test checks if users will successfully allocate 160, 0, and -16 bytes of +// shared memory, and also test user can call free() without worrying about +// nullptr or invalid memory descriptor returned from malloc. //==-------------------------------------------------------------------------------------==// #include @@ -16,35 +16,35 @@ #include using namespace cl::sycl; -int main(int argc, char * argv[]) { +int main(int argc, char *argv[]) { auto exception_handler = [](cl::sycl::exception_list exceptions) { for (std::exception_ptr const &e : exceptions) { try { - std::rethrow_exception(e); - } - catch (cl::sycl::exception const &e) { - std::cout << "Caught asynchronous SYCL " - "exception:\n" - << e.what() << std::endl; + std::rethrow_exception(e); + } catch (cl::sycl::exception const &e) { + std::cout << "Caught asynchronous SYCL " + "exception:\n" + << e.what() << std::endl; } } }; queue myQueue(default_selector{}, exception_handler); std::cout << "Device: " << myQueue.get_device().get_info() - << std::endl; - + << std::endl; + double *ia = (double *)malloc_shared(160, myQueue); double *ja = (double *)malloc_shared(0, myQueue); double *result = (double *)malloc_shared(-16, myQueue); - std::cout << "ia : " << ia << " ja: " << ja << " result : " << result << std::endl; + std::cout << "ia : " << ia << " ja: " << ja << " result : " << result + << std::endl; // followings should not throws CL_INVALID_VALUE - free(ia, myQueue); - free(nullptr); - free(ja, myQueue); - free(result, myQueue); + cl::sycl::free(ia, myQueue); + cl::sycl::free(nullptr, myQueue); + cl::sycl::free(ja, myQueue); + cl::sycl::free(result, myQueue); return 0; } From e942ffc7ada8792d38dc645accd8b720123c6d7c Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Mon, 9 Mar 2020 10:17:14 -0700 Subject: [PATCH 21/25] Update sycl/test/regression/usm_malloc_shared.cpp Signed-off-by: Byoungro So Co-Authored-By: Alexey Bader --- sycl/test/regression/usm_malloc_shared.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sycl/test/regression/usm_malloc_shared.cpp b/sycl/test/regression/usm_malloc_shared.cpp index 757ca6cd7972c..b94708914accb 100644 --- a/sycl/test/regression/usm_malloc_shared.cpp +++ b/sycl/test/regression/usm_malloc_shared.cpp @@ -1,7 +1,8 @@ // RUN: %clangxx -fsycl %s -o %t.out -// RUN: env SYCL_DEVICE_TYPE=CPU %t.out -// RUN: env SYCL_DEVICE_TYPE=GPU %t.out // RUN: env SYCL_DEVICE_TYPE=HOST %t.out +// RUN: %CPU_RUN_PLACEHOLDER %t.out +// RUN: %GPU_RUN_PLACEHOLDER %t.out +// RUN: %ACC_RUN_PLACEHOLDER %t.out //==-------------- usm_free.cpp - SYCL USM free malloc_shared and free test //-------------==// From 8dd7ee04ff56c736d5e0214546ef75d139b75fab Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Mon, 9 Mar 2020 11:15:04 -0700 Subject: [PATCH 22/25] cleaned up unnecessary lines Signed-off-by: Byoungro So --- sycl/test/regression/usm_malloc_shared.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sycl/test/regression/usm_malloc_shared.cpp b/sycl/test/regression/usm_malloc_shared.cpp index b94708914accb..c652f0c63e4bb 100644 --- a/sycl/test/regression/usm_malloc_shared.cpp +++ b/sycl/test/regression/usm_malloc_shared.cpp @@ -4,13 +4,9 @@ // RUN: %GPU_RUN_PLACEHOLDER %t.out // RUN: %ACC_RUN_PLACEHOLDER %t.out -//==-------------- usm_free.cpp - SYCL USM free malloc_shared and free test -//-------------==// -// // This test checks if users will successfully allocate 160, 0, and -16 bytes of // shared memory, and also test user can call free() without worrying about // nullptr or invalid memory descriptor returned from malloc. -//==-------------------------------------------------------------------------------------==// #include #include @@ -41,7 +37,7 @@ int main(int argc, char *argv[]) { std::cout << "ia : " << ia << " ja: " << ja << " result : " << result << std::endl; - // followings should not throws CL_INVALID_VALUE + // followings should not throw CL_INVALID_VALUE cl::sycl::free(ia, myQueue); cl::sycl::free(nullptr, myQueue); cl::sycl::free(ja, myQueue); From 23a243dc7e5dbcc830c47c4f1c6354e61d4abd30 Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Tue, 10 Mar 2020 12:30:15 -0700 Subject: [PATCH 23/25] removed GPU and ACC test run Signed-off-by: Byoungro So --- sycl/test/regression/usm_malloc_shared.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/sycl/test/regression/usm_malloc_shared.cpp b/sycl/test/regression/usm_malloc_shared.cpp index c652f0c63e4bb..e8b59eea4cb4e 100644 --- a/sycl/test/regression/usm_malloc_shared.cpp +++ b/sycl/test/regression/usm_malloc_shared.cpp @@ -1,8 +1,6 @@ // RUN: %clangxx -fsycl %s -o %t.out // RUN: env SYCL_DEVICE_TYPE=HOST %t.out // RUN: %CPU_RUN_PLACEHOLDER %t.out -// RUN: %GPU_RUN_PLACEHOLDER %t.out -// RUN: %ACC_RUN_PLACEHOLDER %t.out // This test checks if users will successfully allocate 160, 0, and -16 bytes of // shared memory, and also test user can call free() without worrying about From df098b95b642259e086494743eb987abb3f4a7dd Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Wed, 11 Mar 2020 12:20:22 -0700 Subject: [PATCH 24/25] added assertion of bad malloc cases Signed-off-by: Byoungro So --- sycl/test/regression/usm_malloc_shared.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sycl/test/regression/usm_malloc_shared.cpp b/sycl/test/regression/usm_malloc_shared.cpp index e8b59eea4cb4e..40979b11362b7 100644 --- a/sycl/test/regression/usm_malloc_shared.cpp +++ b/sycl/test/regression/usm_malloc_shared.cpp @@ -32,6 +32,10 @@ int main(int argc, char *argv[]) { double *ja = (double *)malloc_shared(0, myQueue); double *result = (double *)malloc_shared(-16, myQueue); + assert(ia != nullptr); + assert(ja == nullptr); + assert(result == nullptr); + std::cout << "ia : " << ia << " ja: " << ja << " result : " << result << std::endl; From 823df2ad0a90d1fa9a6a84cf1a6847378699c06c Mon Sep 17 00:00:00 2001 From: Byoungro So Date: Wed, 11 Mar 2020 12:24:53 -0700 Subject: [PATCH 25/25] fixed empty space format Signed-off-by: Byoungro So --- sycl/test/regression/usm_malloc_shared.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/test/regression/usm_malloc_shared.cpp b/sycl/test/regression/usm_malloc_shared.cpp index 40979b11362b7..c078d225791f8 100644 --- a/sycl/test/regression/usm_malloc_shared.cpp +++ b/sycl/test/regression/usm_malloc_shared.cpp @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) { assert(ia != nullptr); assert(ja == nullptr); assert(result == nullptr); - + std::cout << "ia : " << ia << " ja: " << ja << " result : " << result << std::endl;