Skip to content

Commit b5567c5

Browse files
[SYCL] Reintroduce barrier trivial event for empty in-order queue (#20263)
The changes in #20159 removed a test case checking that barriers on empty queues would be considered complete immediately. This commit reintroduces it with a fix for the case. --------- Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
1 parent 41a107a commit b5567c5

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

sycl/source/queue.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,14 @@ event queue::ext_oneapi_submit_barrier(const std::vector<event> &WaitList,
366366
!EventImpl.hasCommandGraph();
367367
});
368368

369+
// If we have an empty in-order queue and no dependencies, we can just return
370+
// a trivially finished event.
371+
if (is_in_order() && !impl->hasCommandGraph() && !impl->MIsProfilingEnabled &&
372+
AllEventsEmptyOrNop && ext_oneapi_empty()) {
373+
return detail::createSyclObjFromImpl<event>(
374+
detail::event_impl::create_default_event());
375+
}
376+
369377
if (WaitList.empty() || AllEventsEmptyOrNop)
370378
return submit([=](handler &CGH) { CGH.ext_oneapi_barrier(); }, CodeLoc);
371379
else

sycl/test-e2e/InorderQueue/in_order_ext_oneapi_submit_barrier.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ int main() {
6060
Q.wait();
6161
assert(*Res == 10);
6262
}
63+
{
64+
// Test cast 3 - empty queue.
65+
std::cout << "Test 3" << std::endl;
66+
sycl::queue EmptyQ({sycl::property::queue::in_order{}});
67+
auto BarrierEvent = EmptyQ.ext_oneapi_submit_barrier();
68+
assert(
69+
BarrierEvent.get_info<sycl::info::event::command_execution_status>() ==
70+
sycl::info::event_command_status::complete);
71+
BarrierEvent.wait();
72+
}
6373
{
6474
// Test cast 4 - graph.
6575
sycl::queue GQueue{sycl::property::queue::in_order{}};

sycl/unittests/Extensions/ExtOneapiBarrierOpt.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include <detail/queue_impl.hpp>
910
#include <gtest/gtest.h>
1011
#include <helpers/ScopedEnvVar.hpp>
1112
#include <helpers/UrMock.hpp>
@@ -39,6 +40,11 @@ class ExtOneapiBarrierOptTest : public ::testing::Test {
3940
TEST_F(ExtOneapiBarrierOptTest, EmptyEventTest) {
4041
sycl::queue q1{{sycl::property::queue::in_order()}};
4142

43+
// To avoid current optimizations for empty queues, we trick q1 into thinking
44+
// that it isn't empty.
45+
int dummyInt = 0;
46+
q1.prefetch(&dummyInt, sizeof(int));
47+
4248
mock::getCallbacks().set_after_callback(
4349
"urEnqueueEventsWaitWithBarrierExt",
4450
&redefinedEnqueueEventsWaitWithBarrierExt);

0 commit comments

Comments
 (0)