@@ -41,9 +41,10 @@ ur_exp_command_buffer_handle_t_::ur_exp_command_buffer_handle_t_(
41
41
ur_result_t ur_exp_command_buffer_handle_t_::finalizeCommandBuffer () {
42
42
// It is not allowed to append to command list from multiple threads.
43
43
std::scoped_lock<ur_shared_mutex> guard (this ->Mutex );
44
+ auto commandListLocked = commandListManager.lock ();
44
45
UR_ASSERT (!isFinalized, UR_RESULT_ERROR_INVALID_OPERATION);
45
46
// Close the command lists and have them ready for dispatch.
46
- ZE2UR_CALL (zeCommandListClose, (this -> commandListManager . getZeCommandList ()));
47
+ ZE2UR_CALL (zeCommandListClose, (commandListLocked-> getZeCommandList ()));
47
48
isFinalized = true ;
48
49
return UR_RESULT_SUCCESS;
49
50
}
@@ -130,7 +131,8 @@ ur_result_t urCommandBufferAppendKernelLaunchExp(
130
131
std::ignore = numKernelAlternatives;
131
132
std::ignore = kernelAlternatives;
132
133
std::ignore = command;
133
- UR_CALL (commandBuffer->commandListManager .appendKernelLaunch (
134
+ auto commandListLocked = commandBuffer->commandListManager .lock ();
135
+ UR_CALL (commandListLocked->appendKernelLaunch (
134
136
hKernel, workDim, pGlobalWorkOffset, pGlobalWorkSize, pLocalWorkSize, 0 ,
135
137
nullptr , nullptr ));
136
138
return UR_RESULT_SUCCESS;
@@ -157,8 +159,9 @@ ur_result_t urCommandBufferAppendUSMMemcpyExp(
157
159
158
160
std::ignore = phCommand;
159
161
// Responsibility of UMD to offload to copy engine
160
- UR_CALL (hCommandBuffer->commandListManager .appendUSMMemcpy (
161
- false , pDst, pSrc, size, 0 , nullptr , nullptr ));
162
+ auto commandListLocked = hCommandBuffer->commandListManager .lock ();
163
+ UR_CALL (commandListLocked->appendUSMMemcpy (false , pDst, pSrc, size, 0 ,
164
+ nullptr , nullptr ));
162
165
163
166
return UR_RESULT_SUCCESS;
164
167
} catch (...) {
@@ -185,7 +188,8 @@ ur_result_t urCommandBufferAppendMemBufferCopyExp(
185
188
186
189
std::ignore = phCommand;
187
190
// Responsibility of UMD to offload to copy engine
188
- UR_CALL (hCommandBuffer->commandListManager .appendMemBufferCopy (
191
+ auto commandListLocked = hCommandBuffer->commandListManager .lock ();
192
+ UR_CALL (commandListLocked->appendMemBufferCopy (
189
193
hSrcMem, hDstMem, srcOffset, dstOffset, size, 0 , nullptr , nullptr ));
190
194
191
195
return UR_RESULT_SUCCESS;
@@ -213,8 +217,9 @@ ur_result_t urCommandBufferAppendMemBufferWriteExp(
213
217
214
218
std::ignore = phCommand;
215
219
// Responsibility of UMD to offload to copy engine
216
- UR_CALL (hCommandBuffer->commandListManager .appendMemBufferWrite (
217
- hBuffer, false , offset, size, pSrc, 0 , nullptr , nullptr ));
220
+ auto commandListLocked = hCommandBuffer->commandListManager .lock ();
221
+ UR_CALL (commandListLocked->appendMemBufferWrite (hBuffer, false , offset, size,
222
+ pSrc, 0 , nullptr , nullptr ));
218
223
219
224
return UR_RESULT_SUCCESS;
220
225
} catch (...) {
@@ -241,8 +246,9 @@ ur_result_t urCommandBufferAppendMemBufferReadExp(
241
246
std::ignore = phCommand;
242
247
243
248
// Responsibility of UMD to offload to copy engine
244
- UR_CALL (hCommandBuffer->commandListManager .appendMemBufferRead (
245
- hBuffer, false , offset, size, pDst, 0 , nullptr , nullptr ));
249
+ auto commandListLocked = hCommandBuffer->commandListManager .lock ();
250
+ UR_CALL (commandListLocked->appendMemBufferRead (hBuffer, false , offset, size,
251
+ pDst, 0 , nullptr , nullptr ));
246
252
247
253
return UR_RESULT_SUCCESS;
248
254
} catch (...) {
@@ -271,7 +277,8 @@ ur_result_t urCommandBufferAppendMemBufferCopyRectExp(
271
277
272
278
std::ignore = phCommand;
273
279
// Responsibility of UMD to offload to copy engine
274
- UR_CALL (hCommandBuffer->commandListManager .appendMemBufferCopyRect (
280
+ auto commandListLocked = hCommandBuffer->commandListManager .lock ();
281
+ UR_CALL (commandListLocked->appendMemBufferCopyRect (
275
282
hSrcMem, hDstMem, srcOrigin, dstOrigin, region, srcRowPitch,
276
283
srcSlicePitch, dstRowPitch, dstSlicePitch, 0 , nullptr , nullptr ));
277
284
@@ -303,7 +310,8 @@ ur_result_t urCommandBufferAppendMemBufferWriteRectExp(
303
310
std::ignore = phCommand;
304
311
305
312
// Responsibility of UMD to offload to copy engine
306
- UR_CALL (hCommandBuffer->commandListManager .appendMemBufferWriteRect (
313
+ auto commandListLocked = hCommandBuffer->commandListManager .lock ();
314
+ UR_CALL (commandListLocked->appendMemBufferWriteRect (
307
315
hBuffer, false , bufferOffset, hostOffset, region, bufferRowPitch,
308
316
bufferSlicePitch, hostRowPitch, hostSlicePitch, pSrc, 0 , nullptr ,
309
317
nullptr ));
@@ -336,7 +344,8 @@ ur_result_t urCommandBufferAppendMemBufferReadRectExp(
336
344
std::ignore = phCommand;
337
345
338
346
// Responsibility of UMD to offload to copy engine
339
- UR_CALL (hCommandBuffer->commandListManager .appendMemBufferReadRect (
347
+ auto commandListLocked = hCommandBuffer->commandListManager .lock ();
348
+ UR_CALL (commandListLocked->appendMemBufferReadRect (
340
349
hBuffer, false , bufferOffset, hostOffset, region, bufferRowPitch,
341
350
bufferSlicePitch, hostRowPitch, hostSlicePitch, pDst, 0 , nullptr ,
342
351
nullptr ));
@@ -366,8 +375,9 @@ ur_result_t urCommandBufferAppendUSMFillExp(
366
375
367
376
std::ignore = phCommand;
368
377
369
- UR_CALL (hCommandBuffer->commandListManager .appendUSMFill (
370
- pMemory, patternSize, pPattern, size, 0 , nullptr , nullptr ));
378
+ auto commandListLocked = hCommandBuffer->commandListManager .lock ();
379
+ UR_CALL (commandListLocked->appendUSMFill (pMemory, patternSize, pPattern, size,
380
+ 0 , nullptr , nullptr ));
371
381
return UR_RESULT_SUCCESS;
372
382
} catch (...) {
373
383
return exceptionToResult (std::current_exception ());
@@ -393,7 +403,8 @@ ur_result_t urCommandBufferAppendMemBufferFillExp(
393
403
394
404
std::ignore = phCommand;
395
405
396
- UR_CALL (hCommandBuffer->commandListManager .appendMemBufferFill (
406
+ auto commandListLocked = hCommandBuffer->commandListManager .lock ();
407
+ UR_CALL (commandListLocked->appendMemBufferFill (
397
408
hBuffer, pPattern, patternSize, offset, size, 0 , nullptr , nullptr ));
398
409
return UR_RESULT_SUCCESS;
399
410
} catch (...) {
@@ -420,8 +431,9 @@ ur_result_t urCommandBufferAppendUSMPrefetchExp(
420
431
421
432
std::ignore = phCommand;
422
433
423
- UR_CALL (hCommandBuffer->commandListManager .appendUSMPrefetch (
424
- pMemory, size, flags, 0 , nullptr , nullptr ));
434
+ auto commandListLocked = hCommandBuffer->commandListManager .lock ();
435
+ UR_CALL (commandListLocked->appendUSMPrefetch (pMemory, size, flags, 0 , nullptr ,
436
+ nullptr ));
425
437
426
438
return UR_RESULT_SUCCESS;
427
439
} catch (...) {
@@ -447,8 +459,8 @@ ur_result_t urCommandBufferAppendUSMAdviseExp(
447
459
448
460
std::ignore = phCommand;
449
461
450
- UR_CALL ( hCommandBuffer->commandListManager .appendUSMAdvise (pMemory, size,
451
- advice, nullptr ));
462
+ auto commandListLocked = hCommandBuffer->commandListManager .lock ();
463
+ UR_CALL (commandListLocked-> appendUSMAdvise (pMemory, size, advice, nullptr ));
452
464
453
465
return UR_RESULT_SUCCESS;
454
466
} catch (...) {
@@ -483,4 +495,16 @@ urCommandBufferGetInfoExp(ur_exp_command_buffer_handle_t hCommandBuffer,
483
495
return exceptionToResult (std::current_exception ());
484
496
}
485
497
498
+ ur_result_t urCommandBufferEnqueueExp (
499
+ ur_exp_command_buffer_handle_t CommandBuffer, ur_queue_handle_t UrQueue,
500
+ uint32_t NumEventsInWaitList, const ur_event_handle_t *EventWaitList,
501
+ ur_event_handle_t *Event) try {
502
+ auto commandListLocked = CommandBuffer->commandListManager .lock ();
503
+ return UrQueue->get ().enqueueCommandBuffer (
504
+ commandListLocked->getZeCommandList (), Event, NumEventsInWaitList,
505
+ EventWaitList);
506
+ } catch (...) {
507
+ return exceptionToResult (std::current_exception ());
508
+ }
509
+
486
510
} // namespace ur::level_zero
0 commit comments