Skip to content

[SYCL] Fix use-after-release kernel issue #18146

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

Closed
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
3 changes: 1 addition & 2 deletions sycl/source/detail/graph_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,11 +1474,10 @@ void exec_graph_impl::populateURKernelUpdateStructs(
ur_kernel_handle_t UrKernel = nullptr;
auto Kernel = ExecCG.MSyclKernel;
auto KernelBundleImplPtr = ExecCG.MKernelBundle;
std::shared_ptr<sycl::detail::kernel_impl> SyclKernelImpl = nullptr;
const sycl::detail::KernelArgMask *EliminatedArgMask = nullptr;

if (auto SyclKernelImpl = KernelBundleImplPtr
? KernelBundleImplPtr->tryGetKernel(
? KernelBundleImplPtr->tryGetOfflineKernel(
ExecCG.MKernelName, KernelBundleImplPtr)
: std::shared_ptr<kernel_impl>{nullptr}) {
UrKernel = SyclKernelImpl->getHandleRef();
Expand Down
21 changes: 14 additions & 7 deletions sycl/source/detail/kernel_bundle_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ class kernel_bundle_impl {
get_kernel(const kernel_id &KernelID,
const std::shared_ptr<detail::kernel_bundle_impl> &Self) const {
if (std::shared_ptr<kernel_impl> KernelImpl =
tryGetOfflineKernel(KernelID, Self))
tryGetOfflineKernelImpl(KernelID, Self))
return detail::createSyclObjFromImpl<kernel>(std::move(KernelImpl));
throw sycl::exception(make_error_code(errc::invalid),
"The kernel bundle does not contain the kernel "
Expand Down Expand Up @@ -692,7 +692,7 @@ class kernel_bundle_impl {
});
}

std::shared_ptr<kernel_impl> tryGetOfflineKernel(
std::shared_ptr<kernel_impl> tryGetOfflineKernelImpl(
const kernel_id &KernelID,
const std::shared_ptr<detail::kernel_bundle_impl> &Self) const {
using ImageImpl = std::shared_ptr<detail::device_image_impl>;
Expand Down Expand Up @@ -758,6 +758,17 @@ class kernel_bundle_impl {
SelectedImage->get_ur_program_ref(), CacheMutex);
}

std::shared_ptr<kernel_impl>
tryGetOfflineKernel(detail::KernelNameStrRefT Name,
const std::shared_ptr<kernel_bundle_impl> &Self) const {
// Fall back to regular offline compiled kernel_bundle look-up.
if (std::optional<kernel_id> MaybeKernelID =
sycl::detail::ProgramManager::getInstance().tryGetSYCLKernelID(
Name))
return tryGetOfflineKernelImpl(*MaybeKernelID, Self);
return nullptr;
}

std::shared_ptr<kernel_impl>
tryGetKernel(detail::KernelNameStrRefT Name,
const std::shared_ptr<kernel_bundle_impl> &Self) const {
Expand All @@ -774,11 +785,7 @@ class kernel_bundle_impl {
}

// Fall back to regular offline compiled kernel_bundle look-up.
if (std::optional<kernel_id> MaybeKernelID =
sycl::detail::ProgramManager::getInstance().tryGetSYCLKernelID(
Name))
return tryGetOfflineKernel(*MaybeKernelID, Self);
return nullptr;
return tryGetOfflineKernel(Name, Self);
}

private:
Expand Down
4 changes: 2 additions & 2 deletions sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2523,8 +2523,8 @@ getCGKernelInfo(const CGExecKernel &CommandGroup, ContextImplPtr ContextImpl,

if (auto SyclKernelImpl =
KernelBundleImplPtr
? KernelBundleImplPtr->tryGetKernel(CommandGroup.MKernelName,
KernelBundleImplPtr)
? KernelBundleImplPtr->tryGetOfflineKernel(
CommandGroup.MKernelName, KernelBundleImplPtr)
: std::shared_ptr<kernel_impl>{nullptr}) {
UrKernel = SyclKernelImpl->getHandleRef();
DeviceImageImpl = SyclKernelImpl->getDeviceImage();
Expand Down
6 changes: 2 additions & 4 deletions sycl/source/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,8 @@ event handler::finalize() {
// Make sure implicit non-interop kernel bundles have the kernel
if (!impl->isStateExplicitKernelBundle() &&
!(MKernel && MKernel->isInterop()) &&
(KernelBundleImpPtr->empty() ||
KernelBundleImpPtr->hasSYCLOfflineImages()) &&
!KernelBundleImpPtr->tryGetKernel(MKernelName.data(),
KernelBundleImpPtr)) {
!KernelBundleImpPtr->tryGetOfflineKernel(MKernelName.data(),
KernelBundleImpPtr)) {
auto Dev =
impl->MGraph ? impl->MGraph->getDevice() : MQueue->get_device();
kernel_id KernelID =
Expand Down
Loading