From 3b89f1f268989481213c4dd45343c2355f0bbf2e Mon Sep 17 00:00:00 2001 From: "Larsen, Steffen" Date: Wed, 7 Aug 2024 06:36:05 -0700 Subject: [PATCH] [SYCL] Add work-around for event leak in profiling tag Due to a bug in the L0 UR adapter, the profiling tag extension leaks UR events on out-of-order queues. This is not due to the profiling tag events themselves, but rather due to the need for a barrier enforcing correct ordering of the inserted tag. Since the barrier ensures completion prior to the profiling tag executing, the output event is not needed, but the L0 adapter leaks the event if no output event is specified. To combat this, this work-around passes an output event and immediately frees it after the barrier has been submitted. See https://github.com/oneapi-src/unified-runtime/issues/1947. Signed-off-by: Larsen, Steffen --- sycl/source/detail/scheduler/commands.cpp | 10 ++++++++-- .../test-e2e/ProfilingTag/profile_tag_leak.cpp | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 sycl/test-e2e/ProfilingTag/profile_tag_leak.cpp 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; +}