From c49eeda87e2dedddcdb3a82de98868c95f7d5009 Mon Sep 17 00:00:00 2001 From: Artur Gainullin Date: Fri, 28 Oct 2022 12:02:31 -0700 Subject: [PATCH] [SYCL] Queue has to be released later than event (#7225) --- sycl/plugins/level_zero/pi_level_zero.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 28de622547c11..4a669cba8b081 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -6026,20 +6026,25 @@ static pi_result piEventReleaseInternal(pi_event Event) { PI_CALL(piEventReleaseInternal(Event->HostVisibleEvent)); } - // We intentionally incremented the reference counter when an event is - // created so that we can avoid pi_queue is released before the associated - // pi_event is released. Here we have to decrement it so pi_queue - // can be released successfully. - if (Event->Queue) { - PI_CALL(piQueueReleaseInternal(Event->Queue)); - } - + // Save pointer to the queue before deleting/resetting event. + // When we add an event to the cache we need to check whether profiling is + // enabled or not, so we access properties of the queue and that's why queue + // must released later. + auto Queue = Event->Queue; if (DisableEventsCaching || !Event->OwnZeEvent) { delete Event; } else { Event->Context->addEventToCache(Event); } + // We intentionally incremented the reference counter when an event is + // created so that we can avoid pi_queue is released before the associated + // pi_event is released. Here we have to decrement it so pi_queue + // can be released successfully. + if (Queue) { + PI_CALL(piQueueReleaseInternal(Queue)); + } + return PI_SUCCESS; }