@@ -2004,27 +2004,38 @@ pi_result _pi_queue::insertActiveBarriers(pi_command_list_ptr_t &CmdList,
2004
2004
if (ActiveBarriers.empty ())
2005
2005
return PI_SUCCESS;
2006
2006
2007
- // Create a wait-list and retain events. This will filter out finished events.
2007
+ // Create a wait-list and retain events.
2008
2008
_pi_ze_event_list_t ActiveBarriersWaitList;
2009
2009
if (auto Res = ActiveBarriersWaitList.createAndRetainPiZeEventList (
2010
- ActiveBarriers.size (), ActiveBarriers.data (), this , UseCopyEngine))
2010
+ ActiveBarriers.vector ().size (), ActiveBarriers.vector ().data (), this ,
2011
+ UseCopyEngine))
2011
2012
return Res;
2012
2013
2013
- // We can now release all the active barriers and replace them with the ones
2014
- // in the wait list.
2015
- for (pi_event &BarrierEvent : ActiveBarriers)
2016
- PI_CALL (piEventReleaseInternal (BarrierEvent));
2014
+ // We can now replace active barriers with the ones in the wait list.
2017
2015
ActiveBarriers.clear ();
2018
- ActiveBarriers.insert (
2019
- ActiveBarriers.end (), ActiveBarriersWaitList.PiEventList ,
2020
- ActiveBarriersWaitList.PiEventList + ActiveBarriersWaitList.Length );
2016
+
2017
+ if (ActiveBarriersWaitList.Length == 0 ) {
2018
+ return PI_SUCCESS;
2019
+ }
2020
+
2021
+ for (pi_uint32 I = 0 ; I < ActiveBarriersWaitList.Length ; ++I) {
2022
+ auto &Event = ActiveBarriersWaitList.PiEventList [I];
2023
+ ActiveBarriers.add (Event);
2024
+ }
2025
+
2026
+ pi_event Event = nullptr ;
2027
+ if (auto Res = createEventAndAssociateQueue (
2028
+ this , &Event, PI_COMMAND_TYPE_USER, CmdList, /* IsInternal*/ true ))
2029
+ return Res;
2030
+
2031
+ Event->WaitList = ActiveBarriersWaitList;
2032
+ Event->OwnZeEvent = true ;
2021
2033
2022
2034
// If there are more active barriers, insert a barrier on the command-list. We
2023
2035
// do not need an event for finishing so we pass nullptr.
2024
- if (!ActiveBarriers.empty ())
2025
- ZE_CALL (zeCommandListAppendBarrier,
2026
- (CmdList->first , nullptr , ActiveBarriersWaitList.Length ,
2027
- ActiveBarriersWaitList.ZeEventList ));
2036
+ ZE_CALL (zeCommandListAppendBarrier,
2037
+ (CmdList->first , nullptr , ActiveBarriersWaitList.Length ,
2038
+ ActiveBarriersWaitList.ZeEventList ));
2028
2039
return PI_SUCCESS;
2029
2040
}
2030
2041
@@ -6191,6 +6202,17 @@ pi_result piEventRelease(pi_event Event) {
6191
6202
return PI_SUCCESS;
6192
6203
}
6193
6204
6205
+ void _pi_queue::active_barriers::add (pi_event &Event) {
6206
+ Event->RefCount .increment ();
6207
+ Events.push_back (Event);
6208
+ }
6209
+
6210
+ void _pi_queue::active_barriers::clear () {
6211
+ for (const auto &Event : Events)
6212
+ piEventReleaseInternal (Event);
6213
+ Events.clear ();
6214
+ }
6215
+
6194
6216
static pi_result piEventReleaseInternal (pi_event Event) {
6195
6217
PI_ASSERT (Event, PI_ERROR_INVALID_EVENT);
6196
6218
@@ -6561,6 +6583,7 @@ pi_result piEnqueueEventsWaitWithBarrier(pi_queue Queue,
6561
6583
if (auto Res = createEventAndAssociateQueue (
6562
6584
Queue, &Event, PI_COMMAND_TYPE_USER, CmdList, IsInternal))
6563
6585
return Res;
6586
+
6564
6587
Event->WaitList = EventWaitList;
6565
6588
ZE_CALL (zeCommandListAppendBarrier,
6566
6589
(CmdList->first , Event->ZeEvent , EventWaitList.Length ,
@@ -6611,21 +6634,13 @@ pi_result piEnqueueEventsWaitWithBarrier(pi_queue Queue,
6611
6634
// Because of the dependency between commands in the in-order queue we don't
6612
6635
// need to keep track of any active barriers if we have in-order queue.
6613
6636
if (UseMultipleCmdlistBarriers && !Queue->isInOrderQueue ()) {
6614
- // Retain and save the resulting event for future commands.
6615
- (*Event)->RefCount .increment ();
6616
- Queue->ActiveBarriers .push_back (*Event);
6637
+ Queue->ActiveBarriers .add (*Event);
6617
6638
}
6618
6639
return PI_SUCCESS;
6619
6640
}
6620
6641
6621
6642
// Since there are no events to explicitly create a barrier for, we are
6622
- // inserting a queue-wide barrier. As such, the barrier will also encapsulate
6623
- // the active barriers, so we can release and clear the active barriers list.
6624
- // Doing it early prevents potential additional barriers from implicitly being
6625
- // appended.
6626
- for (pi_event &E : Queue->ActiveBarriers )
6627
- PI_CALL (piEventReleaseInternal (E));
6628
- Queue->ActiveBarriers .clear ();
6643
+ // inserting a queue-wide barrier.
6629
6644
6630
6645
// Command list(s) for putting barriers.
6631
6646
std::vector<pi_command_list_ptr_t > CmdLists;
@@ -6688,11 +6703,12 @@ pi_result piEnqueueEventsWaitWithBarrier(pi_queue Queue,
6688
6703
// Insert a barrier into each unique command queue using the available
6689
6704
// command-lists.
6690
6705
std::vector<pi_event> EventWaitVector (CmdLists.size ());
6691
- for (size_t I = 0 ; I < CmdLists.size (); ++I)
6692
- if (auto Res = insertBarrierIntoCmdList (
6693
- CmdLists[I], _pi_ze_event_list_t {}, EventWaitVector[I], false ))
6706
+ for (size_t I = 0 ; I < CmdLists.size (); ++I) {
6707
+ if (auto Res =
6708
+ insertBarrierIntoCmdList (CmdLists[I], _pi_ze_event_list_t {},
6709
+ EventWaitVector[I], /* IsInternal*/ true ))
6694
6710
return Res;
6695
-
6711
+ }
6696
6712
// If there were multiple queues we need to create a "convergence" event to
6697
6713
// be our active barrier. This convergence event is signalled by a barrier
6698
6714
// on all the events from the barriers we have inserted into each queue.
@@ -6706,8 +6722,6 @@ pi_result piEnqueueEventsWaitWithBarrier(pi_queue Queue,
6706
6722
EventWaitVector.size (), EventWaitVector.data (), Queue,
6707
6723
ConvergenceCmdList->second .isCopy (Queue)))
6708
6724
return Res;
6709
- for (pi_event &E : EventWaitVector)
6710
- PI_CALL (piEventReleaseInternal (E));
6711
6725
6712
6726
// Insert a barrier with the events from each command-queue into the
6713
6727
// convergence command list. The resulting event signals the convergence of
@@ -6729,9 +6743,8 @@ pi_result piEnqueueEventsWaitWithBarrier(pi_queue Queue,
6729
6743
if (auto Res = Queue->executeCommandList (CmdList, false , OkToBatch))
6730
6744
return Res;
6731
6745
6732
- // We must keep the event internally to use if new command lists are created.
6733
- (*Event)->RefCount .increment ();
6734
- Queue->ActiveBarriers .push_back (*Event);
6746
+ Queue->ActiveBarriers .clear ();
6747
+ Queue->ActiveBarriers .add (*Event);
6735
6748
return PI_SUCCESS;
6736
6749
}
6737
6750
@@ -6838,10 +6851,7 @@ pi_result _pi_queue::synchronize() {
6838
6851
6839
6852
// With the entire queue synchronized, the active barriers must be done so we
6840
6853
// can remove them.
6841
- for (pi_event &BarrierEvent : ActiveBarriers)
6842
- PI_CALL (piEventReleaseInternal (BarrierEvent));
6843
6854
ActiveBarriers.clear ();
6844
-
6845
6855
return PI_SUCCESS;
6846
6856
}
6847
6857
0 commit comments