From fe9b08a2190d231e762f4b7ef1773deae8f6b0b8 Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Fri, 24 Feb 2023 15:50:36 -0800 Subject: [PATCH] [SYCL] Fix refcounting for kernel_bundle interop with OpenCL OpenCL interop spec basically says that each "conversion" must adjust reference counter of the underlying object. Many of the interop interfaces had been fixed in https://github.com/intel/llvm/pull/3236 but the majority of the kernel_bundle feature was implemented after that and made the same omission. I'm not sure if that is the best way to fix it though. Another alternative would be to move all these retains into the OpenCL PI plugin. --- sycl/source/backend.cpp | 2 ++ sycl/source/detail/device_image_impl.hpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/sycl/source/backend.cpp b/sycl/source/backend.cpp index 8e9d9e94a3223..495c123f7d008 100644 --- a/sycl/source/backend.cpp +++ b/sycl/source/backend.cpp @@ -141,6 +141,8 @@ make_kernel_bundle(pi_native_handle NativeHandle, const context &TargetContext, pi::PiProgram PiProgram = nullptr; Plugin.call( NativeHandle, ContextImpl->getHandleRef(), !KeepOwnership, &PiProgram); + if (Plugin.getBackend() == backend::opencl) + Plugin.call(PiProgram); std::vector ProgramDevices; size_t NumDevices = 0; diff --git a/sycl/source/detail/device_image_impl.hpp b/sycl/source/detail/device_image_impl.hpp index 719563d456e1f..f04fea1b8c774 100644 --- a/sycl/source/detail/device_image_impl.hpp +++ b/sycl/source/detail/device_image_impl.hpp @@ -230,6 +230,8 @@ class device_image_impl { const auto &ContextImplPtr = detail::getSyclObjImpl(MContext); const plugin &Plugin = ContextImplPtr->getPlugin(); + if (Plugin.getBackend() == backend::opencl) + Plugin.call(MProgram); pi_native_handle NativeProgram = 0; Plugin.call(MProgram, &NativeProgram);