@@ -220,7 +220,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferRead(
220
220
if (hBuffer->LastEventWritingToMemObj &&
221
221
hBuffer->LastEventWritingToMemObj ->getQueue ()->getDevice () !=
222
222
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 ();
224
226
ScopedContext Active (Device);
225
227
HIPStream = hipStream_t{0 }; // Default stream for different device
226
228
// 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(
229
231
&hBuffer->LastEventWritingToMemObj ));
230
232
}
231
233
234
+ ScopedContext Active (Device);
235
+
232
236
// Use the default stream if copying from another device
233
237
UR_CHECK_ERROR (enqueueEventsWait (hQueue, HIPStream, numEventsInWaitList,
234
238
phEventWaitList));
235
239
236
- // enqueueEventsWait may set a different context
237
- ScopedContext Active (Device);
238
-
239
240
if (phEvent) {
240
241
RetImplEvent =
241
242
std::unique_ptr<ur_event_handle_t_>(ur_event_handle_t_::makeNative (
@@ -588,7 +589,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferReadRect(
588
589
if (hBuffer->LastEventWritingToMemObj &&
589
590
hBuffer->LastEventWritingToMemObj ->getQueue ()->getDevice () !=
590
591
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 ();
592
595
ScopedContext Active (Device);
593
596
HIPStream = hipStream_t{0 }; // Default stream for different device
594
597
// 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(
597
600
&hBuffer->LastEventWritingToMemObj ));
598
601
}
599
602
603
+ ScopedContext Active (Device);
604
+
600
605
UR_CHECK_ERROR (enqueueEventsWait (hQueue, HIPStream, numEventsInWaitList,
601
606
phEventWaitList));
602
607
603
- // enqueueEventsWait may set a different context
604
- ScopedContext Active (Device);
605
-
606
608
if (phEvent) {
607
609
RetImplEvent =
608
610
std::unique_ptr<ur_event_handle_t_>(ur_event_handle_t_::makeNative (
@@ -1023,7 +1025,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageRead(
1023
1025
if (hImage->LastEventWritingToMemObj &&
1024
1026
hImage->LastEventWritingToMemObj ->getQueue ()->getDevice () !=
1025
1027
hQueue->getDevice ()) {
1026
- Device = hImage->LastEventWritingToMemObj ->getQueue ()->getDevice ();
1028
+ hQueue = hImage->LastEventWritingToMemObj ->getQueue ();
1029
+ Device = hQueue->getDevice ();
1027
1030
ScopedContext Active (Device);
1028
1031
HIPStream = hipStream_t{0 }; // Default stream for different device
1029
1032
// We may have to wait for an event on another queue if it is the last
0 commit comments