From 59fcd06003886f421bb6594a208a8960407f11f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20=C5=9Alusarczyk?= Date: Tue, 9 Dec 2025 13:19:07 +0100 Subject: [PATCH] [SYCL] optimize createSyclObjFromImpl calls to take rvalue-ref to shared_ptr if possible --- sycl/include/sycl/ext/oneapi/weak_object.hpp | 3 ++- sycl/include/sycl/kernel_bundle.hpp | 3 ++- sycl/source/detail/program_manager/program_manager.cpp | 6 ++---- sycl/source/detail/queue_impl.cpp | 5 +++-- sycl/source/detail/queue_impl.hpp | 4 ++-- sycl/source/kernel_bundle.cpp | 2 +- sycl/source/queue.cpp | 3 ++- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/sycl/include/sycl/ext/oneapi/weak_object.hpp b/sycl/include/sycl/ext/oneapi/weak_object.hpp index 686b242b0d29c..9fcab38e6b7d1 100644 --- a/sycl/include/sycl/ext/oneapi/weak_object.hpp +++ b/sycl/include/sycl/ext/oneapi/weak_object.hpp @@ -73,7 +73,8 @@ class weak_object : public detail::weak_object_base { auto MObjImplPtr = this->MObjWeakPtr.lock(); if (!MObjImplPtr) return std::nullopt; - return sycl::detail::createSyclObjFromImpl(MObjImplPtr); + return sycl::detail::createSyclObjFromImpl( + std::move(MObjImplPtr)); } SYCLObjT lock() const { std::optional OptionalObj = try_lock(); diff --git a/sycl/include/sycl/kernel_bundle.hpp b/sycl/include/sycl/kernel_bundle.hpp index 9e8619b3d9ed0..6c4c6d57c07e8 100644 --- a/sycl/include/sycl/kernel_bundle.hpp +++ b/sycl/include/sycl/kernel_bundle.hpp @@ -731,7 +731,8 @@ template kernel_bundle get_empty_interop_kernel_bundle(const context &Ctx) { detail::KernelBundleImplPtr Impl = detail::get_empty_interop_kernel_bundle_impl(Ctx, Ctx.get_devices()); - return detail::createSyclObjFromImpl>(Impl); + return detail::createSyclObjFromImpl>( + std::move(Impl)); } } // namespace detail diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index ba59d2cbb7a5a..4b1a6c194466f 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -1723,10 +1723,8 @@ void ProgramManager::addImage(sycl_device_binary RawImg, // ... and create a unique kernel ID for the entry auto It = m_KernelName2KernelIDs.find(name); if (It == m_KernelName2KernelIDs.end()) { - std::shared_ptr KernelIDImpl = - std::make_shared(name); - sycl::kernel_id KernelID = - detail::createSyclObjFromImpl(KernelIDImpl); + sycl::kernel_id KernelID = detail::createSyclObjFromImpl( + std::make_shared(name)); It = m_KernelName2KernelIDs.emplace_hint(It, name, KernelID); } diff --git a/sycl/source/detail/queue_impl.cpp b/sycl/source/detail/queue_impl.cpp index 50fd63b05b291..dc864aeb9e77b 100644 --- a/sycl/source/detail/queue_impl.cpp +++ b/sycl/source/detail/queue_impl.cpp @@ -81,7 +81,7 @@ prepareSYCLEventAssociatedWithQueue(detail::queue_impl &QueueImpl) { auto EventImpl = detail::event_impl::create_device_event(QueueImpl); EventImpl->setContextImpl(QueueImpl.getContextImpl()); EventImpl->setStateIncomplete(); - return detail::createSyclObjFromImpl(EventImpl); + return detail::createSyclObjFromImpl(std::move(EventImpl)); } const std::vector & @@ -103,7 +103,8 @@ queue_impl::getExtendDependencyList(const std::vector &DepEvents, if (ExternalEvent) MutableVec.push_back(*ExternalEvent); if (ExtraEvent) - MutableVec.push_back(detail::createSyclObjFromImpl(ExtraEvent)); + MutableVec.push_back( + detail::createSyclObjFromImpl(std::move(ExtraEvent))); return MutableVec; } diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index da606acfdc0f4..2dbd430c6b388 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -348,7 +348,7 @@ class queue_impl : public std::enable_shared_from_this { detail::EventImplPtr ResEvent = submit_impl(CGF, /*CallerNeedsEvent=*/true, Loc, IsTopCodeLoc, SubmitInfo); - return createSyclObjFromImpl(ResEvent); + return createSyclObjFromImpl(std::move(ResEvent)); } event submit_kernel_direct_with_event( @@ -361,7 +361,7 @@ class queue_impl : public std::enable_shared_from_this { detail::EventImplPtr EventImpl = submit_kernel_direct_impl( NDRDescT(RangeView), HostKernel, DeviceKernelInfo, /*CallerNeedsEvent*/ true, DepEvents, Props, CodeLoc, IsTopCodeLoc); - return createSyclObjFromImpl(EventImpl); + return createSyclObjFromImpl(std::move(EventImpl)); } void submit_kernel_direct_without_event( diff --git a/sycl/source/kernel_bundle.cpp b/sycl/source/kernel_bundle.cpp index 9639f0cb960d0..02dd935ea2bb5 100644 --- a/sycl/source/kernel_bundle.cpp +++ b/sycl/source/kernel_bundle.cpp @@ -516,7 +516,7 @@ obj_kb compile_from_source( kernel_bundle_impl &sourceImpl = *getSyclObjImpl(SourceKB); std::shared_ptr KBImpl = sourceImpl.compile_from_source( UniqueDevices, BuildOptions, LogPtr, RegisteredKernelNames); - auto result = sycl::detail::createSyclObjFromImpl(KBImpl); + auto result = sycl::detail::createSyclObjFromImpl(std::move(KBImpl)); if (LogView) *LogView = Log; return result; diff --git a/sycl/source/queue.cpp b/sycl/source/queue.cpp index 2a4b3f0bc243e..1efa8a45b5d05 100644 --- a/sycl/source/queue.cpp +++ b/sycl/source/queue.cpp @@ -92,7 +92,8 @@ queue::ext_oneapi_get_graph() const { return sycl::detail::createSyclObjFromImpl< ext::oneapi::experimental::command_graph< - ext::oneapi::experimental::graph_state::modifiable>>(Graph); + ext::oneapi::experimental::graph_state::modifiable>>( + std::move(Graph)); } void queue::throw_asynchronous() { impl->throw_asynchronous(); }