From a098e761c71b262004e959bd03e7c2e593405f1e Mon Sep 17 00:00:00 2001 From: Sergey Kanaev Date: Fri, 27 Nov 2020 18:14:23 +0300 Subject: [PATCH 1/4] [SYCL] Add test Signed-off-by: Sergey Kanaev --- .../host-interop-task/interop-task.cpp | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/sycl/test/on-device/host-interop-task/interop-task.cpp b/sycl/test/on-device/host-interop-task/interop-task.cpp index 191f473e8bb77..e02099ba6a197 100644 --- a/sycl/test/on-device/host-interop-task/interop-task.cpp +++ b/sycl/test/on-device/host-interop-task/interop-task.cpp @@ -150,6 +150,46 @@ void test2() { } } +// Same as above but with queue constructed out of context +void test2_1() { + static constexpr int COUNT = 4; + buffer Buffer1{BUFFER_SIZE}; + buffer Buffer2{BUFFER_SIZE}; + + auto Device = default_selector().select_device(); + auto Context = context(Device); + // init the buffer with a'priori invalid data + { + queue Q(Context, Device); + init(Buffer1, Buffer2, Q); + } + + // Repeat a couple of times + for (size_t Idx = 0; Idx < COUNT; ++Idx) { + queue Q(Context, Device); + copy(Buffer1, Buffer2, Q); + modify(Buffer2, Q); + copy(Buffer2, Buffer1, Q); + } + + { + auto Acc = Buffer1.get_access(); + + for (size_t Idx = 0; Idx < Acc.get_count(); ++Idx) { + std::cout << "First buffer [" << Idx << "] = " << Acc[Idx] << std::endl; + assert((Acc[Idx] == COUNT - 1) && "Invalid data in the first buffer"); + } + } + { + auto Acc = Buffer2.get_access(); + + for (size_t Idx = 0; Idx < Acc.get_count(); ++Idx) { + std::cout << "Second buffer [" << Idx << "] = " << Acc[Idx] << std::endl; + assert((Acc[Idx] == COUNT - 1) && "Invalid data in the second buffer"); + } + } +} + // A test that does a clEnqueueWait inside the interop scope, for an event // captured outside the command group. The OpenCL event can be set after the // command group finishes. Must not deadlock according to implementation and @@ -251,6 +291,7 @@ void test6() { int main() { test1(); test2(); + test2_1(); test3(); test4(); test5(); From 5fedfb4a8bbbc2b9ce2424d7f69db9c5e146f3cc Mon Sep 17 00:00:00 2001 From: Sergey Kanaev Date: Fri, 27 Nov 2020 18:14:44 +0300 Subject: [PATCH 2/4] [SYCL] Fix Signed-off-by: Sergey Kanaev --- sycl/source/detail/scheduler/commands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index 21513a035b732..99021f04b085c 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -2039,7 +2039,7 @@ cl_int ExecCGCommand::enqueueImp() { Req->MSYCLMemObj->MRecord->MAllocaCommands; for (AllocaCommandBase *AllocaCmd : AllocaCmds) - if (HostTask->MQueue == AllocaCmd->getQueue()) { + if (HostTask->MQueue->getContextImplPtr() == AllocaCmd->getQueue()->getContextImplPtr()) { auto MemArg = reinterpret_cast(AllocaCmd->getMemAllocation()); ReqToMem.emplace_back(std::make_pair(Req, MemArg)); From 71962f7089960b5c566536cba1db95b631d14c6e Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Sat, 28 Nov 2020 13:29:13 +0300 Subject: [PATCH 3/4] Update sycl/source/detail/scheduler/commands.cpp --- sycl/source/detail/scheduler/commands.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index 99021f04b085c..2ec64700dee97 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -2039,7 +2039,8 @@ cl_int ExecCGCommand::enqueueImp() { Req->MSYCLMemObj->MRecord->MAllocaCommands; for (AllocaCommandBase *AllocaCmd : AllocaCmds) - if (HostTask->MQueue->getContextImplPtr() == AllocaCmd->getQueue()->getContextImplPtr()) { + if (HostTask->MQueue->getContextImplPtr() == + AllocaCmd->getQueue()->getContextImplPtr()) { auto MemArg = reinterpret_cast(AllocaCmd->getMemAllocation()); ReqToMem.emplace_back(std::make_pair(Req, MemArg)); From f9f1d80288c391664e230f15fa64aa801ee28914 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Sat, 28 Nov 2020 13:36:20 +0300 Subject: [PATCH 4/4] Fix typo in comments. One more change to trigger PR update. --- sycl/source/detail/scheduler/commands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index 2ec64700dee97..8a983128d32d6 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -485,7 +485,7 @@ void Command::processDepEvent(EventImplPtr DepEvent, const DepDesc &Dep) { // 1. Async work is not supported for host device. // 2. The event handle can be null in case of, for example, alloca command, - // which is currently synchrounious, so don't generate OpenCL event. + // which is currently synchronous, so don't generate OpenCL event. // Though, this event isn't host one as it's context isn't host one. if (DepEvent->is_host() || DepEvent->getHandleRef() == nullptr) { // call to waitInternal() is in waitForPreparedHostEvents() as it's called