@@ -661,8 +661,6 @@ ze_result_t ZeCall::doCall(ze_result_t ZeResult, const char *ZeName,
661
661
662
662
pi_result _pi_queue::setLastDiscardedEvent (pi_event Event) {
663
663
try {
664
- // We expect previous event to be in the cache.
665
- assert (LastDiscardedEvent == nullptr );
666
664
LastDiscardedEvent = new _pi_event (Event->ZeEvent , Event->ZeEventPool ,
667
665
Context, PI_COMMAND_TYPE_USER, true );
668
666
} catch (const std::bad_alloc &) {
@@ -679,17 +677,17 @@ pi_result _pi_queue::setLastDiscardedEvent(pi_event Event) {
679
677
680
678
pi_result
681
679
_pi_queue::resetLastDiscardedEvent (pi_command_list_ptr_t CommandList) {
682
- if (LastCommandEvent && LastCommandEvent->IsDiscarded &&
683
- CommandList != CommandListMap.end ()) {
680
+ if (LastCommandEvent && LastCommandEvent->IsDiscarded ) {
684
681
ZE_CALL (zeCommandListAppendBarrier,
685
682
(CommandList->first , nullptr , 1 , &(LastCommandEvent->ZeEvent )));
686
683
ZE_CALL (zeCommandListAppendEventReset,
687
684
(CommandList->first , LastCommandEvent->ZeEvent ));
688
685
689
- // Remember last discarded event. Can't put it to the cache right now to
690
- // avoid taking it as the next discarded event which will cause using same
691
- // event two times in a row. We need to round robin between two events.
692
- setLastDiscardedEvent (LastCommandEvent);
686
+ // Put previous discarded event to the cache.
687
+ if (LastDiscardedEvent)
688
+ PI_CALL (addEventToCache (LastDiscardedEvent));
689
+ // Update last discarded event. It will be put to the cache after submission of the next command.
690
+ PI_CALL (setLastDiscardedEvent (LastCommandEvent));
693
691
}
694
692
return PI_SUCCESS;
695
693
}
@@ -715,13 +713,6 @@ inline static pi_result createEventAndAssociateQueue(
715
713
// If event is discarded then try to get event from the queue cache.
716
714
*Event = IsInternal ? Queue->getEventFromCache (ForceHostVisible) : nullptr ;
717
715
718
- if (IsInternal && Queue->LastDiscardedEvent ) {
719
- // We've possibly got discarded event above so it is time to reset the last
720
- // disarded event (if any) and put it to the cache.
721
- PI_CALL (Queue->addEventToCache (Queue->LastDiscardedEvent ));
722
- Queue->LastDiscardedEvent = nullptr ;
723
- }
724
-
725
716
if (*Event == nullptr )
726
717
PI_CALL (EventCreate (Queue->Context , Queue, ForceHostVisible, Event));
727
718
@@ -1661,8 +1652,9 @@ pi_result _pi_queue::executeCommandList(pi_command_list_ptr_t CommandList,
1661
1652
if (!CommandList->second .EventList .empty () &&
1662
1653
this ->LastCommandEvent != CommandList->second .EventList .back ()) {
1663
1654
this ->LastCommandEvent = CommandList->second .EventList .back ();
1664
- if (this ->LastCommandEvent ->IsDiscarded )
1655
+ if (this ->LastCommandEvent ->IsDiscarded ) {
1665
1656
PI_CALL (resetLastDiscardedEvent (CommandList));
1657
+ }
1666
1658
}
1667
1659
1668
1660
this ->LastCommandList = CommandList;
0 commit comments