@@ -220,7 +220,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferRead(
220220 if (hBuffer->LastEventWritingToMemObj &&
221221 hBuffer->LastEventWritingToMemObj ->getQueue ()->getDevice () !=
222222 hQueue->getDevice ()) {
223- Device = hBuffer->LastEventWritingToMemObj ->getQueue ()->getDevice ();
223+ // This event is never created with interop so getQueue is never null
224+ hQueue = hBuffer->LastEventWritingToMemObj ->getQueue ();
225+ Device = hQueue->getDevice ();
224226 ScopedContext Active (Device);
225227 HIPStream = hipStream_t{0 }; // Default stream for different device
226228 // We may have to wait for an event on another queue if it is the last
@@ -229,13 +231,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferRead(
229231 &hBuffer->LastEventWritingToMemObj ));
230232 }
231233
234+ ScopedContext Active (Device);
235+
232236 // Use the default stream if copying from another device
233237 UR_CHECK_ERROR (enqueueEventsWait (hQueue, HIPStream, numEventsInWaitList,
234238 phEventWaitList));
235239
236- // enqueueEventsWait may set a different context
237- ScopedContext Active (Device);
238-
239240 if (phEvent) {
240241 RetImplEvent =
241242 std::unique_ptr<ur_event_handle_t_>(ur_event_handle_t_::makeNative (
@@ -588,7 +589,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferReadRect(
588589 if (hBuffer->LastEventWritingToMemObj &&
589590 hBuffer->LastEventWritingToMemObj ->getQueue ()->getDevice () !=
590591 hQueue->getDevice ()) {
591- Device = hBuffer->LastEventWritingToMemObj ->getQueue ()->getDevice ();
592+ // This event is never created with interop so getQueue is never null
593+ hQueue = hBuffer->LastEventWritingToMemObj ->getQueue ();
594+ Device = hQueue->getDevice ();
592595 ScopedContext Active (Device);
593596 HIPStream = hipStream_t{0 }; // Default stream for different device
594597 // We may have to wait for an event on another queue if it is the last
@@ -597,12 +600,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferReadRect(
597600 &hBuffer->LastEventWritingToMemObj ));
598601 }
599602
603+ ScopedContext Active (Device);
604+
600605 UR_CHECK_ERROR (enqueueEventsWait (hQueue, HIPStream, numEventsInWaitList,
601606 phEventWaitList));
602607
603- // enqueueEventsWait may set a different context
604- ScopedContext Active (Device);
605-
606608 if (phEvent) {
607609 RetImplEvent =
608610 std::unique_ptr<ur_event_handle_t_>(ur_event_handle_t_::makeNative (
@@ -1023,7 +1025,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageRead(
10231025 if (hImage->LastEventWritingToMemObj &&
10241026 hImage->LastEventWritingToMemObj ->getQueue ()->getDevice () !=
10251027 hQueue->getDevice ()) {
1026- Device = hImage->LastEventWritingToMemObj ->getQueue ()->getDevice ();
1028+ hQueue = hImage->LastEventWritingToMemObj ->getQueue ();
1029+ Device = hQueue->getDevice ();
10271030 ScopedContext Active (Device);
10281031 HIPStream = hipStream_t{0 }; // Default stream for different device
10291032 // We may have to wait for an event on another queue if it is the last
0 commit comments