Skip to content

Commit 8c1dddd

Browse files
authored
[SYCL] Fix calculation of unreleased events in a pool (#4730)
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 <[email protected]>
1 parent d5ba0db commit 8c1dddd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,11 @@ _pi_context::getFreeSlotInExistingOrNewPool(ze_event_pool_handle_t &Pool,
448448
ZE_CALL(zeEventPoolCreate, (ZeContext, &ZeEventPoolDesc, ZeDevices.size(),
449449
&ZeDevices[0], ZePool));
450450
NumEventsAvailableInEventPool[*ZePool] = MaxNumEventsPerPool - 1;
451-
NumEventsUnreleasedInEventPool[*ZePool] = MaxNumEventsPerPool;
451+
NumEventsUnreleasedInEventPool[*ZePool] = 1;
452452
} else {
453453
Index = MaxNumEventsPerPool - NumEventsAvailableInEventPool[*ZePool];
454454
--NumEventsAvailableInEventPool[*ZePool];
455+
++NumEventsUnreleasedInEventPool[*ZePool];
455456
}
456457
Pool = *ZePool;
457458
return PI_SUCCESS;
@@ -466,6 +467,8 @@ pi_result _pi_context::decrementUnreleasedEventsInPool(pi_event Event) {
466467

467468
// Put the empty pool to the cache of the pools.
468469
std::lock_guard<std::mutex> Lock(ZeEventPoolCacheMutex);
470+
if (NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0)
471+
die("Invalid event release: event pool doesn't have unreleased events");
469472
if (--NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0) {
470473
if (ZeEventPoolCache.front() != Event->ZeEventPool) {
471474
ZeEventPoolCache.push_back(Event->ZeEventPool);
@@ -474,6 +477,9 @@ pi_result _pi_context::decrementUnreleasedEventsInPool(pi_event Event) {
474477
}
475478

476479
if (Event->ZeHostVisibleEventPool) {
480+
if (NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0)
481+
die("Invalid host visible event release: host visible event pool doesn't "
482+
"have unreleased events");
477483
if (--NumEventsUnreleasedInEventPool[Event->ZeHostVisibleEventPool] == 0) {
478484
if (ZeHostVisibleEventPoolCache.front() !=
479485
Event->ZeHostVisibleEventPool) {

0 commit comments

Comments
 (0)