Skip to content

Commit 887370e

Browse files
[SYCL][L0] Wait for all events completion to do full cleanup (#3985)
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent b2b24b9 commit 887370e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4371,8 +4371,21 @@ pi_result piEventRelease(pi_event Event) {
43714371
die("piEventRelease: called on a destroyed event");
43724372
}
43734373

4374+
// The event is no longer needed upstream, but we have to wait for its
4375+
// completion in order to do proper cleanup. Otherwise refcount may still be
4376+
// non-zero in the check below and we will get event leak.
4377+
//
4378+
// TODO: in case this potentially "early" wait causes performance problems,
4379+
// e.g. due to closing a batch too early, or blocking the host for no good
4380+
// reason, then we should look into moving the wait down to queue release
4381+
// (will need to remember all events in the queue for that).
4382+
//
4383+
if (!Event->CleanedUp)
4384+
PI_CALL(piEventsWait(1, &Event));
4385+
43744386
if (--(Event->RefCount) == 0) {
4375-
cleanupAfterEvent(Event);
4387+
if (!Event->CleanedUp)
4388+
cleanupAfterEvent(Event);
43764389

43774390
if (Event->CommandType == PI_COMMAND_TYPE_MEM_BUFFER_UNMAP &&
43784391
Event->CommandData) {

0 commit comments

Comments
 (0)