Skip to content

Commit 29536ed

Browse files
[SYCL][L0] Use device-scope events for queue with discard_events property (#8908)
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent 305da17 commit 29536ed

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -364,22 +364,26 @@ pi_result _pi_queue::resetDiscardedEvent(pi_command_list_ptr_t CommandList) {
364364
// \param CommandList is the command list where the event is added
365365
// \param IsInternal tells if the event is internal, i.e. visible in the L0
366366
// 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) {
373374

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+
}
376380

377381
// If event is discarded then try to get event from the queue cache.
378382
*Event =
379-
IsInternal ? Queue->getEventFromQueueCache(ForceHostVisible) : nullptr;
383+
IsInternal ? Queue->getEventFromQueueCache(HostVisible.value()) : nullptr;
380384

381385
if (*Event == nullptr)
382-
PI_CALL(EventCreate(Queue->Context, Queue, ForceHostVisible, Event));
386+
PI_CALL(EventCreate(Queue->Context, Queue, HostVisible.value(), Event));
383387

384388
(*Event)->Queue = Queue;
385389
(*Event)->CommandType = CommandType;
@@ -427,10 +431,14 @@ pi_result _pi_queue::signalEventFromCmdListIfLastEventDiscarded(
427431
LastCommandEvent->IsDiscarded))
428432
return PI_SUCCESS;
429433

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.
430438
pi_event Event;
431439
PI_CALL(createEventAndAssociateQueue(
432440
this, &Event, PI_COMMAND_TYPE_USER, CommandList,
433-
/* IsDiscarded */ false, /* ForceHostVisible */ false))
441+
/* IsInternal */ false, /* HostVisible */ false));
434442
PI_CALL(piEventReleaseInternal(Event));
435443
LastCommandEvent = Event;
436444

@@ -1486,7 +1494,7 @@ pi_result _pi_queue::executeCommandList(pi_command_list_ptr_t CommandList,
14861494
pi_event HostVisibleEvent;
14871495
auto Res = createEventAndAssociateQueue(
14881496
this, &HostVisibleEvent, PI_COMMAND_TYPE_USER, CommandList,
1489-
/* IsInternal */ false, /* ForceHostVisible */ true);
1497+
/* IsInternal */ false, /* HostVisible */ true);
14901498
if (Res)
14911499
return Res;
14921500

@@ -4605,7 +4613,7 @@ _pi_event::getOrCreateHostVisibleEvent(ze_event_handle_t &ZeHostVisibleEvent) {
46054613
// Create a "proxy" host-visible event.
46064614
auto Res = createEventAndAssociateQueue(
46074615
Queue, &HostVisibleEvent, PI_COMMAND_TYPE_USER, CommandList,
4608-
/* IsInternal */ false, /* ForceHostVisible */ true);
4616+
/* IsInternal */ false, /* HostVisible */ true);
46094617
if (Res != PI_SUCCESS)
46104618
return Res;
46114619

@@ -5457,7 +5465,8 @@ pi_result piEnqueueEventsWait(pi_queue Queue, pi_uint32 NumEventsInWaitList,
54575465

54585466
if (OutEvent) {
54595467
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);
54615470
if (Res != PI_SUCCESS)
54625471
return Res;
54635472
}
@@ -5733,8 +5742,9 @@ pi_result _pi_queue::synchronize() {
57335742
return PI_SUCCESS;
57345743

57355744
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);
57385748
if (Res != PI_SUCCESS)
57395749
return Res;
57405750
auto zeEvent = Event->ZeEvent;

0 commit comments

Comments
 (0)