Skip to content

Commit

Permalink
use synchronous host wait for zeHandle copies
Browse files Browse the repository at this point in the history
This workarounds the problems with adding waitlist events
to the copy immediate command list.
  • Loading branch information
pbalcer committed Sep 30, 2024
1 parent 12e22c2 commit 3ab27af
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions source/adapters/level_zero/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2175,17 +2175,10 @@ ur_result_t _ur_buffer::getZeHandle(char *&ZeHandle, access_mode_t AccessMode,
}

if (NeedCopy) {

// Generate the waitlist for the Copy calls based on the passed in
// dependencies, if they exist.
_ur_ze_event_list_t waitlist;
waitlist.ZeEventList = nullptr;
waitlist.Length = numWaitEvents;
if (numWaitEvents != 0) {
waitlist.ZeEventList = new ze_event_handle_t[numWaitEvents];
for (uint32_t i = 0; i < numWaitEvents; i++) {
waitlist.ZeEventList[i] = phWaitEvents[i]->ZeEvent;
}
// Wait for all events synchronously to make sure that the copy
// operates on the correct data.
for (unsigned i = 0; i < numWaitEvents; ++i) {
ZE2UR_CALL(zeHostSynchronize, (phWaitEvents[i]->ZeEvent));
}

// Copy valid buffer data to this allocation.
Expand Down Expand Up @@ -2225,26 +2218,24 @@ ur_result_t _ur_buffer::getZeHandle(char *&ZeHandle, access_mode_t AccessMode,
if (!HostAllocation.Valid) {
ZE2UR_CALL(zeCommandListAppendMemoryCopy,
(UrContext->ZeCommandListInit, HostAllocation.ZeHandle,
ZeHandleSrc, Size, nullptr, waitlist.Length,
waitlist.ZeEventList));
ZeHandleSrc, Size, nullptr, 0,
nullptr));
// Mark the host allocation data as valid so it can be reused.
// It will be invalidated below if the current access is not
// read-only.
HostAllocation.Valid = true;
}
ZE2UR_CALL(zeCommandListAppendMemoryCopy,
(UrContext->ZeCommandListInit, ZeHandle,
HostAllocation.ZeHandle, Size, nullptr, waitlist.Length,
waitlist.ZeEventList));
HostAllocation.ZeHandle, Size, nullptr, 0,
nullptr));
} else {
// Perform P2P copy.
std::scoped_lock<ur_mutex> Lock(UrContext->ImmediateCommandListMutex);
ZE2UR_CALL(zeCommandListAppendMemoryCopy,
(UrContext->ZeCommandListInit, ZeHandle, ZeHandleSrc, Size,
nullptr, waitlist.Length, waitlist.ZeEventList));
nullptr, 0, nullptr));
}
if (waitlist.ZeEventList)
delete waitlist.ZeEventList;
}
Allocation.Valid = true;
LastDeviceWithValidAllocation = Device;
Expand Down

0 comments on commit 3ab27af

Please sign in to comment.