Skip to content

Commit 4da489c

Browse files
[UR][L0] event pool leak fix
Addresses event pool leak when SYCL_PI_LEVEL_ZERO_DISABLE_EVENTS_CACHING is set Signed-off-by: Zhang, Winston <[email protected]>
1 parent 0ce943e commit 4da489c

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

unified-runtime/source/adapters/level_zero/context.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,20 @@ ur_result_t ur_context_handle_t_::finalize() {
337337
}
338338
ZePoolCache.clear();
339339
}
340+
for (auto &ZePool : ZePoolCleanupList) {
341+
if (NumEventsAvailableInEventPool[ZePool] == 0 &&
342+
checkL0LoaderTeardown()) {
343+
auto ZeResult = ZE_CALL_NOCHECK(zeEventPoolDestroy, (ZePool));
344+
// Gracefully handle the case that L0 was already unloaded.
345+
if (ZeResult && (ZeResult != ZE_RESULT_ERROR_UNINITIALIZED &&
346+
ZeResult != ZE_RESULT_ERROR_UNKNOWN))
347+
return ze2urResult(ZeResult);
348+
if (ZeResult == ZE_RESULT_ERROR_UNKNOWN) {
349+
ZeResult = ZE_RESULT_ERROR_UNINITIALIZED;
350+
}
351+
}
352+
}
353+
ZePoolCleanupList.clear();
340354
}
341355

342356
if (checkL0LoaderTeardown()) {
@@ -420,13 +434,9 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool(
420434
if (!ZePoolCache->empty()) {
421435
if (NumEventsAvailableInEventPool[ZePoolCache->front()] == 0) {
422436
if (DisableEventsCaching) {
423-
// Remove full pool from the cache if events caching is disabled.
437+
ZePoolCleanupList.push_back(*ZePoolCache->begin());
424438
ZePoolCache->erase(ZePoolCache->begin());
425439
} else {
426-
// If event caching is enabled then we don't destroy events so there is
427-
// no need to remove pool from the cache and add it back when it has
428-
// available slots. Just keep it in the tail of the cache so that all
429-
// pools can be destroyed during context destruction.
430440
ZePoolCache->push_front(nullptr);
431441
}
432442
}

unified-runtime/source/adapters/level_zero/context.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ struct ur_context_handle_t_ : ur_object {
160160
std::vector<std::list<ze_event_pool_handle_t>> ZeEventPoolCache{30};
161161
std::vector<std::unordered_map<ze_device_handle_t, size_t>>
162162
ZeEventPoolCacheDeviceMap{30};
163+
std::list<ze_event_pool_handle_t> ZePoolCleanupList;
163164

164165
// This map will be used to determine if a pool is full or not
165166
// by storing number of empty slots available in the pool.

0 commit comments

Comments
 (0)