Skip to content

Commit 235e039

Browse files
committed
Add to cache in executeCommandList
1 parent 563b05f commit 235e039

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,6 @@ ze_result_t ZeCall::doCall(ze_result_t ZeResult, const char *ZeName,
661661

662662
pi_result _pi_queue::setLastDiscardedEvent(pi_event Event) {
663663
try {
664-
// We expect previous event to be in the cache.
665-
assert(LastDiscardedEvent == nullptr);
666664
LastDiscardedEvent = new _pi_event(Event->ZeEvent, Event->ZeEventPool,
667665
Context, PI_COMMAND_TYPE_USER, true);
668666
} catch (const std::bad_alloc &) {
@@ -679,17 +677,17 @@ pi_result _pi_queue::setLastDiscardedEvent(pi_event Event) {
679677

680678
pi_result
681679
_pi_queue::resetLastDiscardedEvent(pi_command_list_ptr_t CommandList) {
682-
if (LastCommandEvent && LastCommandEvent->IsDiscarded &&
683-
CommandList != CommandListMap.end()) {
680+
if (LastCommandEvent && LastCommandEvent->IsDiscarded) {
684681
ZE_CALL(zeCommandListAppendBarrier,
685682
(CommandList->first, nullptr, 1, &(LastCommandEvent->ZeEvent)));
686683
ZE_CALL(zeCommandListAppendEventReset,
687684
(CommandList->first, LastCommandEvent->ZeEvent));
688685

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));
693691
}
694692
return PI_SUCCESS;
695693
}
@@ -715,13 +713,6 @@ inline static pi_result createEventAndAssociateQueue(
715713
// If event is discarded then try to get event from the queue cache.
716714
*Event = IsInternal ? Queue->getEventFromCache(ForceHostVisible) : nullptr;
717715

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-
725716
if (*Event == nullptr)
726717
PI_CALL(EventCreate(Queue->Context, Queue, ForceHostVisible, Event));
727718

@@ -1661,8 +1652,9 @@ pi_result _pi_queue::executeCommandList(pi_command_list_ptr_t CommandList,
16611652
if (!CommandList->second.EventList.empty() &&
16621653
this->LastCommandEvent != CommandList->second.EventList.back()) {
16631654
this->LastCommandEvent = CommandList->second.EventList.back();
1664-
if (this->LastCommandEvent->IsDiscarded)
1655+
if (this->LastCommandEvent->IsDiscarded) {
16651656
PI_CALL(resetLastDiscardedEvent(CommandList));
1657+
}
16661658
}
16671659

16681660
this->LastCommandList = CommandList;

0 commit comments

Comments
 (0)