@@ -70,10 +70,11 @@ ur_exp_command_buffer_handle_t_::ur_exp_command_buffer_handle_t_(
70
70
isInOrder(desc ? desc->isInOrder : false ),
71
71
commandListManager(
72
72
context, device,
73
- std::forward<v2::raii::command_list_unique_handle>(commandList),
74
- isInOrder ? v2::EVENT_FLAGS_COUNTER : 0, nullptr,
75
- PoolCacheType::Regular),
76
- context(context), device(device) {}
73
+ std::forward<v2::raii::command_list_unique_handle>(commandList)),
74
+ context(context), device(device),
75
+ eventPool(context->getEventPoolCache (PoolCacheType::Regular)
76
+ .borrow(device->Id.value(),
77
+ isInOrder ? v2::EVENT_FLAGS_COUNTER : 0)) {}
77
78
78
79
ur_exp_command_buffer_sync_point_t
79
80
ur_exp_command_buffer_handle_t_::getSyncPoint (ur_event_handle_t event) {
@@ -155,7 +156,6 @@ ur_result_t ur_exp_command_buffer_handle_t_::registerExecutionEventUnlocked(
155
156
}
156
157
if (nextExecutionEvent) {
157
158
currentExecution = nextExecutionEvent;
158
- UR_CALL (nextExecutionEvent->retain ());
159
159
}
160
160
return UR_RESULT_SUCCESS;
161
161
}
@@ -202,6 +202,21 @@ ur_result_t ur_exp_command_buffer_handle_t_::applyUpdateCommands(
202
202
203
203
return UR_RESULT_SUCCESS;
204
204
}
205
+
206
+ ur_event_handle_t ur_exp_command_buffer_handle_t_::createEventIfRequested (
207
+ ur_exp_command_buffer_sync_point_t *retSyncPoint) {
208
+ if (retSyncPoint == nullptr ) {
209
+ return nullptr ;
210
+ }
211
+
212
+ auto event = eventPool->allocate ();
213
+ event->setQueue (nullptr );
214
+
215
+ *retSyncPoint = getSyncPoint (event);
216
+
217
+ return event;
218
+ }
219
+
205
220
namespace ur ::level_zero {
206
221
207
222
ur_result_t
@@ -292,18 +307,11 @@ ur_result_t urCommandBufferAppendKernelLaunchExp(
292
307
}
293
308
auto eventsWaitList = commandBuffer->getWaitListFromSyncPoints (
294
309
syncPointWaitList, numSyncPointsInWaitList);
295
- ur_event_handle_t *event = nullptr ;
296
- ur_event_handle_t signalEvent = nullptr ;
297
- if (retSyncPoint != nullptr ) {
298
- event = &signalEvent;
299
- }
300
- UR_CALL (commandListLocked->appendKernelLaunch (
301
- hKernel, workDim, pGlobalWorkOffset, pGlobalWorkSize, pLocalWorkSize,
302
- numSyncPointsInWaitList, eventsWaitList, event));
303
310
304
- if (retSyncPoint != nullptr ) {
305
- *retSyncPoint = commandBuffer->getSyncPoint (signalEvent);
306
- }
311
+ UR_CALL (commandListLocked->appendKernelLaunch (
312
+ hKernel, workDim, pGlobalWorkOffset, pGlobalWorkSize, pLocalWorkSize, 0 ,
313
+ nullptr , numSyncPointsInWaitList, eventsWaitList,
314
+ commandBuffer->createEventIfRequested (retSyncPoint)));
307
315
308
316
return UR_RESULT_SUCCESS;
309
317
} catch (...) {
@@ -324,17 +332,11 @@ ur_result_t urCommandBufferAppendUSMMemcpyExp(
324
332
auto commandListLocked = hCommandBuffer->commandListManager .lock ();
325
333
auto eventsWaitList = hCommandBuffer->getWaitListFromSyncPoints (
326
334
pSyncPointWaitList, numSyncPointsInWaitList);
327
- ur_event_handle_t *event = nullptr ;
328
- ur_event_handle_t signalEvent = nullptr ;
329
- if (pSyncPoint != nullptr ) {
330
- event = &signalEvent;
331
- }
335
+
332
336
UR_CALL (commandListLocked->appendUSMMemcpy (
333
- false , pDst, pSrc, size, numSyncPointsInWaitList, eventsWaitList, event));
337
+ false , pDst, pSrc, size, numSyncPointsInWaitList, eventsWaitList,
338
+ hCommandBuffer->createEventIfRequested (pSyncPoint)));
334
339
335
- if (pSyncPoint != nullptr ) {
336
- *pSyncPoint = hCommandBuffer->getSyncPoint (signalEvent);
337
- }
338
340
return UR_RESULT_SUCCESS;
339
341
} catch (...) {
340
342
return exceptionToResult (std::current_exception ());
@@ -357,18 +359,11 @@ ur_result_t urCommandBufferAppendMemBufferCopyExp(
357
359
auto commandListLocked = hCommandBuffer->commandListManager .lock ();
358
360
auto eventsWaitList = hCommandBuffer->getWaitListFromSyncPoints (
359
361
pSyncPointWaitList, numSyncPointsInWaitList);
360
- ur_event_handle_t *event = nullptr ;
361
- ur_event_handle_t signalEvent = nullptr ;
362
- if (pSyncPoint != nullptr ) {
363
- event = &signalEvent;
364
- }
362
+
365
363
UR_CALL (commandListLocked->appendMemBufferCopy (
366
364
hSrcMem, hDstMem, srcOffset, dstOffset, size, numSyncPointsInWaitList,
367
- eventsWaitList, event ));
365
+ eventsWaitList, hCommandBuffer-> createEventIfRequested (pSyncPoint) ));
368
366
369
- if (pSyncPoint != nullptr ) {
370
- *pSyncPoint = hCommandBuffer->getSyncPoint (signalEvent);
371
- }
372
367
return UR_RESULT_SUCCESS;
373
368
} catch (...) {
374
369
return exceptionToResult (std::current_exception ());
@@ -391,18 +386,11 @@ ur_result_t urCommandBufferAppendMemBufferWriteExp(
391
386
auto commandListLocked = hCommandBuffer->commandListManager .lock ();
392
387
auto eventsWaitList = hCommandBuffer->getWaitListFromSyncPoints (
393
388
pSyncPointWaitList, numSyncPointsInWaitList);
394
- ur_event_handle_t *event = nullptr ;
395
- ur_event_handle_t signalEvent = nullptr ;
396
- if (pSyncPoint != nullptr ) {
397
- event = &signalEvent;
398
- }
399
- UR_CALL (commandListLocked->appendMemBufferWrite (hBuffer, false , offset, size,
400
- pSrc, numSyncPointsInWaitList,
401
- eventsWaitList, event));
402
389
403
- if (pSyncPoint != nullptr ) {
404
- *pSyncPoint = hCommandBuffer->getSyncPoint (signalEvent);
405
- }
390
+ UR_CALL (commandListLocked->appendMemBufferWrite (
391
+ hBuffer, false , offset, size, pSrc, numSyncPointsInWaitList,
392
+ eventsWaitList, hCommandBuffer->createEventIfRequested (pSyncPoint)));
393
+
406
394
return UR_RESULT_SUCCESS;
407
395
} catch (...) {
408
396
return exceptionToResult (std::current_exception ());
@@ -423,18 +411,11 @@ ur_result_t urCommandBufferAppendMemBufferReadExp(
423
411
auto commandListLocked = hCommandBuffer->commandListManager .lock ();
424
412
auto eventsWaitList = hCommandBuffer->getWaitListFromSyncPoints (
425
413
pSyncPointWaitList, numSyncPointsInWaitList);
426
- ur_event_handle_t *event = nullptr ;
427
- ur_event_handle_t signalEvent = nullptr ;
428
- if (pSyncPoint != nullptr ) {
429
- event = &signalEvent;
430
- }
431
- UR_CALL (commandListLocked->appendMemBufferRead (hBuffer, false , offset, size,
432
- pDst, numSyncPointsInWaitList,
433
- eventsWaitList, event));
434
414
435
- if (pSyncPoint != nullptr ) {
436
- *pSyncPoint = hCommandBuffer->getSyncPoint (signalEvent);
437
- }
415
+ UR_CALL (commandListLocked->appendMemBufferRead (
416
+ hBuffer, false , offset, size, pDst, numSyncPointsInWaitList,
417
+ eventsWaitList, hCommandBuffer->createEventIfRequested (pSyncPoint)));
418
+
438
419
return UR_RESULT_SUCCESS;
439
420
} catch (...) {
440
421
return exceptionToResult (std::current_exception ());
@@ -459,19 +440,12 @@ ur_result_t urCommandBufferAppendMemBufferCopyRectExp(
459
440
auto commandListLocked = hCommandBuffer->commandListManager .lock ();
460
441
auto eventsWaitList = hCommandBuffer->getWaitListFromSyncPoints (
461
442
pSyncPointWaitList, numSyncPointsInWaitList);
462
- ur_event_handle_t *event = nullptr ;
463
- ur_event_handle_t signalEvent = nullptr ;
464
- if (pSyncPoint != nullptr ) {
465
- event = &signalEvent;
466
- }
443
+
467
444
UR_CALL (commandListLocked->appendMemBufferCopyRect (
468
445
hSrcMem, hDstMem, srcOrigin, dstOrigin, region, srcRowPitch,
469
446
srcSlicePitch, dstRowPitch, dstSlicePitch, numSyncPointsInWaitList,
470
- eventsWaitList, event ));
447
+ eventsWaitList, hCommandBuffer-> createEventIfRequested (pSyncPoint) ));
471
448
472
- if (pSyncPoint != nullptr ) {
473
- *pSyncPoint = hCommandBuffer->getSyncPoint (signalEvent);
474
- }
475
449
return UR_RESULT_SUCCESS;
476
450
} catch (...) {
477
451
return exceptionToResult (std::current_exception ());
@@ -496,19 +470,13 @@ ur_result_t urCommandBufferAppendMemBufferWriteRectExp(
496
470
auto commandListLocked = hCommandBuffer->commandListManager .lock ();
497
471
auto eventsWaitList = hCommandBuffer->getWaitListFromSyncPoints (
498
472
pSyncPointWaitList, numSyncPointsInWaitList);
499
- ur_event_handle_t *event = nullptr ;
500
- ur_event_handle_t signalEvent = nullptr ;
501
- if (pSyncPoint != nullptr ) {
502
- event = &signalEvent;
503
- }
473
+
504
474
UR_CALL (commandListLocked->appendMemBufferWriteRect (
505
475
hBuffer, false , bufferOffset, hostOffset, region, bufferRowPitch,
506
476
bufferSlicePitch, hostRowPitch, hostSlicePitch, pSrc,
507
- numSyncPointsInWaitList, eventsWaitList, event));
477
+ numSyncPointsInWaitList, eventsWaitList,
478
+ hCommandBuffer->createEventIfRequested (pSyncPoint)));
508
479
509
- if (pSyncPoint != nullptr ) {
510
- *pSyncPoint = hCommandBuffer->getSyncPoint (signalEvent);
511
- }
512
480
return UR_RESULT_SUCCESS;
513
481
} catch (...) {
514
482
return exceptionToResult (std::current_exception ());
@@ -533,19 +501,13 @@ ur_result_t urCommandBufferAppendMemBufferReadRectExp(
533
501
auto commandListLocked = hCommandBuffer->commandListManager .lock ();
534
502
auto eventsWaitList = hCommandBuffer->getWaitListFromSyncPoints (
535
503
pSyncPointWaitList, numSyncPointsInWaitList);
536
- ur_event_handle_t *event = nullptr ;
537
- ur_event_handle_t signalEvent = nullptr ;
538
- if (pSyncPoint != nullptr ) {
539
- event = &signalEvent;
540
- }
504
+
541
505
UR_CALL (commandListLocked->appendMemBufferReadRect (
542
506
hBuffer, false , bufferOffset, hostOffset, region, bufferRowPitch,
543
507
bufferSlicePitch, hostRowPitch, hostSlicePitch, pDst,
544
- numSyncPointsInWaitList, eventsWaitList, event));
508
+ numSyncPointsInWaitList, eventsWaitList,
509
+ hCommandBuffer->createEventIfRequested (pSyncPoint)));
545
510
546
- if (pSyncPoint != nullptr ) {
547
- *pSyncPoint = hCommandBuffer->getSyncPoint (signalEvent);
548
- }
549
511
return UR_RESULT_SUCCESS;
550
512
} catch (...) {
551
513
return exceptionToResult (std::current_exception ());
@@ -565,17 +527,10 @@ ur_result_t urCommandBufferAppendUSMFillExp(
565
527
auto commandListLocked = hCommandBuffer->commandListManager .lock ();
566
528
auto eventsWaitList = hCommandBuffer->getWaitListFromSyncPoints (
567
529
pSyncPointWaitList, numSyncPointsInWaitList);
568
- ur_event_handle_t *event = nullptr ;
569
- ur_event_handle_t signalEvent = nullptr ;
570
- if (pSyncPoint != nullptr ) {
571
- event = &signalEvent;
572
- }
573
- UR_CALL (commandListLocked->appendUSMFill (pMemory, patternSize, pPattern, size,
574
- numSyncPointsInWaitList,
575
- eventsWaitList, event));
576
- if (pSyncPoint != nullptr ) {
577
- *pSyncPoint = hCommandBuffer->getSyncPoint (signalEvent);
578
- }
530
+
531
+ UR_CALL (commandListLocked->appendUSMFill (
532
+ pMemory, patternSize, pPattern, size, numSyncPointsInWaitList,
533
+ eventsWaitList, hCommandBuffer->createEventIfRequested (pSyncPoint)));
579
534
return UR_RESULT_SUCCESS;
580
535
} catch (...) {
581
536
return exceptionToResult (std::current_exception ());
@@ -596,17 +551,11 @@ ur_result_t urCommandBufferAppendMemBufferFillExp(
596
551
auto commandListLocked = hCommandBuffer->commandListManager .lock ();
597
552
auto eventsWaitList = hCommandBuffer->getWaitListFromSyncPoints (
598
553
pSyncPointWaitList, numSyncPointsInWaitList);
599
- ur_event_handle_t *event = nullptr ;
600
- ur_event_handle_t signalEvent = nullptr ;
601
- if (pSyncPoint != nullptr ) {
602
- event = &signalEvent;
603
- }
554
+
604
555
UR_CALL (commandListLocked->appendMemBufferFill (
605
556
hBuffer, pPattern, patternSize, offset, size, numSyncPointsInWaitList,
606
- eventsWaitList, event));
607
- if (pSyncPoint != nullptr ) {
608
- *pSyncPoint = hCommandBuffer->getSyncPoint (signalEvent);
609
- }
557
+ eventsWaitList, hCommandBuffer->createEventIfRequested (pSyncPoint)));
558
+
610
559
return UR_RESULT_SUCCESS;
611
560
} catch (...) {
612
561
return exceptionToResult (std::current_exception ());
@@ -628,17 +577,11 @@ ur_result_t urCommandBufferAppendUSMPrefetchExp(
628
577
auto commandListLocked = hCommandBuffer->commandListManager .lock ();
629
578
auto eventsWaitList = hCommandBuffer->getWaitListFromSyncPoints (
630
579
pSyncPointWaitList, numSyncPointsInWaitList);
631
- ur_event_handle_t *event = nullptr ;
632
- ur_event_handle_t signalEvent = nullptr ;
633
- if (pSyncPoint != nullptr ) {
634
- event = &signalEvent;
635
- }
580
+
636
581
UR_CALL (commandListLocked->appendUSMPrefetch (
637
- pMemory, size, flags, numSyncPointsInWaitList, eventsWaitList, event));
582
+ pMemory, size, flags, numSyncPointsInWaitList, eventsWaitList,
583
+ hCommandBuffer->createEventIfRequested (pSyncPoint)));
638
584
639
- if (pSyncPoint != nullptr ) {
640
- *pSyncPoint = hCommandBuffer->getSyncPoint (signalEvent);
641
- }
642
585
return UR_RESULT_SUCCESS;
643
586
} catch (...) {
644
587
return exceptionToResult (std::current_exception ());
@@ -658,17 +601,11 @@ ur_result_t urCommandBufferAppendUSMAdviseExp(
658
601
auto commandListLocked = hCommandBuffer->commandListManager .lock ();
659
602
auto eventsWaitList = hCommandBuffer->getWaitListFromSyncPoints (
660
603
pSyncPointWaitList, numSyncPointsInWaitList);
661
- ur_event_handle_t *event = nullptr ;
662
- ur_event_handle_t signalEvent = nullptr ;
663
- if (pSyncPoint != nullptr ) {
664
- event = &signalEvent;
665
- }
604
+
666
605
UR_CALL (commandListLocked->appendUSMAdvise (
667
- pMemory, size, advice, numSyncPointsInWaitList, eventsWaitList, event));
606
+ pMemory, size, advice, numSyncPointsInWaitList, eventsWaitList,
607
+ hCommandBuffer->createEventIfRequested (pSyncPoint)));
668
608
669
- if (pSyncPoint != nullptr ) {
670
- *pSyncPoint = hCommandBuffer->getSyncPoint (signalEvent);
671
- }
672
609
return UR_RESULT_SUCCESS;
673
610
} catch (...) {
674
611
return exceptionToResult (std::current_exception ());
@@ -714,23 +651,17 @@ ur_result_t urCommandBufferAppendNativeCommandExp(
714
651
auto commandListLocked = hCommandBuffer->commandListManager .lock ();
715
652
auto eventsWaitList = hCommandBuffer->getWaitListFromSyncPoints (
716
653
pSyncPointWaitList, numSyncPointsInWaitList);
717
- ur_event_handle_t *event = nullptr ;
718
- ur_event_handle_t signalEvent = nullptr ;
719
- if (pSyncPoint != nullptr ) {
720
- event = &signalEvent;
721
- }
722
- UR_CALL (commandListLocked->appendBarrier (numSyncPointsInWaitList,
723
- eventsWaitList, nullptr ));
654
+
655
+ UR_CALL (commandListLocked->appendEventsWaitWithBarrier (
656
+ numSyncPointsInWaitList, eventsWaitList, nullptr ));
724
657
725
658
// Call user-defined function immediately
726
659
pfnNativeCommand (pData);
727
660
728
661
// Barrier on all commands after user defined commands.
729
- UR_CALL (commandListLocked->appendBarrier (0 , nullptr , event));
662
+ UR_CALL (commandListLocked->appendEventsWaitWithBarrier (
663
+ 0 , nullptr , hCommandBuffer->createEventIfRequested (pSyncPoint)));
730
664
731
- if (pSyncPoint != nullptr ) {
732
- *pSyncPoint = hCommandBuffer->getSyncPoint (signalEvent);
733
- }
734
665
return UR_RESULT_SUCCESS;
735
666
}
736
667
0 commit comments