Skip to content

Commit 7583fd2

Browse files
committed
[L0] Wait on host visible events on the host and wait in a single call all device only events
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
1 parent daf52a4 commit 7583fd2

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

source/adapters/level_zero/memory.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,18 +2175,32 @@ ur_result_t _ur_buffer::getZeHandle(char *&ZeHandle, access_mode_t AccessMode,
21752175
}
21762176

21772177
if (NeedCopy) {
2178-
2179-
// Generate the waitlist for the Copy calls based on the passed in
2180-
// dependencies, if they exist.
2178+
// Wait on all dependency events passed in to ensure that the memory which
2179+
// is being init is updated correctly.
21812180
_ur_ze_event_list_t waitlist;
21822181
waitlist.ZeEventList = nullptr;
2183-
waitlist.Length = numWaitEvents;
2184-
if (numWaitEvents != 0) {
2185-
waitlist.ZeEventList = new ze_event_handle_t[numWaitEvents];
2186-
for (uint32_t i = 0; i < numWaitEvents; i++) {
2187-
waitlist.ZeEventList[i] = phWaitEvents[i]->ZeEvent;
2182+
waitlist.Length = 0;
2183+
uint32_t EventListIndex = 0;
2184+
for (unsigned i = 0; i < numWaitEvents; ++i) {
2185+
if (phWaitEvents[i]->HostVisibleEvent) {
2186+
ZE2UR_CALL(zeEventHostSynchronize,
2187+
(phWaitEvents[i]->ZeEvent, UINT64_MAX));
2188+
} else {
2189+
// Generate the waitlist for the Copy calls based on the passed in
2190+
// dependencies, if they exist for device only.
2191+
if (waitlist.ZeEventList == nullptr) {
2192+
waitlist.ZeEventList = new ze_event_handle_t[numWaitEvents];
2193+
}
2194+
waitlist.ZeEventList[EventListIndex] = phWaitEvents[i]->ZeEvent;
2195+
waitlist.Length++;
2196+
EventListIndex++;
21882197
}
21892198
}
2199+
if (waitlist.Length > 0) {
2200+
ZE2UR_CALL(zeCommandListAppendWaitOnEvents,
2201+
(UrContext->ZeCommandListInit, waitlist.Length,
2202+
waitlist.ZeEventList));
2203+
}
21902204

21912205
// Copy valid buffer data to this allocation.
21922206
// TODO: see if we should better use peer's device allocation used
@@ -2225,26 +2239,25 @@ ur_result_t _ur_buffer::getZeHandle(char *&ZeHandle, access_mode_t AccessMode,
22252239
if (!HostAllocation.Valid) {
22262240
ZE2UR_CALL(zeCommandListAppendMemoryCopy,
22272241
(UrContext->ZeCommandListInit, HostAllocation.ZeHandle,
2228-
ZeHandleSrc, Size, nullptr, waitlist.Length,
2229-
waitlist.ZeEventList));
2242+
ZeHandleSrc, Size, nullptr, 0u, nullptr));
22302243
// Mark the host allocation data as valid so it can be reused.
22312244
// It will be invalidated below if the current access is not
22322245
// read-only.
22332246
HostAllocation.Valid = true;
22342247
}
22352248
ZE2UR_CALL(zeCommandListAppendMemoryCopy,
22362249
(UrContext->ZeCommandListInit, ZeHandle,
2237-
HostAllocation.ZeHandle, Size, nullptr, waitlist.Length,
2238-
waitlist.ZeEventList));
2250+
HostAllocation.ZeHandle, Size, nullptr, 0u, nullptr));
22392251
} else {
22402252
// Perform P2P copy.
22412253
std::scoped_lock<ur_mutex> Lock(UrContext->ImmediateCommandListMutex);
22422254
ZE2UR_CALL(zeCommandListAppendMemoryCopy,
22432255
(UrContext->ZeCommandListInit, ZeHandle, ZeHandleSrc, Size,
2244-
nullptr, waitlist.Length, waitlist.ZeEventList));
2256+
nullptr, 0u, nullptr));
22452257
}
2246-
if (waitlist.ZeEventList)
2258+
if (waitlist.ZeEventList) {
22472259
delete waitlist.ZeEventList;
2260+
}
22482261
}
22492262
Allocation.Valid = true;
22502263
LastDeviceWithValidAllocation = Device;

0 commit comments

Comments
 (0)