Skip to content

Commit d286ca2

Browse files
[SYCL] Add sync for host task after barrier (#15345)
PR includes the following fixes: * When submitting a command to an out-of-order queue we don't need to add the dependency from the last barrier to the scheduler if command is enqueued via UR because that means that UR backend will take care of the command from barrier. * We used to update the last barrier only if barrier which is being submitted to the sycl::queue is not enqueued to the backend which is not correct, because there might be host tasks following that barrier which have to depend on it. Signed-off-by: Tikhomirova, Kseniya <kseniya.tikhomirova@intel.com>
1 parent 8d1c9f0 commit d286ca2

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

sycl/source/detail/queue_impl.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -784,18 +784,19 @@ class queue_impl {
784784
if (Type == CGType::Barrier && !Deps.UnenqueuedCmdEvents.empty()) {
785785
Handler.depends_on(Deps.UnenqueuedCmdEvents);
786786
}
787-
if (Deps.LastBarrier)
787+
if (Deps.LastBarrier && (Type == CGType::CodeplayHostTask ||
788+
(!Deps.LastBarrier->isEnqueued())))
788789
Handler.depends_on(Deps.LastBarrier);
790+
789791
EventRet = Handler.finalize();
790792
EventImplPtr EventRetImpl = getSyclObjImpl(EventRet);
791793
if (Type == CGType::CodeplayHostTask)
792794
Deps.UnenqueuedCmdEvents.push_back(EventRetImpl);
793-
else if (!EventRetImpl->isEnqueued()) {
794-
if (Type == CGType::Barrier || Type == CGType::BarrierWaitlist) {
795-
Deps.LastBarrier = EventRetImpl;
796-
Deps.UnenqueuedCmdEvents.clear();
797-
} else
798-
Deps.UnenqueuedCmdEvents.push_back(EventRetImpl);
795+
else if (Type == CGType::Barrier || Type == CGType::BarrierWaitlist) {
796+
Deps.LastBarrier = EventRetImpl;
797+
Deps.UnenqueuedCmdEvents.clear();
798+
} else if (!EventRetImpl->isEnqueued()) {
799+
Deps.UnenqueuedCmdEvents.push_back(EventRetImpl);
799800
}
800801
}
801802
}

sycl/unittests/scheduler/HostTaskAndBarrier.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ TEST_F(BarrierHandlingWithHostTask, BarrierHostTaskKernel) {
196196
sycl::event HTEvent = AddTask(TestCGType::HOST_TASK);
197197
EventImplPtr HostTaskEventImpl = sycl::detail::getSyclObjImpl(HTEvent);
198198
auto HostTaskWaitList = HostTaskEventImpl->getWaitList();
199-
ASSERT_EQ(HostTaskWaitList.size(), 0u);
199+
ASSERT_EQ(HostTaskWaitList.size(), 1u);
200+
EXPECT_EQ(HostTaskWaitList[0], BarrierEventImpl);
200201
EXPECT_EQ(HostTaskEventImpl->isEnqueued(), true);
201202

202203
sycl::event KernelEvent = AddTask(TestCGType::KERNEL_TASK);
@@ -225,7 +226,8 @@ TEST_F(BarrierHandlingWithHostTask, BarrierKernelHostTask) {
225226
sycl::event HTEvent = AddTask(TestCGType::HOST_TASK);
226227
EventImplPtr HostTaskEventImpl = sycl::detail::getSyclObjImpl(HTEvent);
227228
auto HostTaskWaitList = HostTaskEventImpl->getWaitList();
228-
ASSERT_EQ(HostTaskWaitList.size(), 0u);
229+
ASSERT_EQ(HostTaskWaitList.size(), 1u);
230+
EXPECT_EQ(HostTaskWaitList[0], BarrierEventImpl);
229231
EXPECT_EQ(HostTaskEventImpl->isEnqueued(), true);
230232

231233
MainLock.unlock();
@@ -272,7 +274,8 @@ TEST_F(BarrierHandlingWithHostTask, KernelBarrierHostTask) {
272274
sycl::event HTEvent = AddTask(TestCGType::HOST_TASK);
273275
EventImplPtr HostTaskEventImpl = sycl::detail::getSyclObjImpl(HTEvent);
274276
auto HostTaskWaitList = HostTaskEventImpl->getWaitList();
275-
ASSERT_EQ(HostTaskWaitList.size(), 0u);
277+
ASSERT_EQ(HostTaskWaitList.size(), 1u);
278+
EXPECT_EQ(HostTaskWaitList[0], BarrierEventImpl);
276279
EXPECT_EQ(HostTaskEventImpl->isEnqueued(), true);
277280

278281
MainLock.unlock();

0 commit comments

Comments
 (0)