diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index f2ac3963b76c6..15b58fa73c7fe 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -3238,10 +3238,16 @@ ur_result_t ExecCGCommand::enqueueImpQueue() { // If the queue is not in-order, we need to insert a barrier. This barrier // does not need output events as it will implicitly enforce the following // enqueue is blocked until it finishes. - if (!MQueue->isInOrder()) + if (!MQueue->isInOrder()) { + // FIXME: Due to a bug in the L0 UR adapter, we will leak events if we do + // not pass an output event to the UR call. Once that is fixed, + // this immediately-deleted event can be removed. + ur_event_handle_t PreTimestampBarrierEvent{}; Plugin->call(urEnqueueEventsWaitWithBarrier, MQueue->getHandleRef(), /*num_events_in_wait_list=*/0, - /*event_wait_list=*/nullptr, /*event=*/nullptr); + /*event_wait_list=*/nullptr, &PreTimestampBarrierEvent); + Plugin->call(urEventRelease, PreTimestampBarrierEvent); + } Plugin->call(urEnqueueTimestampRecordingExp, MQueue->getHandleRef(), /*blocking=*/false, diff --git a/sycl/test-e2e/ProfilingTag/profile_tag_leak.cpp b/sycl/test-e2e/ProfilingTag/profile_tag_leak.cpp new file mode 100644 index 0000000000000..c555a1aa61765 --- /dev/null +++ b/sycl/test-e2e/ProfilingTag/profile_tag_leak.cpp @@ -0,0 +1,18 @@ +// REQUIRES: level_zero + +// RUN: %{build} -o %t.out +// RUN: %{l0_leak_check} %{run} %t.out 2>&1 | FileCheck %s --implicit-check-not=LEAK + +// Regression test to avoid the reintroduction of a leak in L0 in the profiling +// tags when using barriers to ensure ordering on out-of-order queues. + +#include +#include + +int main() { + sycl::queue Queue; + sycl::event TagE = + sycl::ext::oneapi::experimental::submit_profiling_tag(Queue); + Queue.wait(); + return 0; +}