@@ -364,22 +364,26 @@ pi_result _pi_queue::resetDiscardedEvent(pi_command_list_ptr_t CommandList) {
364
364
// \param CommandList is the command list where the event is added
365
365
// \param IsInternal tells if the event is internal, i.e. visible in the L0
366
366
// plugin only.
367
- // \param ForceHostVisible tells if the event must be created in
368
- // the host-visible pool
369
- inline static pi_result createEventAndAssociateQueue (
370
- pi_queue Queue, pi_event *Event, pi_command_type CommandType,
371
- pi_command_list_ptr_t CommandList, bool IsInternal = false ,
372
- bool ForceHostVisible = false ) {
367
+ // \param HostVisible tells if the event must be created in the
368
+ // host-visible pool. If not set then this function will decide.
369
+ inline static pi_result
370
+ createEventAndAssociateQueue (pi_queue Queue, pi_event *Event,
371
+ pi_command_type CommandType,
372
+ pi_command_list_ptr_t CommandList, bool IsInternal,
373
+ std::optional<bool > HostVisible = std::nullopt) {
373
374
374
- if (!ForceHostVisible)
375
- ForceHostVisible = Queue->Device ->ZeEventsScope == AllHostVisible;
375
+ if (!HostVisible.has_value ()) {
376
+ // Internal/discarded events do not need host-scope visibility.
377
+ HostVisible =
378
+ IsInternal ? false : Queue->Device ->ZeEventsScope == AllHostVisible;
379
+ }
376
380
377
381
// If event is discarded then try to get event from the queue cache.
378
382
*Event =
379
- IsInternal ? Queue->getEventFromQueueCache (ForceHostVisible ) : nullptr ;
383
+ IsInternal ? Queue->getEventFromQueueCache (HostVisible. value () ) : nullptr ;
380
384
381
385
if (*Event == nullptr )
382
- PI_CALL (EventCreate (Queue->Context , Queue, ForceHostVisible , Event));
386
+ PI_CALL (EventCreate (Queue->Context , Queue, HostVisible. value () , Event));
383
387
384
388
(*Event)->Queue = Queue;
385
389
(*Event)->CommandType = CommandType;
@@ -427,10 +431,14 @@ pi_result _pi_queue::signalEventFromCmdListIfLastEventDiscarded(
427
431
LastCommandEvent->IsDiscarded ))
428
432
return PI_SUCCESS;
429
433
434
+ // NOTE: We create this "glue" event not as internal so it is not
435
+ // participating in the discarded events reset/reuse logic, but
436
+ // with no host-visibility since it is not going to be waited
437
+ // from the host.
430
438
pi_event Event;
431
439
PI_CALL (createEventAndAssociateQueue (
432
440
this , &Event, PI_COMMAND_TYPE_USER, CommandList,
433
- /* IsDiscarded */ false , /* ForceHostVisible */ false ))
441
+ /* IsInternal */ false , /* HostVisible */ false ));
434
442
PI_CALL (piEventReleaseInternal (Event));
435
443
LastCommandEvent = Event;
436
444
@@ -1486,7 +1494,7 @@ pi_result _pi_queue::executeCommandList(pi_command_list_ptr_t CommandList,
1486
1494
pi_event HostVisibleEvent;
1487
1495
auto Res = createEventAndAssociateQueue (
1488
1496
this , &HostVisibleEvent, PI_COMMAND_TYPE_USER, CommandList,
1489
- /* IsInternal */ false , /* ForceHostVisible */ true );
1497
+ /* IsInternal */ false , /* HostVisible */ true );
1490
1498
if (Res)
1491
1499
return Res;
1492
1500
@@ -4605,7 +4613,7 @@ _pi_event::getOrCreateHostVisibleEvent(ze_event_handle_t &ZeHostVisibleEvent) {
4605
4613
// Create a "proxy" host-visible event.
4606
4614
auto Res = createEventAndAssociateQueue (
4607
4615
Queue, &HostVisibleEvent, PI_COMMAND_TYPE_USER, CommandList,
4608
- /* IsInternal */ false , /* ForceHostVisible */ true );
4616
+ /* IsInternal */ false , /* HostVisible */ true );
4609
4617
if (Res != PI_SUCCESS)
4610
4618
return Res;
4611
4619
@@ -5457,7 +5465,8 @@ pi_result piEnqueueEventsWait(pi_queue Queue, pi_uint32 NumEventsInWaitList,
5457
5465
5458
5466
if (OutEvent) {
5459
5467
auto Res = createEventAndAssociateQueue (
5460
- Queue, OutEvent, PI_COMMAND_TYPE_USER, Queue->CommandListMap .end ());
5468
+ Queue, OutEvent, PI_COMMAND_TYPE_USER, Queue->CommandListMap .end (),
5469
+ /* IsInternal */ false );
5461
5470
if (Res != PI_SUCCESS)
5462
5471
return Res;
5463
5472
}
@@ -5733,8 +5742,9 @@ pi_result _pi_queue::synchronize() {
5733
5742
return PI_SUCCESS;
5734
5743
5735
5744
pi_event Event;
5736
- pi_result Res = createEventAndAssociateQueue (
5737
- Queue, &Event, PI_COMMAND_TYPE_USER, ImmCmdList, false );
5745
+ pi_result Res =
5746
+ createEventAndAssociateQueue (Queue, &Event, PI_COMMAND_TYPE_USER,
5747
+ ImmCmdList, /* IsInternal */ false );
5738
5748
if (Res != PI_SUCCESS)
5739
5749
return Res;
5740
5750
auto zeEvent = Event->ZeEvent ;
0 commit comments