@@ -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,22 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool(
461461 });
462462 }
463463
464- ZE2UR_CALL (zeEventPoolCreate, (ZeContext, &ZeEventPoolDesc,
465- ZeDevices.size (), &ZeDevices[0 ], &Pool));
464+ ur_result_t Result = UR_CALL_NOCHECK (
465+ zeEventPoolCreate,
466+ (ZeContext, &ZeEventPoolDesc, ZeDevices.size (), &ZeDevices[0 ],
467+ &Pool)) if (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+ ur_result_t Result = UR_CALL_NOCHECK (
477+ zeEventPoolCreate,
478+ (ZeContext, &ZeEventPoolDesc, ZeDevices.size (), &ZeDevices[0 ], &Pool))
479+ }
466480 Index = 0 ;
467481 NumEventsAvailableInEventPool[Pool] = MaxNumEventsPerPool - 1 ;
468482 NumEventsUnreleasedInEventPool[Pool] = 1 ;
@@ -546,8 +560,22 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool(
546560 });
547561 }
548562
549- ZE2UR_CALL (zeEventPoolCreate, (ZeContext, &ZeEventPoolDesc,
550- ZeDevices.size (), &ZeDevices[0 ], ZePool));
563+ ur_result_t Result = UR_CALL_NOCHECK (
564+ zeEventPoolCreate,
565+ (ZeContext, &ZeEventPoolDesc, ZeDevices.size (), &ZeDevices[0 ],
566+ &Pool)) if (Result == UR_RESULT_ERROR_OUT_OF_RESOURCES &&
567+ !Queue->isInOrderQueue ()) {
568+ if (Queue->UsingImmCmdLists ) {
569+ UR_CALL (CleanupEventsInImmCmdLists (Queue, true /* QueueLocked*/ ,
570+ false /* QueueSynced*/ ,
571+ nullptr /* CompletedEvent*/ ));
572+ } else {
573+ UR_CALL (resetCommandLists (Queue));
574+ }
575+ UR_CALL_NOCHECK (
576+ zeEventPoolCreate,
577+ (ZeContext, &ZeEventPoolDesc, ZeDevices.size (), &ZeDevices[0 ], &Pool))
578+ }
551579 NumEventsAvailableInEventPool[*ZePool] = MaxNumEventsPerPool - 1 ;
552580 NumEventsUnreleasedInEventPool[*ZePool] = 1 ;
553581 } else {
0 commit comments