Skip to content

Commit

Permalink
[SYCL] Add sync for host task after barrier (#15345)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
KseniyaTikhomirova authored Sep 11, 2024
1 parent 8d1c9f0 commit d286ca2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
15 changes: 8 additions & 7 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,18 +784,19 @@ class queue_impl {
if (Type == CGType::Barrier && !Deps.UnenqueuedCmdEvents.empty()) {
Handler.depends_on(Deps.UnenqueuedCmdEvents);
}
if (Deps.LastBarrier)
if (Deps.LastBarrier && (Type == CGType::CodeplayHostTask ||
(!Deps.LastBarrier->isEnqueued())))
Handler.depends_on(Deps.LastBarrier);

EventRet = Handler.finalize();
EventImplPtr EventRetImpl = getSyclObjImpl(EventRet);
if (Type == CGType::CodeplayHostTask)
Deps.UnenqueuedCmdEvents.push_back(EventRetImpl);
else if (!EventRetImpl->isEnqueued()) {
if (Type == CGType::Barrier || Type == CGType::BarrierWaitlist) {
Deps.LastBarrier = EventRetImpl;
Deps.UnenqueuedCmdEvents.clear();
} else
Deps.UnenqueuedCmdEvents.push_back(EventRetImpl);
else if (Type == CGType::Barrier || Type == CGType::BarrierWaitlist) {
Deps.LastBarrier = EventRetImpl;
Deps.UnenqueuedCmdEvents.clear();
} else if (!EventRetImpl->isEnqueued()) {
Deps.UnenqueuedCmdEvents.push_back(EventRetImpl);
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions sycl/unittests/scheduler/HostTaskAndBarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ TEST_F(BarrierHandlingWithHostTask, BarrierHostTaskKernel) {
sycl::event HTEvent = AddTask(TestCGType::HOST_TASK);
EventImplPtr HostTaskEventImpl = sycl::detail::getSyclObjImpl(HTEvent);
auto HostTaskWaitList = HostTaskEventImpl->getWaitList();
ASSERT_EQ(HostTaskWaitList.size(), 0u);
ASSERT_EQ(HostTaskWaitList.size(), 1u);
EXPECT_EQ(HostTaskWaitList[0], BarrierEventImpl);
EXPECT_EQ(HostTaskEventImpl->isEnqueued(), true);

sycl::event KernelEvent = AddTask(TestCGType::KERNEL_TASK);
Expand Down Expand Up @@ -225,7 +226,8 @@ TEST_F(BarrierHandlingWithHostTask, BarrierKernelHostTask) {
sycl::event HTEvent = AddTask(TestCGType::HOST_TASK);
EventImplPtr HostTaskEventImpl = sycl::detail::getSyclObjImpl(HTEvent);
auto HostTaskWaitList = HostTaskEventImpl->getWaitList();
ASSERT_EQ(HostTaskWaitList.size(), 0u);
ASSERT_EQ(HostTaskWaitList.size(), 1u);
EXPECT_EQ(HostTaskWaitList[0], BarrierEventImpl);
EXPECT_EQ(HostTaskEventImpl->isEnqueued(), true);

MainLock.unlock();
Expand Down Expand Up @@ -272,7 +274,8 @@ TEST_F(BarrierHandlingWithHostTask, KernelBarrierHostTask) {
sycl::event HTEvent = AddTask(TestCGType::HOST_TASK);
EventImplPtr HostTaskEventImpl = sycl::detail::getSyclObjImpl(HTEvent);
auto HostTaskWaitList = HostTaskEventImpl->getWaitList();
ASSERT_EQ(HostTaskWaitList.size(), 0u);
ASSERT_EQ(HostTaskWaitList.size(), 1u);
EXPECT_EQ(HostTaskWaitList[0], BarrierEventImpl);
EXPECT_EQ(HostTaskEventImpl->isEnqueued(), true);

MainLock.unlock();
Expand Down

0 comments on commit d286ca2

Please sign in to comment.