@@ -986,6 +986,7 @@ pi_result _pi_ze_event_list_t::createAndRetainPiZeEventList(
986
986
987
987
for (pi_uint32 I = 0 ; I < this ->Length ; I++) {
988
988
PI_CALL (piEventRetain (this ->PiEventList [I]));
989
+
989
990
}
990
991
991
992
return PI_SUCCESS;
@@ -4481,8 +4482,8 @@ static pi_result enqueueMemCopyHelper(pi_command_type CommandType,
4481
4482
(*Event)->WaitList = TmpWaitList;
4482
4483
4483
4484
const auto &WaitList = (*Event)->WaitList ;
4484
-
4485
4485
if (WaitList.Length ) {
4486
+
4486
4487
ZE_CALL (zeCommandListAppendWaitOnEvents,
4487
4488
(ZeCommandList, WaitList.Length , WaitList.ZeEventList ));
4488
4489
}
@@ -4815,15 +4816,23 @@ pi_result piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer,
4815
4816
// For integrated devices the buffer has been allocated in host memory.
4816
4817
if (Buffer->OnHost ) {
4817
4818
// Wait on incoming events before doing the copy
4818
- if (Queue->isInOrderQueue () && Queue->LastCommandEvent != nullptr ) {
4819
- PI_CALL (piEventsWait (1 , &(Queue->LastCommandEvent )));
4819
+ PI_CALL (piEventsWait (NumEventsInWaitList, EventWaitList));
4820
4820
4821
- // Lock automatically releases when this goes out of scope.
4822
- std::lock_guard<std::mutex> lock (Queue->PiQueueMutex );
4823
- Queue->LastCommandEvent = *Event;
4824
- }
4821
+ if (Queue->isInOrderQueue ()) {
4822
+ pi_event TmpLastCommandEvent = nullptr ;
4825
4823
4826
- PI_CALL (piEventsWait (NumEventsInWaitList, EventWaitList));
4824
+ {
4825
+ // Lock automatically releases when this goes out of scope.
4826
+ std::lock_guard<std::mutex> lock (Queue->PiQueueMutex );
4827
+ if (Queue->LastCommandEvent != nullptr ) {
4828
+ TmpLastCommandEvent = Queue->LastCommandEvent ;
4829
+ }
4830
+ }
4831
+
4832
+ if (TmpLastCommandEvent != nullptr ) {
4833
+ PI_CALL (piEventsWait (1 , &TmpLastCommandEvent));
4834
+ }
4835
+ }
4827
4836
4828
4837
if (Buffer->MapHostPtr ) {
4829
4838
*RetMap = Buffer->MapHostPtr + Offset;
@@ -4833,6 +4842,12 @@ pi_result piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer,
4833
4842
*RetMap = pi_cast<char *>(Buffer->getZeHandle ()) + Offset;
4834
4843
}
4835
4844
4845
+ {
4846
+ // Lock automatically releases when this goes out of scope.
4847
+ std::lock_guard<std::mutex> lock (Queue->PiQueueMutex );
4848
+ Queue->LastCommandEvent = *Event;
4849
+ }
4850
+
4836
4851
// Signal this event
4837
4852
ZE_CALL (zeEventHostSignal, (ZeEvent));
4838
4853
@@ -4933,20 +4948,32 @@ pi_result piEnqueueMemUnmap(pi_queue Queue, pi_mem MemObj, void *MappedPtr,
4933
4948
// For integrated devices the buffer is allocated in host memory.
4934
4949
if (MemObj->OnHost ) {
4935
4950
// Wait on incoming events before doing the copy
4936
- if (Queue->isInOrderQueue () && Queue->LastCommandEvent != nullptr ) {
4937
- PI_CALL (piEventsWait (1 , &(Queue->LastCommandEvent )));
4938
-
4939
- // Lock automatically releases when this goes out of scope.
4940
- std::lock_guard<std::mutex> lock (Queue->PiQueueMutex );
4941
- Queue->LastCommandEvent = *Event;
4942
- }
4943
-
4944
4951
PI_CALL (piEventsWait (NumEventsInWaitList, EventWaitList));
4945
4952
4953
+ if (Queue->isInOrderQueue ()) {
4954
+ pi_event TmpLastCommandEvent = nullptr ;
4955
+ {
4956
+ // Lock automatically releases when this goes out of scope.
4957
+ std::lock_guard<std::mutex> lock (Queue->PiQueueMutex );
4958
+ if (Queue->LastCommandEvent != nullptr ) {
4959
+ TmpLastCommandEvent = Queue->LastCommandEvent ;
4960
+ }
4961
+ }
4962
+ if (TmpLastCommandEvent != nullptr ) {
4963
+ PI_CALL (piEventsWait (1 , &TmpLastCommandEvent));
4964
+ }
4965
+ }
4966
+
4946
4967
if (MemObj->MapHostPtr )
4947
4968
memcpy (pi_cast<char *>(MemObj->getZeHandle ()) + MapInfo.Offset , MappedPtr,
4948
4969
MapInfo.Size );
4949
4970
4971
+ {
4972
+ // Lock automatically releases when this goes out of scope.
4973
+ std::lock_guard<std::mutex> lock (Queue->PiQueueMutex );
4974
+ Queue->LastCommandEvent = *Event;
4975
+ }
4976
+
4950
4977
// Signal this event
4951
4978
ZE_CALL (zeEventHostSignal, (ZeEvent));
4952
4979
0 commit comments