Skip to content

Commit

Permalink
Merge pull request #1656 from pbalcer/leaks-program-kernel
Browse files Browse the repository at this point in the history
fix leaks on level-zero interop program and kernel handles
  • Loading branch information
kbenzie committed May 24, 2024
1 parent 3b57cff commit d403f07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions source/adapters/level_zero/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelCreateWithNativeHandle(
try {
Kernel = new ur_kernel_handle_t_(ZeKernel, Properties->isNativeHandleOwned,
Context);
if (Properties->isNativeHandleOwned) {
// If ownership is passed to the adapter we need to pass the kernel
// to this vector which is then used during ZeKernelRelease.
Kernel->ZeKernels.push_back(ZeKernel);
}

*RetKernel = reinterpret_cast<ur_kernel_handle_t>(Kernel);
} catch (const std::bad_alloc &) {
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
Expand Down
11 changes: 8 additions & 3 deletions source/adapters/level_zero/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,15 @@ void ur_program_handle_t_::ur_release_program_resources(bool deletion) {
}

if (ZeModule && OwnZeModule) {
for (auto &ZeModulePair : this->ZeModuleMap) {
ZE_CALL_NOCHECK(zeModuleDestroy, (ZeModulePair.second));
if (ZeModuleMap.empty()) {
// interop api
ZE_CALL_NOCHECK(zeModuleDestroy, (ZeModule));
} else {
for (auto &ZeModulePair : this->ZeModuleMap) {
ZE_CALL_NOCHECK(zeModuleDestroy, (ZeModulePair.second));
}
this->ZeModuleMap.clear();
}
this->ZeModuleMap.clear();
}
resourcesReleased = true;
}
Expand Down

0 comments on commit d403f07

Please sign in to comment.