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