@@ -2175,18 +2175,32 @@ ur_result_t _ur_buffer::getZeHandle(char *&ZeHandle, access_mode_t AccessMode,
2175
2175
}
2176
2176
2177
2177
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.
2181
2180
_ur_ze_event_list_t waitlist;
2182
2181
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++;
2188
2197
}
2189
2198
}
2199
+ if (waitlist.Length > 0 ) {
2200
+ ZE2UR_CALL (zeCommandListAppendWaitOnEvents,
2201
+ (UrContext->ZeCommandListInit , waitlist.Length ,
2202
+ waitlist.ZeEventList ));
2203
+ }
2190
2204
2191
2205
// Copy valid buffer data to this allocation.
2192
2206
// 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,
2225
2239
if (!HostAllocation.Valid ) {
2226
2240
ZE2UR_CALL (zeCommandListAppendMemoryCopy,
2227
2241
(UrContext->ZeCommandListInit , HostAllocation.ZeHandle ,
2228
- ZeHandleSrc, Size, nullptr , waitlist.Length ,
2229
- waitlist.ZeEventList ));
2242
+ ZeHandleSrc, Size, nullptr , 0u , nullptr ));
2230
2243
// Mark the host allocation data as valid so it can be reused.
2231
2244
// It will be invalidated below if the current access is not
2232
2245
// read-only.
2233
2246
HostAllocation.Valid = true ;
2234
2247
}
2235
2248
ZE2UR_CALL (zeCommandListAppendMemoryCopy,
2236
2249
(UrContext->ZeCommandListInit , ZeHandle,
2237
- HostAllocation.ZeHandle , Size, nullptr , waitlist.Length ,
2238
- waitlist.ZeEventList ));
2250
+ HostAllocation.ZeHandle , Size, nullptr , 0u , nullptr ));
2239
2251
} else {
2240
2252
// Perform P2P copy.
2241
2253
std::scoped_lock<ur_mutex> Lock (UrContext->ImmediateCommandListMutex );
2242
2254
ZE2UR_CALL (zeCommandListAppendMemoryCopy,
2243
2255
(UrContext->ZeCommandListInit , ZeHandle, ZeHandleSrc, Size,
2244
- nullptr , waitlist. Length , waitlist. ZeEventList ));
2256
+ nullptr , 0u , nullptr ));
2245
2257
}
2246
- if (waitlist.ZeEventList )
2258
+ if (waitlist.ZeEventList ) {
2247
2259
delete waitlist.ZeEventList ;
2260
+ }
2248
2261
}
2249
2262
Allocation.Valid = true ;
2250
2263
LastDeviceWithValidAllocation = Device;
0 commit comments