@@ -40,10 +40,10 @@ ur_exp_command_buffer_handle_t_::ur_exp_command_buffer_handle_t_(
4040
4141ur_result_t ur_exp_command_buffer_handle_t_::finalizeCommandBuffer () {
4242 // 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 ( );
4444 UR_ASSERT (!isFinalized, UR_RESULT_ERROR_INVALID_OPERATION);
4545 // Close the command lists and have them ready for dispatch.
46- ZE2UR_CALL (zeCommandListClose, (this -> commandListManager . getZeCommandList ()));
46+ ZE2UR_CALL (zeCommandListClose, (commandListLocked-> getZeCommandList ()));
4747 isFinalized = true ;
4848 return UR_RESULT_SUCCESS;
4949}
@@ -130,7 +130,8 @@ ur_result_t urCommandBufferAppendKernelLaunchExp(
130130 std::ignore = numKernelAlternatives;
131131 std::ignore = kernelAlternatives;
132132 std::ignore = command;
133- UR_CALL (commandBuffer->commandListManager .appendKernelLaunch (
133+ auto commandListLocked = commandBuffer->commandListManager .lock ();
134+ UR_CALL (commandListLocked->appendKernelLaunch (
134135 hKernel, workDim, pGlobalWorkOffset, pGlobalWorkSize, pLocalWorkSize, 0 ,
135136 nullptr , nullptr ));
136137 return UR_RESULT_SUCCESS;
@@ -157,8 +158,9 @@ ur_result_t urCommandBufferAppendUSMMemcpyExp(
157158
158159 std::ignore = phCommand;
159160 // 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 ));
162164
163165 return UR_RESULT_SUCCESS;
164166} catch (...) {
@@ -185,7 +187,8 @@ ur_result_t urCommandBufferAppendMemBufferCopyExp(
185187
186188 std::ignore = phCommand;
187189 // 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 (
189192 hSrcMem, hDstMem, srcOffset, dstOffset, size, 0 , nullptr , nullptr ));
190193
191194 return UR_RESULT_SUCCESS;
@@ -213,8 +216,9 @@ ur_result_t urCommandBufferAppendMemBufferWriteExp(
213216
214217 std::ignore = phCommand;
215218 // 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 ));
218222
219223 return UR_RESULT_SUCCESS;
220224} catch (...) {
@@ -241,8 +245,9 @@ ur_result_t urCommandBufferAppendMemBufferReadExp(
241245 std::ignore = phCommand;
242246
243247 // 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 ));
246251
247252 return UR_RESULT_SUCCESS;
248253} catch (...) {
@@ -271,7 +276,8 @@ ur_result_t urCommandBufferAppendMemBufferCopyRectExp(
271276
272277 std::ignore = phCommand;
273278 // 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 (
275281 hSrcMem, hDstMem, srcOrigin, dstOrigin, region, srcRowPitch,
276282 srcSlicePitch, dstRowPitch, dstSlicePitch, 0 , nullptr , nullptr ));
277283
@@ -303,7 +309,8 @@ ur_result_t urCommandBufferAppendMemBufferWriteRectExp(
303309 std::ignore = phCommand;
304310
305311 // 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 (
307314 hBuffer, false , bufferOffset, hostOffset, region, bufferRowPitch,
308315 bufferSlicePitch, hostRowPitch, hostSlicePitch, pSrc, 0 , nullptr ,
309316 nullptr ));
@@ -336,7 +343,8 @@ ur_result_t urCommandBufferAppendMemBufferReadRectExp(
336343 std::ignore = phCommand;
337344
338345 // 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 (
340348 hBuffer, false , bufferOffset, hostOffset, region, bufferRowPitch,
341349 bufferSlicePitch, hostRowPitch, hostSlicePitch, pDst, 0 , nullptr ,
342350 nullptr ));
@@ -366,8 +374,9 @@ ur_result_t urCommandBufferAppendUSMFillExp(
366374
367375 std::ignore = phCommand;
368376
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 ));
371380 return UR_RESULT_SUCCESS;
372381} catch (...) {
373382 return exceptionToResult (std::current_exception ());
@@ -393,7 +402,8 @@ ur_result_t urCommandBufferAppendMemBufferFillExp(
393402
394403 std::ignore = phCommand;
395404
396- UR_CALL (hCommandBuffer->commandListManager .appendMemBufferFill (
405+ auto commandListLocked = hCommandBuffer->commandListManager .lock ();
406+ UR_CALL (commandListLocked->appendMemBufferFill (
397407 hBuffer, pPattern, patternSize, offset, size, 0 , nullptr , nullptr ));
398408 return UR_RESULT_SUCCESS;
399409} catch (...) {
@@ -420,8 +430,9 @@ ur_result_t urCommandBufferAppendUSMPrefetchExp(
420430
421431 std::ignore = phCommand;
422432
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 ));
425436
426437 return UR_RESULT_SUCCESS;
427438} catch (...) {
@@ -447,8 +458,8 @@ ur_result_t urCommandBufferAppendUSMAdviseExp(
447458
448459 std::ignore = phCommand;
449460
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 ));
452463
453464 return UR_RESULT_SUCCESS;
454465} catch (...) {
@@ -483,4 +494,14 @@ urCommandBufferGetInfoExp(ur_exp_command_buffer_handle_t hCommandBuffer,
483494 return exceptionToResult (std::current_exception ());
484495}
485496
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+
486507} // namespace ur::level_zero
0 commit comments