Skip to content

Commit

Permalink
[SYCL] Add work-around for event leak in profiling tag
Browse files Browse the repository at this point in the history
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 oneapi-src/unified-runtime#1947.

Signed-off-by: Larsen, Steffen <[email protected]>
  • Loading branch information
steffenlarsen committed Aug 7, 2024
1 parent 00c8e63 commit 3b89f1f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions sycl/test-e2e/ProfilingTag/profile_tag_leak.cpp
Original file line number Diff line number Diff line change
@@ -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 <sycl/detail/core.hpp>
#include <sycl/ext/oneapi/experimental/profiling_tag.hpp>

int main() {
sycl::queue Queue;
sycl::event TagE =
sycl::ext::oneapi::experimental::submit_profiling_tag(Queue);
Queue.wait();
return 0;
}

0 comments on commit 3b89f1f

Please sign in to comment.