Skip to content

Commit e9702e4

Browse files
author
Hugh Delaney
committed
Reassign hQueue if copying from a different device
We should use the queue associated with the most reecent copy of data if reading from buffer.
1 parent 49f71b7 commit e9702e4

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

source/adapters/hip/enqueue.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)