Skip to content

[SYCL][L0] Make sure that we only query/sync host-visible events from the host. #4613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,11 @@ pi_result _pi_queue::resetCommandList(pi_command_list_ptr_t CommandList,
CommandList->second.InUse = false;

// Finally release/cleanup all the events in this command list.
// Note, we don't need to synchronize the events since the fence
// synchronized above already does that.
auto &EventList = CommandList->second.EventList;
for (auto &Event : EventList) {
if (!Event->CleanedUp) {
ZE_CALL(zeHostSynchronize, (Event->ZeEvent));
Event->cleanup(this);
}
Event->ZeCommandList = nullptr;
Expand Down Expand Up @@ -1349,10 +1350,10 @@ pi_result _pi_ze_event_list_t::createAndRetainPiZeEventList(
PI_ASSERT(EventList[I] != nullptr, PI_INVALID_VALUE);
auto ZeEvent = EventList[I]->ZeEvent;

// Avoid polling of the device-scope events.
// TODO: be more fine-grain and check individual events.
if (FilterEventWaitList && ZeAllHostVisibleEvents) {
auto Res = ZE_CALL_NOCHECK(zeEventQueryStatus, (ZeEvent));
// Poll of the host-visible events.
auto ZeEventHostVisible = EventList[I]->getHostVisibleEvent();
if (FilterEventWaitList && ZeEventHostVisible) {
auto Res = ZE_CALL_NOCHECK(zeEventQueryStatus, (ZeEventHostVisible));
if (Res == ZE_RESULT_SUCCESS) {
// Event has already completed, don't put it into the list
continue;
Expand Down Expand Up @@ -4507,7 +4508,7 @@ ze_event_handle_t _pi_event::getHostVisibleEvent() const {
} else if (ZeHostVisibleEvent) {
return ZeHostVisibleEvent;
} else {
die("The host-visible proxy event missing");
return nullptr;
}
}

Expand Down Expand Up @@ -4642,17 +4643,19 @@ pi_result piEventGetInfo(pi_event Event, pi_event_info ParamName,
}
}

// Make sure that we query the host-visible event.
ze_event_handle_t ZeHostVisibleEvent;
if (auto Res = Event->getOrCreateHostVisibleEvent(ZeHostVisibleEvent))
return Res;

ze_result_t ZeResult;
ZeResult = ZE_CALL_NOCHECK(zeEventQueryStatus, (ZeHostVisibleEvent));
if (ZeResult == ZE_RESULT_SUCCESS) {
return getInfo(ParamValueSize, ParamValue, ParamValueSizeRet,
pi_int32{CL_COMPLETE}); // Untie from OpenCL
// Make sure that we query a host-visible event only.
// If one wasn't yet created then don't create it here as well, and
// just conservatively return that event is not yet completed.
auto ZeHostVisibleEvent = Event->getHostVisibleEvent();
if (ZeHostVisibleEvent) {
ze_result_t ZeResult;
ZeResult = ZE_CALL_NOCHECK(zeEventQueryStatus, (ZeHostVisibleEvent));
if (ZeResult == ZE_RESULT_SUCCESS) {
return getInfo(ParamValueSize, ParamValue, ParamValueSizeRet,
pi_int32{CL_COMPLETE}); // Untie from OpenCL
}
}

// TODO: We don't know if the status is queued, submitted or running.
// For now return "running", as others are unlikely to be of
// interest.
Expand Down Expand Up @@ -4883,6 +4886,9 @@ pi_result piEventsWait(pi_uint32 NumEvents, const pi_event *EventList) {

for (uint32_t I = 0; I < NumEvents; I++) {
ze_event_handle_t ZeEvent = EventList[I]->getHostVisibleEvent();
if (!ZeEvent)
die("The host-visible proxy event missing");

zePrint("ZeEvent = %#lx\n", pi_cast<std::uintptr_t>(ZeEvent));
ZE_CALL(zeHostSynchronize, (ZeEvent));

Expand Down
2 changes: 1 addition & 1 deletion sycl/plugins/level_zero/pi_level_zero.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ struct _pi_event : _pi_object {
ze_event_pool_handle_t ZeHostVisibleEventPool = {nullptr};
// Get the host-visible event or create one and enqueue its signal.
pi_result getOrCreateHostVisibleEvent(ze_event_handle_t &HostVisibleEvent);
// Get the host-visible event ensuring that one was already created before.
// Return the host-visible event if one was already created before, or null.
ze_event_handle_t getHostVisibleEvent() const;

// Level Zero command list where the command signaling this event was appended
Expand Down