Skip to content

Commit 0448cb8

Browse files
committed
Simplify barrier insertion in the beginning of command list
1 parent 81c7a11 commit 0448cb8

File tree

2 files changed

+23
-37
lines changed

2 files changed

+23
-37
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -743,12 +743,8 @@ pi_result _pi_queue::signalEvent(pi_command_list_ptr_t CommandList) {
743743
this, &SpecialEvent, PI_COMMAND_TYPE_USER, CommandList,
744744
/* IsDiscarded */ false, /* ForceHostVisible */ false));
745745

746-
// We want a barrier in the beginning of a next command list waiting for this
747-
// special event.
748-
ActiveBarriers.push_back(SpecialEvent);
749-
750-
// We don't need additional dependency through LastCommandEvent.
751-
LastCommandEvent = nullptr;
746+
PI_CALL(piEventRelease(SpecialEvent));
747+
LastCommandEvent = SpecialEvent;
752748

753749
ZE_CALL(zeCommandListAppendSignalEvent,
754750
(CommandList->first, SpecialEvent->ZeEvent));
@@ -1098,24 +1094,9 @@ _pi_queue::resetCommandList(pi_command_list_ptr_t CommandList,
10981094
std::vector<pi_event> &EventListToCleanup) {
10991095
bool UseCopyEngine = CommandList->second.isCopy(this);
11001096

1101-
if (isInOrderQueue() && isDiscardEvents()) {
1102-
// If there were discarded events in the command list then we have to
1103-
// release events from wait lists associated with them.
1104-
for (auto WaitList : CommandList->second.WaitLists) {
1105-
std::list<pi_event> EventsToBeReleased;
1106-
WaitList.collectEventsForReleaseAndDestroyPiZeEventList(
1107-
EventsToBeReleased);
1108-
1109-
// Event may be in the wait list of more than one event. But we have to
1110-
// cleanup it only once, that's why use unordered_set to make it happen.
1111-
std::unordered_set<pi_event> Events;
1112-
std::copy(EventsToBeReleased.begin(), EventsToBeReleased.end(),
1113-
std::inserter(Events, Events.begin()));
1114-
1115-
for (auto Event : Events)
1116-
EventListToCleanup.push_back(Event);
1117-
}
1118-
CommandList->second.WaitLists.clear();
1097+
if (CommandList->second.SpecialEvent) {
1098+
EventListToCleanup.push_back(CommandList->second.SpecialEvent);
1099+
CommandList->second.SpecialEvent = nullptr;
11191100
}
11201101

11211102
// Immediate commandlists do not have an associated fence.
@@ -1995,6 +1976,20 @@ pi_result _pi_queue::insertActiveBarriers(pi_command_list_ptr_t &CmdList,
19951976
if (ActiveBarriers.empty())
19961977
return PI_SUCCESS;
19971978

1979+
// For in-order queue every command depends on the previous one so we don't
1980+
// need to insert active barriers for every next command list.
1981+
// But we have to handle LastCommandEvent as an active barrier if we have
1982+
// discard_events mode.
1983+
if (isInOrderQueue() && isDiscardEvents() && LastCommandEvent) {
1984+
ZE_CALL(zeCommandListAppendBarrier,
1985+
(CmdList->first, nullptr, 1, &(LastCommandEvent->ZeEvent)));
1986+
CmdList->second.SpecialEvent = LastCommandEvent;
1987+
// This event will be released on command list completion.
1988+
PI_CALL(piEventRetain(CmdList->second.SpecialEvent));
1989+
LastCommandEvent = nullptr;
1990+
return PI_SUCCESS;
1991+
}
1992+
19981993
// Create a wait-list and retain events. This will filter out finished events.
19991994
_pi_ze_event_list_t ActiveBarriersWaitList;
20001995
if (auto Res = ActiveBarriersWaitList.createAndRetainPiZeEventList(
@@ -2007,12 +2002,9 @@ pi_result _pi_queue::insertActiveBarriers(pi_command_list_ptr_t &CmdList,
20072002
PI_CALL(piEventReleaseInternal(BarrierEvent));
20082003
ActiveBarriers.clear();
20092004

2010-
// For in-order queue every command depends on the previous one so we don't
2011-
// need to insert active barriers for every next command list.
2012-
if (!isInOrderQueue())
2013-
ActiveBarriers.insert(
2014-
ActiveBarriers.end(), ActiveBarriersWaitList.PiEventList,
2015-
ActiveBarriersWaitList.PiEventList + ActiveBarriersWaitList.Length);
2005+
ActiveBarriers.insert(
2006+
ActiveBarriers.end(), ActiveBarriersWaitList.PiEventList,
2007+
ActiveBarriersWaitList.PiEventList + ActiveBarriersWaitList.Length);
20162008

20172009
// If there are more active barriers, insert a barrier on the command-list. We
20182010
// do not need an event for finishing so we pass nullptr.
@@ -2021,12 +2013,6 @@ pi_result _pi_queue::insertActiveBarriers(pi_command_list_ptr_t &CmdList,
20212013
(CmdList->first, nullptr, ActiveBarriersWaitList.Length,
20222014
ActiveBarriersWaitList.ZeEventList));
20232015

2024-
// Active barriers are released at queue synchronization, but for in-order
2025-
// queue we don't keep them till that point so store them in the command list,
2026-
// they will be released on completion of command list.
2027-
if (isInOrderQueue())
2028-
CmdList->second.WaitLists.push_back(ActiveBarriersWaitList);
2029-
20302016
return PI_SUCCESS;
20312017
}
20322018

sycl/plugins/level_zero/pi_level_zero.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ struct pi_command_list_info_t {
612612
// only have last one visible to the host.
613613
std::vector<pi_event> EventList{};
614614

615-
std::list<_pi_ze_event_list_t> WaitLists;
615+
pi_event SpecialEvent = nullptr;
616616

617617
size_t size() const { return EventList.size(); }
618618
void append(pi_event Event) { EventList.push_back(Event); }

0 commit comments

Comments
 (0)