From 3bc9820dfccf02239a3d1d8d9b03606d98f1659c Mon Sep 17 00:00:00 2001 From: Artur Gainullin Date: Fri, 8 Oct 2021 01:53:31 -0700 Subject: [PATCH] [SYCL] Fix calculation of unreleased events in a pool Before the change number of unreleased events was set to the maximum at event pool creation and then only decremented at the moment when event from the pool is released. This is not correct for the case when pool is not completely full. Patch fixes calculation of unreleased events in a pool. Signed-off-by: Artur Gainullin --- sycl/plugins/level_zero/pi_level_zero.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 12fe6c79d35a4..1677e0bf47ced 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -448,10 +448,11 @@ _pi_context::getFreeSlotInExistingOrNewPool(ze_event_pool_handle_t &Pool, ZE_CALL(zeEventPoolCreate, (ZeContext, &ZeEventPoolDesc, ZeDevices.size(), &ZeDevices[0], ZePool)); NumEventsAvailableInEventPool[*ZePool] = MaxNumEventsPerPool - 1; - NumEventsUnreleasedInEventPool[*ZePool] = MaxNumEventsPerPool; + NumEventsUnreleasedInEventPool[*ZePool] = 1; } else { Index = MaxNumEventsPerPool - NumEventsAvailableInEventPool[*ZePool]; --NumEventsAvailableInEventPool[*ZePool]; + ++NumEventsUnreleasedInEventPool[*ZePool]; } Pool = *ZePool; return PI_SUCCESS; @@ -466,6 +467,8 @@ pi_result _pi_context::decrementUnreleasedEventsInPool(pi_event Event) { // Put the empty pool to the cache of the pools. std::lock_guard Lock(ZeEventPoolCacheMutex); + if (NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0) + die("Invalid event release: event pool doesn't have unreleased events"); if (--NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0) { if (ZeEventPoolCache.front() != Event->ZeEventPool) { ZeEventPoolCache.push_back(Event->ZeEventPool); @@ -474,6 +477,9 @@ pi_result _pi_context::decrementUnreleasedEventsInPool(pi_event Event) { } if (Event->ZeHostVisibleEventPool) { + if (NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0) + die("Invalid host visible event release: host visible event pool doesn't " + "have unreleased events"); if (--NumEventsUnreleasedInEventPool[Event->ZeHostVisibleEventPool] == 0) { if (ZeHostVisibleEventPoolCache.front() != Event->ZeHostVisibleEventPool) {