@@ -406,7 +406,7 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool(
406406 ze_event_pool_handle_t &Pool, size_t &Index, bool HostVisible,
407407 bool ProfilingEnabled, ur_device_handle_t Device,
408408 bool CounterBasedEventEnabled, bool UsingImmCmdList,
409- bool InterruptBasedEventEnabled) {
409+ bool InterruptBasedEventEnabled, ur_queue_handle_t Queue ) {
410410
411411 ze_device_handle_t ZeDevice = nullptr ;
412412 if (Device) {
@@ -461,8 +461,21 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool(
461461 });
462462 }
463463
464- ZE2UR_CALL (zeEventPoolCreate, (ZeContext, &ZeEventPoolDesc,
465- ZeDevices.size (), &ZeDevices[0 ], &Pool));
464+ ze_result_t Result = ZE_CALL_NOCHECK (
465+ zeEventPoolCreate,
466+ (ZeContext, &ZeEventPoolDesc, ZeDevices.size (), &ZeDevices[0 ], &Pool));
467+ if (ze2urResult (Result) == UR_RESULT_ERROR_OUT_OF_RESOURCES &&
468+ !Queue->isInOrderQueue ()) {
469+ if (Queue->UsingImmCmdLists ) {
470+ UR_CALL (CleanupEventsInImmCmdLists (Queue, true /* QueueLocked*/ ,
471+ false /* QueueSynced*/ ,
472+ nullptr /* CompletedEvent*/ ));
473+ } else {
474+ UR_CALL (resetCommandLists (Queue));
475+ }
476+ ZE2UR_CALL (zeEventPoolCreate, (ZeContext, &ZeEventPoolDesc,
477+ ZeDevices.size (), &ZeDevices[0 ], &Pool));
478+ }
466479 Index = 0 ;
467480 NumEventsAvailableInEventPool[Pool] = MaxNumEventsPerPool - 1 ;
468481 NumEventsUnreleasedInEventPool[Pool] = 1 ;
@@ -546,8 +559,21 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool(
546559 });
547560 }
548561
549- ZE2UR_CALL (zeEventPoolCreate, (ZeContext, &ZeEventPoolDesc,
550- ZeDevices.size (), &ZeDevices[0 ], ZePool));
562+ ze_result_t Result = ZE_CALL_NOCHECK (
563+ zeEventPoolCreate,
564+ (ZeContext, &ZeEventPoolDesc, ZeDevices.size (), &ZeDevices[0 ], &Pool));
565+ if (ze2urResult (Result) == UR_RESULT_ERROR_OUT_OF_RESOURCES &&
566+ !Queue->isInOrderQueue ()) {
567+ if (Queue->UsingImmCmdLists ) {
568+ UR_CALL (CleanupEventsInImmCmdLists (Queue, true /* QueueLocked*/ ,
569+ false /* QueueSynced*/ ,
570+ nullptr /* CompletedEvent*/ ));
571+ } else {
572+ UR_CALL (resetCommandLists (Queue));
573+ }
574+ ZE2UR_CALL (zeEventPoolCreate, (ZeContext, &ZeEventPoolDesc,
575+ ZeDevices.size (), &ZeDevices[0 ], &Pool));
576+ }
551577 NumEventsAvailableInEventPool[*ZePool] = MaxNumEventsPerPool - 1 ;
552578 NumEventsUnreleasedInEventPool[*ZePool] = 1 ;
553579 } else {
0 commit comments