diff --git a/source/adapters/level_zero/kernel.cpp b/source/adapters/level_zero/kernel.cpp index 44d3654448..acefd600be 100644 --- a/source/adapters/level_zero/kernel.cpp +++ b/source/adapters/level_zero/kernel.cpp @@ -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(Kernel); } catch (const std::bad_alloc &) { return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; diff --git a/source/adapters/level_zero/program.cpp b/source/adapters/level_zero/program.cpp index d60b2a3322..bfb7bf52e2 100644 --- a/source/adapters/level_zero/program.cpp +++ b/source/adapters/level_zero/program.cpp @@ -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; }