From f1ef5b98bcf40db7621c4fc59cc50519401c65d5 Mon Sep 17 00:00:00 2001 From: Artur Gainullin Date: Thu, 4 Sep 2025 07:41:37 -0700 Subject: [PATCH] [SYCL] Fix barrier on barrier dependency between queues (#19970) 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 839570553f3ce..86a35e5ffac6c 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -667,6 +667,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); +}