@@ -986,6 +986,7 @@ pi_result _pi_ze_event_list_t::createAndRetainPiZeEventList(
986986
987987 for (pi_uint32 I = 0 ; I < this ->Length ; I++) {
988988 PI_CALL (piEventRetain (this ->PiEventList [I]));
989+
989990 }
990991
991992 return PI_SUCCESS;
@@ -4481,8 +4482,8 @@ static pi_result enqueueMemCopyHelper(pi_command_type CommandType,
44814482 (*Event)->WaitList = TmpWaitList;
44824483
44834484 const auto &WaitList = (*Event)->WaitList ;
4484-
44854485 if (WaitList.Length ) {
4486+
44864487 ZE_CALL (zeCommandListAppendWaitOnEvents,
44874488 (ZeCommandList, WaitList.Length , WaitList.ZeEventList ));
44884489 }
@@ -4815,15 +4816,23 @@ pi_result piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer,
48154816 // For integrated devices the buffer has been allocated in host memory.
48164817 if (Buffer->OnHost ) {
48174818 // 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));
48204820
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 ;
48254823
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+ }
48274836
48284837 if (Buffer->MapHostPtr ) {
48294838 *RetMap = Buffer->MapHostPtr + Offset;
@@ -4833,6 +4842,12 @@ pi_result piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer,
48334842 *RetMap = pi_cast<char *>(Buffer->getZeHandle ()) + Offset;
48344843 }
48354844
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+
48364851 // Signal this event
48374852 ZE_CALL (zeEventHostSignal, (ZeEvent));
48384853
@@ -4933,20 +4948,32 @@ pi_result piEnqueueMemUnmap(pi_queue Queue, pi_mem MemObj, void *MappedPtr,
49334948 // For integrated devices the buffer is allocated in host memory.
49344949 if (MemObj->OnHost ) {
49354950 // 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-
49444951 PI_CALL (piEventsWait (NumEventsInWaitList, EventWaitList));
49454952
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+
49464967 if (MemObj->MapHostPtr )
49474968 memcpy (pi_cast<char *>(MemObj->getZeHandle ()) + MapInfo.Offset , MappedPtr,
49484969 MapInfo.Size );
49494970
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+
49504977 // Signal this event
49514978 ZE_CALL (zeEventHostSignal, (ZeEvent));
49524979
0 commit comments