From 3f572e01e1862ce166621724c6fc91394f050c01 Mon Sep 17 00:00:00 2001 From: "Gainullin, Artur" Date: Wed, 3 Sep 2025 14:35:16 -0700 Subject: [PATCH] [SYCL] Fix barrier on barrier dependency between queues Currently for the pattern like this: sycl::event eb1 = q1.ext_oneapi_submit_barrier(); q2.ext_oneapi_submit_barrier({ eb1 }); the second barrier ignores eb1 in the waitlist because it is not marked as enqueued even though it is supposed to. This PR fixes that. Fixes https://github.com/intel/llvm/issues/19777 --- sycl/source/detail/queue_impl.hpp | 1 + sycl/unittests/queue/Barrier.cpp | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index ca800e1511032..55f87188400d0 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -662,6 +662,7 @@ class queue_impl : public std::enable_shared_from_this { getAdapter().call(getHandleRef(), 0, nullptr, &UREvent); ResEvent->setHandle(UREvent); + ResEvent->setEnqueued(); return ResEvent; } diff --git a/sycl/unittests/queue/Barrier.cpp b/sycl/unittests/queue/Barrier.cpp index b13d703085fc4..c2df018e16de1 100644 --- a/sycl/unittests/queue/Barrier.cpp +++ b/sycl/unittests/queue/Barrier.cpp @@ -8,13 +8,19 @@ #include #include +#include #include static unsigned NumOfEventsWaitWithBarrierCalls = 0; +static unsigned NumEventsInWaitList = 0; -static ur_result_t redefined_urEnqueueEventsWaitWithBarrierExt(void *) { +static ur_result_t redefined_urEnqueueEventsWaitWithBarrierExt(void *pParams) { NumOfEventsWaitWithBarrierCalls++; + // Get the number of events in the wait list + auto params = + *static_cast(pParams); + NumEventsInWaitList = *params.pnumEventsInWaitList; return UR_RESULT_SUCCESS; } @@ -94,3 +100,17 @@ TEST(Queue, ExtOneAPISubmitBarrierWithWaitList) { ASSERT_EQ(NumOfEventsWaitWithBarrierCalls, 1u); } + +TEST(Queue, BarrierWithBarrierDep) { + sycl::unittest::UrMock<> Mock; + mock::getCallbacks().set_before_callback( + "urEnqueueEventsWaitWithBarrierExt", + &redefined_urEnqueueEventsWaitWithBarrierExt); + sycl::queue Q1(sycl::property::queue::in_order{}); + sycl::queue Q2(sycl::property::queue::in_order{}); + Q1.submit([&](sycl::handler &cgh) { cgh.single_task([=]() {}); }); + sycl::event Barrier1 = Q1.ext_oneapi_submit_barrier(); + NumEventsInWaitList = 0; + Q2.ext_oneapi_submit_barrier({Barrier1}); + ASSERT_EQ(NumEventsInWaitList, 1u); +}