@@ -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, bool IsInternal ) {
410410
411411 ze_device_handle_t ZeDevice = nullptr ;
412412 if (Device) {
@@ -461,8 +461,25 @@ 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 (IsInternal && ze2urResult (Result) == UR_RESULT_ERROR_OUT_OF_RESOURCES &&
468+ Queue) {
469+ if (!Queue->isInOrderQueue ()) {
470+ if (Queue->UsingImmCmdLists ) {
471+ UR_CALL (CleanupEventsInImmCmdLists (Queue, true /* QueueLocked*/ ,
472+ false /* QueueSynced*/ ,
473+ nullptr /* CompletedEvent*/ ));
474+ } else {
475+ UR_CALL (resetCommandLists (Queue));
476+ }
477+ ZE2UR_CALL (zeEventPoolCreate, (ZeContext, &ZeEventPoolDesc,
478+ ZeDevices.size (), &ZeDevices[0 ], &Pool));
479+ }
480+ } else if (ze2urResult (Result) != UR_RESULT_SUCCESS) {
481+ return ze2urResult (Result);
482+ }
466483 Index = 0 ;
467484 NumEventsAvailableInEventPool[Pool] = MaxNumEventsPerPool - 1 ;
468485 NumEventsUnreleasedInEventPool[Pool] = 1 ;
@@ -546,8 +563,25 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool(
546563 });
547564 }
548565
549- ZE2UR_CALL (zeEventPoolCreate, (ZeContext, &ZeEventPoolDesc,
550- ZeDevices.size (), &ZeDevices[0 ], ZePool));
566+ ze_result_t Result = ZE_CALL_NOCHECK (
567+ zeEventPoolCreate,
568+ (ZeContext, &ZeEventPoolDesc, ZeDevices.size (), &ZeDevices[0 ], &Pool));
569+ if (IsInternal && ze2urResult (Result) == UR_RESULT_ERROR_OUT_OF_RESOURCES &&
570+ Queue) {
571+ if (!Queue->isInOrderQueue ()) {
572+ if (Queue->UsingImmCmdLists ) {
573+ UR_CALL (CleanupEventsInImmCmdLists (Queue, true /* QueueLocked*/ ,
574+ false /* QueueSynced*/ ,
575+ nullptr /* CompletedEvent*/ ));
576+ } else {
577+ UR_CALL (resetCommandLists (Queue));
578+ }
579+ ZE2UR_CALL (zeEventPoolCreate, (ZeContext, &ZeEventPoolDesc,
580+ ZeDevices.size (), &ZeDevices[0 ], &Pool));
581+ }
582+ } else if (ze2urResult (Result) != UR_RESULT_SUCCESS) {
583+ return ze2urResult (Result);
584+ }
551585 NumEventsAvailableInEventPool[*ZePool] = MaxNumEventsPerPool - 1 ;
552586 NumEventsUnreleasedInEventPool[*ZePool] = 1 ;
553587 } else {
0 commit comments