Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sycl/source/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,14 @@ event queue::ext_oneapi_submit_barrier(const std::vector<event> &WaitList,
!EventImpl.hasCommandGraph();
});

// If we have an empty in-order queue and no dependencies, we can just return
// a trivially finished event.
if (is_in_order() && !impl->hasCommandGraph() && !impl->MIsProfilingEnabled &&
AllEventsEmptyOrNop && ext_oneapi_empty()) {
return detail::createSyclObjFromImpl<event>(
detail::event_impl::create_default_event());
}

if (WaitList.empty() || AllEventsEmptyOrNop)
return submit([=](handler &CGH) { CGH.ext_oneapi_barrier(); }, CodeLoc);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ int main() {
Q.wait();
assert(*Res == 10);
}
{
// Test cast 3 - empty queue.
std::cout << "Test 3" << std::endl;
sycl::queue EmptyQ({sycl::property::queue::in_order{}});
auto BarrierEvent = EmptyQ.ext_oneapi_submit_barrier();
assert(
BarrierEvent.get_info<sycl::info::event::command_execution_status>() ==
sycl::info::event_command_status::complete);
BarrierEvent.wait();
}
{
// Test cast 4 - graph.
sycl::queue GQueue{sycl::property::queue::in_order{}};
Expand Down
6 changes: 6 additions & 0 deletions sycl/unittests/Extensions/ExtOneapiBarrierOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//

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

// To avoid current optimizations for empty queues, we trick q1 into thinking
// that it isn't empty.
int dummyInt = 0;
q1.prefetch(&dummyInt, sizeof(int));

mock::getCallbacks().set_after_callback(
"urEnqueueEventsWaitWithBarrierExt",
&redefinedEnqueueEventsWaitWithBarrierExt);
Expand Down
Loading