Skip to content

Commit b180fda

Browse files
[SYCL] Reintroduce barrier trivial event for empty in-order queue (#20353)
This is a cherry-pick of #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. Patch-by: Larsen, Steffen <[email protected]>
1 parent 6ffec83 commit b180fda

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
@@ -359,6 +359,14 @@ event queue::ext_oneapi_submit_barrier(const std::vector<event> &WaitList,
359359
!EventImpl.hasCommandGraph();
360360
});
361361

362+
// If we have an empty in-order queue and no dependencies, we can just return
363+
// a trivially finished event.
364+
if (is_in_order() && !impl->hasCommandGraph() && !impl->MIsProfilingEnabled &&
365+
AllEventsEmptyOrNop && ext_oneapi_empty()) {
366+
return detail::createSyclObjFromImpl<event>(
367+
detail::event_impl::create_default_event());
368+
}
369+
362370
if (WaitList.empty() || AllEventsEmptyOrNop)
363371
return submit([=](handler &CGH) { CGH.ext_oneapi_barrier(); }, CodeLoc);
364372
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)