Skip to content

[SYCL] Fix memory leak for interop events created from native handle #6180

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 7 commits into from
May 24, 2022
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
7 changes: 7 additions & 0 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5664,6 +5664,13 @@ pi_result piextEventCreateWithNativeHandle(pi_native_handle NativeHandle,
// need to create a host-visible proxy for it.
(*Event)->HostVisibleEvent = *Event;

// Unlike regular events managed by SYCL RT we don't have to wait for interop
// events completion, and not need to do the their `cleanup()`. This in
// particular guarantees that the extra `piEventRelease` is not called on
// them. That release is needed to match the `piEventRetain` of regular events
// made for waiting for event completion, but not this interop event.
(*Event)->CleanedUp = true;

return PI_SUCCESS;
}

Expand Down
6 changes: 5 additions & 1 deletion sycl/source/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@ __SYCL_EXPORT event make_event(pi_native_handle NativeHandle,
Plugin.call<PiApiKind::piextEventCreateWithNativeHandle>(
NativeHandle, ContextImpl->getHandleRef(), !KeepOwnership, &PiEvent);

return detail::createSyclObjFromImpl<event>(
event Event = detail::createSyclObjFromImpl<event>(
std::make_shared<event_impl>(PiEvent, Context));

if (Backend == backend::opencl)
Plugin.call<PiApiKind::piEventRetain>(PiEvent);
return Event;
}

std::shared_ptr<detail::kernel_bundle_impl>
Expand Down
2 changes: 0 additions & 2 deletions sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ event_impl::event_impl(RT::PiEvent Event, const context &SyclContext)
"clEvent.",
PI_INVALID_CONTEXT);
}

getPlugin().call<PiApiKind::piEventRetain>(MEvent);
}

event_impl::event_impl(const QueueImplPtr &Queue)
Expand Down