From 1b0dc36f2664ee8d873783da157027a8d65da188 Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Tue, 2 Dec 2025 14:35:27 -0800 Subject: [PATCH 1/3] [SYCL] Make `sycl::device` use raw `device_impl *` for its `impl` `device_impl`s are owned by the parent platforms and are only destroyed when SYCL RT is unloaded. As such, there is no reason to pay the price of a `std::shared_ptr` a raw non-owning pointers is enough. Use a pointer and not a reference because `sycl::device` is assignable. --- sycl/gdb/libsycl.so-gdb.py | 4 +- sycl/include/sycl/device.hpp | 23 +++++-- .../sycl/ext/oneapi/backend/level_zero.hpp | 3 +- .../oneapi/experimental/current_device.hpp | 11 +--- sycl/include/sycl/ext/oneapi/weak_object.hpp | 61 +++++++++++++++++++ sycl/include/sycl/interop_handle.hpp | 4 +- sycl/source/detail/context_impl.hpp | 3 +- sycl/source/detail/device_impl.hpp | 2 +- sycl/source/detail/platform_impl.cpp | 18 +++++- sycl/source/detail/platform_impl.hpp | 15 +---- .../program_manager/program_manager.cpp | 2 +- sycl/source/detail/scheduler/commands.cpp | 7 +-- sycl/source/detail/usm/usm_impl.cpp | 2 +- sycl/source/device.cpp | 5 +- sycl/source/device_selector.cpp | 2 +- sycl/source/interop_handle.cpp | 4 +- sycl/source/kernel_bundle.cpp | 2 +- sycl/source/physical_mem.cpp | 2 +- sycl/test/abi/symbol_size_alignment.cpp | 2 +- sycl/test/gdb/printers.cpp | 7 ++- .../Extensions/CommandGraph/Exceptions.cpp | 1 - sycl/unittests/SYCL2020/KernelBundle.cpp | 2 +- .../PersistentDeviceCodeCache.cpp | 14 ++--- 23 files changed, 134 insertions(+), 62 deletions(-) diff --git a/sycl/gdb/libsycl.so-gdb.py b/sycl/gdb/libsycl.so-gdb.py index 96767fe228051..87e637ff0a670 100644 --- a/sycl/gdb/libsycl.so-gdb.py +++ b/sycl/gdb/libsycl.so-gdb.py @@ -374,14 +374,14 @@ def range_common_array(self): class SYCLDevice(SYCLValue): """Provides information about a sycl::device from a gdb.Value.""" - IMPL_OFFSET_TO_PLATFORM = 0x18 + IMPL_OFFSET_TO_PLATFORM = 0x8 PLATFORM_OFFSET_TO_BACKEND = 0x20 def __init__(self, gdb_value): super().__init__(gdb_value) def impl_ptr(self): - return self.gdb_value()["impl"]["_M_ptr"] + return self.gdb_value()["impl"] def backend(self): char_ptr = SYCLType.char_type().pointer() diff --git a/sycl/include/sycl/device.hpp b/sycl/include/sycl/device.hpp index a2836228704f5..be3cf0d192d97 100644 --- a/sycl/include/sycl/device.hpp +++ b/sycl/include/sycl/device.hpp @@ -57,15 +57,14 @@ enum class peer_access { access_supported = 0x0, atomics_supported = 0x1, }; - +template class weak_object; } // namespace ext::oneapi /// The SYCL device class encapsulates a single SYCL device on which kernels /// may be executed. /// /// \ingroup sycl_api -class __SYCL_STANDALONE_DEBUG __SYCL_EXPORT device - : public detail::OwnerLessBase { +class __SYCL_STANDALONE_DEBUG __SYCL_EXPORT device { friend sycl::detail::ImplUtils; public: @@ -93,6 +92,12 @@ class __SYCL_STANDALONE_DEBUG __SYCL_EXPORT device /// \param DeviceSelector is SYCL 2020 Device Selector, a simple callable that /// takes a device and returns an int template >, typename = detail::EnableIfSYCL2020DeviceSelectorInvocable> explicit device(const DeviceSelector &deviceSelector) @@ -361,14 +366,22 @@ class __SYCL_STANDALONE_DEBUG __SYCL_EXPORT device /// \return the default context context ext_oneapi_get_default_context(); + // Definitions are in `` to avoid circular + // dependencies: + inline bool ext_oneapi_owner_before(const device &Other) const noexcept; + inline bool ext_oneapi_owner_before( + const ext::oneapi::weak_object &Other) const noexcept; + // TODO: Remove this diagnostics when __SYCL_WARN_IMAGE_ASPECT is removed. #if defined(__clang__) #pragma clang diagnostic pop #endif // defined(__clang__) private: - std::shared_ptr impl; - device(std::shared_ptr Impl) : impl(std::move(Impl)) {} + // `device_impl`s are owned by the parent platform, user-visible + // `sycl::device` is non-owning and thus very cheap. + detail::device_impl *impl = nullptr; + device(detail::device_impl &impl) : impl(&impl) {} ur_native_handle_t getNative() const; diff --git a/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp b/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp index bd34d76716b96..08c1ccf159610 100644 --- a/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp +++ b/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp @@ -113,7 +113,8 @@ inline device make_device( continue; for (auto &d : p.get_devices()) { - if (auto maybe_device = find_matching_descendent_device(d, BackendObject)) + if (auto maybe_device = + detail::find_matching_descendent_device(d, BackendObject)) return *maybe_device; } } diff --git a/sycl/include/sycl/ext/oneapi/experimental/current_device.hpp b/sycl/include/sycl/ext/oneapi/experimental/current_device.hpp index 7dc41bfc0970b..acde8de7051c8 100644 --- a/sycl/include/sycl/ext/oneapi/experimental/current_device.hpp +++ b/sycl/include/sycl/ext/oneapi/experimental/current_device.hpp @@ -16,13 +16,8 @@ namespace ext::oneapi::experimental::this_thread { namespace detail { using namespace sycl::detail; -// Underlying `std::shared_ptr`'s lifetime is tied to the -// `global_handler`, so a subsequent `lock()` is expected to be successful when -// used from user app. We still go through `std::weak_ptr` here because our own -// unittests are linked statically against SYCL RT objects and have to implement -// some hacks to emulate the lifetime management done by the `global_handler`. -inline std::weak_ptr &get_current_device_impl() { - static thread_local std::weak_ptr current_device{ +inline device_impl *&get_current_device_impl() { + static thread_local device_impl *current_device{ getSyclObjImpl(sycl::device{sycl::default_selector_v})}; return current_device; } @@ -36,7 +31,7 @@ inline std::weak_ptr &get_current_device_impl() { /// task or an asynchronous error handler. inline sycl::device get_current_device() { return detail::createSyclObjFromImpl( - detail::get_current_device_impl().lock()); + *detail::get_current_device_impl()); } /// @brief Sets the current default device to `dev` for the calling host thread. diff --git a/sycl/include/sycl/ext/oneapi/weak_object.hpp b/sycl/include/sycl/ext/oneapi/weak_object.hpp index 686b242b0d29c..c6d6ffeba2d78 100644 --- a/sycl/include/sycl/ext/oneapi/weak_object.hpp +++ b/sycl/include/sycl/ext/oneapi/weak_object.hpp @@ -233,6 +233,67 @@ class weak_object : public detail::weak_object_base { weak_object MWeakGlobalFlushBuf; }; +template <> class weak_object { + friend sycl::device; + + detail::device_impl *dev_impl = nullptr; + +public: + using object_type = device; + + constexpr weak_object() noexcept = default; + weak_object(const device &dev) noexcept + : dev_impl(detail::getSyclObjImpl(dev)) {} + weak_object(const weak_object &Other) noexcept = default; + weak_object(weak_object &&Other) noexcept = default; + + weak_object &operator=(const device &Other) noexcept { + this->dev_impl = detail::getSyclObjImpl(Other); + return *this; + } + weak_object &operator=(const weak_object &Other) noexcept = default; + weak_object &operator=(weak_object &&Other) noexcept = default; + + bool expired() const noexcept { return dev_impl == nullptr; } + + void reset() noexcept { dev_impl = nullptr; } + +#ifndef __SYCL_DEVICE_ONLY__ + std::optional try_lock() const noexcept { + if (!dev_impl) + return std::nullopt; + return sycl::detail::createSyclObjFromImpl(*dev_impl); + } + device lock() const { + std::optional OptionalObj = try_lock(); + if (!OptionalObj) + throw sycl::exception(sycl::make_error_code(sycl::errc::invalid), + "Referenced object has expired."); + return *OptionalObj; + } + bool owner_before(const device &Other) const noexcept { + return dev_impl < detail::getSyclObjImpl(Other); + } + bool owner_before(const weak_object &Other) const noexcept { + return dev_impl < Other.dev_impl; + } +#else + // On device calls to these functions are disallowed, so declare them but + // don't define them to avoid compilation failures. + std::optional try_lock() const noexcept; + device lock() const; + bool owner_before(const device &Other) const noexcept; + bool owner_before(const weak_object &Other) const noexcept; +#endif // __SYCL_DEVICE_ONLY__ +}; } // namespace ext::oneapi +inline bool +device::ext_oneapi_owner_before(const device &Other) const noexcept { + return impl < Other.impl; +} +inline bool device::ext_oneapi_owner_before( + const ext::oneapi::weak_object &Other) const noexcept { + return impl < Other.dev_impl; +} } // namespace _V1 } // namespace sycl diff --git a/sycl/include/sycl/interop_handle.hpp b/sycl/include/sycl/interop_handle.hpp index b797284ce5de5..7e32b1326f742 100644 --- a/sycl/include/sycl/interop_handle.hpp +++ b/sycl/include/sycl/interop_handle.hpp @@ -213,7 +213,7 @@ class interop_handle { #endif interop_handle(std::vector MemObjs, const std::shared_ptr &Queue, - const std::shared_ptr &Device, + detail::device_impl &Device, const std::shared_ptr &Context, ur_exp_command_buffer_handle_t Graph = nullptr) : MQueue(Queue), MDevice(Device), MContext(Context), MGraph(Graph), @@ -243,7 +243,7 @@ class interop_handle { __SYCL_EXPORT ur_native_handle_t getNativeGraph() const; std::shared_ptr MQueue; - std::shared_ptr MDevice; + detail::device_impl &MDevice; std::shared_ptr MContext; ur_exp_command_buffer_handle_t MGraph; diff --git a/sycl/source/detail/context_impl.hpp b/sycl/source/detail/context_impl.hpp index 3b42a6319d223..d8c401e0ebb15 100644 --- a/sycl/source/detail/context_impl.hpp +++ b/sycl/source/detail/context_impl.hpp @@ -186,8 +186,7 @@ class context_impl : public std::enable_shared_from_this { return false; } CurrDevice = detail::getSyclObjImpl( - CurrDevice->get_info()) - .get(); + CurrDevice->get_info()); } return true; diff --git a/sycl/source/detail/device_impl.hpp b/sycl/source/detail/device_impl.hpp index 1e3b735bf86f4..959061d084520 100644 --- a/sycl/source/detail/device_impl.hpp +++ b/sycl/source/detail/device_impl.hpp @@ -129,7 +129,7 @@ template using ur_ret_type = decltype(ur_ret_type_impl()); // TODO: Make code thread-safe -class device_impl : public std::enable_shared_from_this { +class device_impl { struct private_tag { explicit private_tag() = default; }; diff --git a/sycl/source/detail/platform_impl.cpp b/sycl/source/detail/platform_impl.cpp index d88b8972aa5d1..0234ea77bd0bd 100644 --- a/sycl/source/detail/platform_impl.cpp +++ b/sycl/source/detail/platform_impl.cpp @@ -30,6 +30,20 @@ namespace sycl { inline namespace _V1 { namespace detail { +platform_impl::platform_impl(ur_platform_handle_t APlatform, + adapter_impl &Adapter) + : MPlatform(APlatform), MAdapter(&Adapter) { + + // Find out backend of the platform + ur_backend_t UrBackend = UR_BACKEND_UNKNOWN; + Adapter.call_nocheck( + APlatform, UR_PLATFORM_INFO_BACKEND, sizeof(ur_backend_t), &UrBackend, + nullptr); + MBackend = convertUrBackend(UrBackend); +} + +platform_impl::~platform_impl() = default; + platform_impl & platform_impl::getOrMakePlatformImpl(ur_platform_handle_t UrPlatform, adapter_impl &Adapter) { @@ -266,7 +280,7 @@ device_impl &platform_impl::getOrMakeDeviceImpl(ur_device_handle_t UrDevice) { return *Result; // Otherwise make the impl - MDevices.emplace_back(std::make_shared( + MDevices.emplace_back(std::make_unique( UrDevice, *this, device_impl::private_tag{})); return *MDevices.back(); @@ -568,7 +582,7 @@ bool platform_impl::has(aspect Aspect) const { } device_impl *platform_impl::getDeviceImplHelper(ur_device_handle_t UrDevice) { - for (const std::shared_ptr &Device : MDevices) { + for (const std::unique_ptr &Device : MDevices) { if (Device->getHandleRef() == UrDevice) return Device.get(); } diff --git a/sycl/source/detail/platform_impl.hpp b/sycl/source/detail/platform_impl.hpp index adc2cb6c04a9a..ca6594a11ab21 100644 --- a/sycl/source/detail/platform_impl.hpp +++ b/sycl/source/detail/platform_impl.hpp @@ -39,18 +39,9 @@ class platform_impl : public std::enable_shared_from_this { // // Platforms can only be created under `GlobalHandler`'s ownership via // `platform_impl::getOrMakePlatformImpl` method. - explicit platform_impl(ur_platform_handle_t APlatform, adapter_impl &Adapter) - : MPlatform(APlatform), MAdapter(&Adapter) { - - // Find out backend of the platform - ur_backend_t UrBackend = UR_BACKEND_UNKNOWN; - Adapter.call_nocheck( - APlatform, UR_PLATFORM_INFO_BACKEND, sizeof(ur_backend_t), &UrBackend, - nullptr); - MBackend = convertUrBackend(UrBackend); - } + explicit platform_impl(ur_platform_handle_t APlatform, adapter_impl &Adapter); - ~platform_impl() = default; + ~platform_impl(); public: /// Checks if this platform supports extension. @@ -221,7 +212,7 @@ class platform_impl : public std::enable_shared_from_this { adapter_impl *MAdapter; - std::vector> MDevices; + std::vector> MDevices; friend class GlobalHandler; std::mutex MDeviceMapMutex; }; diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index 835e31952d5d0..6e15a41d1cb68 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -2470,7 +2470,7 @@ device_image_plain ProgramManager::getDeviceImageFromBinaryImage( const device &Dev) { const bundle_state ImgState = getBinImageState(BinImage); - assert(compatibleWithDevice(BinImage, *getSyclObjImpl(Dev).get())); + assert(compatibleWithDevice(BinImage, *getSyclObjImpl(Dev))); std::shared_ptr> KernelIDs; // Collect kernel names for the image. diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index f36b1e269e009..db70c8d1c5474 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -424,7 +424,7 @@ class DispatchHostTask { assert(HostTask.MQueue && "Host task submissions should have an associated queue"); interop_handle IH{MReqToMem, HostTask.MQueue, - HostTask.MQueue->getDeviceImpl().shared_from_this(), + HostTask.MQueue->getDeviceImpl(), HostTask.MQueue->getContextImpl().shared_from_this()}; // TODO: should all the backends that support this entry point use this // for host task? @@ -3163,8 +3163,7 @@ ur_result_t ExecCGCommand::enqueueImpCommandBuffer() { ur_exp_command_buffer_handle_t InteropCommandBuffer = ChildCommandBuffer ? ChildCommandBuffer : MCommandBuffer; - interop_handle IH{std::move(ReqToMem), MQueue, - DeviceImpl.shared_from_this(), + interop_handle IH{std::move(ReqToMem), MQueue, DeviceImpl, ContextImpl.shared_from_this(), InteropCommandBuffer}; CommandBufferNativeCommandData CustomOpData{ std::move(IH), HostTask->MHostTask->MInteropTask}; @@ -3539,7 +3538,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() { EnqueueNativeCommandData CustomOpData{ interop_handle{std::move(ReqToMem), HostTask->MQueue, - HostTask->MQueue->getDeviceImpl().shared_from_this(), + HostTask->MQueue->getDeviceImpl(), HostTask->MQueue->getContextImpl().shared_from_this()}, HostTask->MHostTask->MInteropTask}; diff --git a/sycl/source/detail/usm/usm_impl.cpp b/sycl/source/detail/usm/usm_impl.cpp index 27e05a2c636b4..4151bf9feb381 100644 --- a/sycl/source/detail/usm/usm_impl.cpp +++ b/sycl/source/detail/usm/usm_impl.cpp @@ -245,7 +245,7 @@ void *alignedAlloc(size_t Alignment, size_t Size, const context &Ctxt, #endif void *RetVal = alignedAllocInternal(Alignment, Size, getSyclObjImpl(Ctxt).get(), - getSyclObjImpl(Dev).get(), Kind, PropList); + getSyclObjImpl(Dev), Kind, PropList); #ifdef XPTI_ENABLE_INSTRUMENTATION // Once the allocation is complete, update metadata with the memory pointer // before the mem_alloc_end event is sent diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index 3b8caf79ff72e..cc68a356763e3 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -41,9 +41,8 @@ device::device(cl_device_id DeviceId) { Adapter.call( detail::ur::cast(DeviceId), Adapter.getUrAdapter(), nullptr, &Device); - impl = detail::platform_impl::getPlatformFromUrDevice(Device, Adapter) - .getOrMakeDeviceImpl(Device) - .shared_from_this(); + impl = &detail::platform_impl::getPlatformFromUrDevice(Device, Adapter) + .getOrMakeDeviceImpl(Device); __SYCL_OCL_CALL(clRetainDevice, DeviceId); } diff --git a/sycl/source/device_selector.cpp b/sycl/source/device_selector.cpp index 40b3f40f95eb8..f0ba21beb08bc 100644 --- a/sycl/source/device_selector.cpp +++ b/sycl/source/device_selector.cpp @@ -33,7 +33,7 @@ namespace detail { // itself, so only matching devices will be scored. static int getDevicePreference(const device &Device) { int Score = 0; - const device_impl &DeviceImpl = *getSyclObjImpl(Device).get(); + const device_impl &DeviceImpl = *getSyclObjImpl(Device); // Strongly prefer devices with available images. auto &program_manager = sycl::detail::ProgramManager::getInstance(); if (program_manager.hasCompatibleImage(DeviceImpl)) diff --git a/sycl/source/interop_handle.cpp b/sycl/source/interop_handle.cpp index 1796bf5f3a089..ccba78caa165d 100644 --- a/sycl/source/interop_handle.cpp +++ b/sycl/source/interop_handle.cpp @@ -40,12 +40,12 @@ interop_handle::getNativeMem(detail::Requirement *Req) const { detail::adapter_impl &Adapter = MQueue->getAdapter(); ur_native_handle_t Handle; Adapter.call( - Iter->second, MDevice->getHandleRef(), &Handle); + Iter->second, MDevice.getHandleRef(), &Handle); return Handle; } ur_native_handle_t interop_handle::getNativeDevice() const { - return MDevice->getNative(); + return MDevice.getNative(); } ur_native_handle_t interop_handle::getNativeContext() const { diff --git a/sycl/source/kernel_bundle.cpp b/sycl/source/kernel_bundle.cpp index 14d19ddacaa6b..edb42bcf8da60 100644 --- a/sycl/source/kernel_bundle.cpp +++ b/sycl/source/kernel_bundle.cpp @@ -379,7 +379,7 @@ std::vector get_kernel_ids() { } bool is_compatible(const std::vector &KernelIDs, const device &Dev) { - return detail::is_compatible(KernelIDs, *getSyclObjImpl(Dev)); + return detail::is_compatible(KernelIDs, *detail::getSyclObjImpl(Dev)); } ///////////////////////// diff --git a/sycl/source/physical_mem.cpp b/sycl/source/physical_mem.cpp index 9284927596592..67486c83df317 100644 --- a/sycl/source/physical_mem.cpp +++ b/sycl/source/physical_mem.cpp @@ -21,7 +21,7 @@ physical_mem::physical_mem(const device &SyclDevice, const context &SyclContext, "Device does not support aspect::ext_oneapi_virtual_mem."); impl = std::make_shared( - *getSyclObjImpl(SyclDevice), SyclContext, NumBytes); + *detail::getSyclObjImpl(SyclDevice), SyclContext, NumBytes); } void *physical_mem::map(uintptr_t Ptr, size_t NumBytes, diff --git a/sycl/test/abi/symbol_size_alignment.cpp b/sycl/test/abi/symbol_size_alignment.cpp index 5f0279580e657..a1514bd774f48 100644 --- a/sycl/test/abi/symbol_size_alignment.cpp +++ b/sycl/test/abi/symbol_size_alignment.cpp @@ -47,7 +47,7 @@ int main() { check, 40, 8>(); check(); check(); - check(); + check(); check(); check(); check(); diff --git a/sycl/test/gdb/printers.cpp b/sycl/test/gdb/printers.cpp index 7e7898207a82b..e6b5d3d76e400 100644 --- a/sycl/test/gdb/printers.cpp +++ b/sycl/test/gdb/printers.cpp @@ -44,8 +44,9 @@ sycl::item<2, false> item_wo_offset = // CHECK: 0 | size_t[1] common_array // CHECK: 0 | class sycl::device -// CHECK: 0 | class std::shared_ptr impl -// CHECK: 0 | element_type * _M_ptr +// CHECK: 0 | detail::device_impl * impl +// CHECK: | [sizeof=8, dsize=8, align=8, +// CHECK: | nvsize=8, nvalign=8] // CHECK: 0 | class sycl::queue // CHECK: 0 | class std::shared_ptr impl @@ -69,7 +70,7 @@ sycl::item<2, false> item_wo_offset = // CHECK: 32 | backend MBackend // CHECK: 0 | class sycl::detail::device_impl -// CHECK: 24 | platform_impl & MPlatform +// CHECK: 8 | platform_impl & MPlatform // DEVICE: 0 | class sycl::detail::AccessorImplDevice<1> // DEVICE: 0 | class sycl::id<> Offset diff --git a/sycl/unittests/Extensions/CommandGraph/Exceptions.cpp b/sycl/unittests/Extensions/CommandGraph/Exceptions.cpp index 1a635a751229c..af141a0bd0674 100644 --- a/sycl/unittests/Extensions/CommandGraph/Exceptions.cpp +++ b/sycl/unittests/Extensions/CommandGraph/Exceptions.cpp @@ -923,7 +923,6 @@ TEST_F(CommandGraphTest, DynamicCommandGroupMismatchAccessorEdges) { // correct exception behaviour. TEST_F(CommandGraphTest, AsyncAllocKindExceptionCheck) { auto Context = Queue.get_context(); - auto Device = Queue.get_device(); void *Ptr1 = nullptr; void *Ptr2 = nullptr; diff --git a/sycl/unittests/SYCL2020/KernelBundle.cpp b/sycl/unittests/SYCL2020/KernelBundle.cpp index 52074dbaabeb6..6a082c1232ccd 100644 --- a/sycl/unittests/SYCL2020/KernelBundle.cpp +++ b/sycl/unittests/SYCL2020/KernelBundle.cpp @@ -542,6 +542,6 @@ TEST(KernelBundle, HasKernelForSubDevice) { EXPECT_EQ(std::find(BundleDevs.begin(), BundleDevs.end(), SubDev), BundleDevs.end()) << "Sub-device should not be in the devices of the kernel bundle."; - EXPECT_FALSE(getSyclObjImpl(SubDev)->isRootDevice()); + EXPECT_FALSE(sycl::detail::getSyclObjImpl(SubDev)->isRootDevice()); EXPECT_TRUE(Bundle.has_kernel(KernelId, SubDev)); } diff --git a/sycl/unittests/kernel-and-program/PersistentDeviceCodeCache.cpp b/sycl/unittests/kernel-and-program/PersistentDeviceCodeCache.cpp index d760b3a748c16..3270cd963a727 100644 --- a/sycl/unittests/kernel-and-program/PersistentDeviceCodeCache.cpp +++ b/sycl/unittests/kernel-and-program/PersistentDeviceCodeCache.cpp @@ -224,7 +224,7 @@ class PersistentDeviceCodeCache std::to_string(ThreadCount)}; DeviceCodeID = ProgramID; std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath( - *getSyclObjImpl(Dev), {&Img}, + *detail::getSyclObjImpl(Dev), {&Img}, {'S', 'p', 'e', 'c', 'C', 'o', 'n', 's', 't', ProgramID}, BuildOptions); ASSERT_NO_ERROR(llvm::sys::fs::remove_directories(ItemDir)); @@ -286,7 +286,7 @@ TEST_P(PersistentDeviceCodeCache, KeysWithNullTermSymbol) { std::string Key{'1', '\0', '3', '4', '\0'}; std::vector SpecConst(Key.begin(), Key.end()); std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath( - *getSyclObjImpl(Dev), {&Img}, SpecConst, Key); + *detail::getSyclObjImpl(Dev), {&Img}, SpecConst, Key); ASSERT_NO_ERROR(llvm::sys::fs::remove_directories(ItemDir)); detail::PersistentDeviceCodeCache::putItemToDisc({Dev}, {&Img}, SpecConst, @@ -336,7 +336,7 @@ TEST_P(PersistentDeviceCodeCache, MultipleImages) { B->getRawData().EntriesBegin->GetName()) < 0; }); std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath( - *getSyclObjImpl(Dev), Imgs, {}, BuildOptions); + *detail::getSyclObjImpl(Dev), Imgs, {}, BuildOptions); ASSERT_NO_ERROR(llvm::sys::fs::remove_directories(ItemDir)); detail::PersistentDeviceCodeCache::putItemToDisc({Dev}, Imgs, {}, @@ -389,7 +389,7 @@ TEST_P(PersistentDeviceCodeCache, ConcurentReadWriteCacheBigItem) { TEST_P(PersistentDeviceCodeCache, CorruptedCacheFiles) { std::string BuildOptions{"--corrupted-file"}; std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath( - *getSyclObjImpl(Dev), {&Img}, {}, BuildOptions); + *detail::getSyclObjImpl(Dev), {&Img}, {}, BuildOptions); ASSERT_NO_ERROR(llvm::sys::fs::remove_directories(ItemDir)); // Only source file is present @@ -474,7 +474,7 @@ TEST_P(PersistentDeviceCodeCache, CorruptedCacheFiles) { TEST_P(PersistentDeviceCodeCache, LockFile) { std::string BuildOptions{"--obsolete-lock"}; std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath( - *getSyclObjImpl(Dev), {&Img}, {}, BuildOptions); + *detail::getSyclObjImpl(Dev), {&Img}, {}, BuildOptions); ASSERT_NO_ERROR(llvm::sys::fs::remove_directories(ItemDir)); // Create 1st cahe item @@ -524,7 +524,7 @@ TEST_P(PersistentDeviceCodeCache, LockFile) { TEST_P(PersistentDeviceCodeCache, AccessDeniedForCacheDir) { std::string BuildOptions{"--build-options"}; std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath( - *getSyclObjImpl(Dev), {&Img}, {}, BuildOptions); + *detail::getSyclObjImpl(Dev), {&Img}, {}, BuildOptions); ASSERT_NO_ERROR(llvm::sys::fs::remove_directories(ItemDir)); detail::PersistentDeviceCodeCache::putItemToDisc({Dev}, {&Img}, {}, BuildOptions, NativeProg); @@ -580,7 +580,7 @@ TEST_P(PersistentDeviceCodeCache, BasicEviction) { BuildOptions, NativeProg); std::string ItemDir = detail::PersistentDeviceCodeCache::getCacheItemPath( - *getSyclObjImpl(Dev), {&Img}, {}, BuildOptions); + *detail::getSyclObjImpl(Dev), {&Img}, {}, BuildOptions); size_t SizeOfOneEntry = (size_t)(detail::getDirectorySize(ItemDir)); detail::PersistentDeviceCodeCache::putItemToDisc({Dev}, {&Img}, {}, From 647947c95252a437a806442860da8c1603a7a0c1 Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Wed, 3 Dec 2025 15:19:11 -0800 Subject: [PATCH 2/3] Try to fix Win --- sycl/source/device.cpp | 4 ++++ sycl/test/abi/sycl_symbols_windows.dump | 7 +------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index cc68a356763e3..823f9da09eb09 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -17,6 +17,10 @@ #include #include +// Trying to force MSVC to generate the symbol/export for the inline function +// that it needs on the import (because the class itself is being exported): +#include + namespace sycl { inline namespace _V1 { namespace detail { diff --git a/sycl/test/abi/sycl_symbols_windows.dump b/sycl/test/abi/sycl_symbols_windows.dump index cac88ba890cfd..a644550e251b6 100644 --- a/sycl/test/abi/sycl_symbols_windows.dump +++ b/sycl/test/abi/sycl_symbols_windows.dump @@ -326,7 +326,7 @@ ??0default_selector@_V1@sycl@@QEAA@$$QEAV012@@Z ??0default_selector@_V1@sycl@@QEAA@AEBV012@@Z ??0default_selector@_V1@sycl@@QEAA@XZ -??0device@_V1@sycl@@AEAA@V?$shared_ptr@Vdevice_impl@detail@_V1@sycl@@@std@@@Z +??0device@_V1@sycl@@AEAA@AEAVdevice_impl@detail@12@@Z ??0device@_V1@sycl@@QEAA@$$QEAV012@@Z ??0device@_V1@sycl@@QEAA@AEBV012@@Z ??0device@_V1@sycl@@QEAA@AEBVdevice_selector@12@@Z @@ -490,7 +490,6 @@ ??1context@_V1@sycl@@QEAA@XZ ??1cpu_selector@_V1@sycl@@UEAA@XZ ??1default_selector@_V1@sycl@@UEAA@XZ -??1device@_V1@sycl@@QEAA@XZ ??1device_image_plain@detail@_V1@sycl@@QEAA@XZ ??1device_selector@_V1@sycl@@UEAA@XZ ??1dynamic_command_group@experimental@oneapi@ext@_V1@sycl@@QEAA@XZ @@ -523,8 +522,6 @@ ??1tls_code_loc_t@detail@_V1@sycl@@QEAA@XZ ??4?$OwnerLessBase@Vcontext@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z ??4?$OwnerLessBase@Vcontext@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z -??4?$OwnerLessBase@Vdevice@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z -??4?$OwnerLessBase@Vdevice@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z ??4?$OwnerLessBase@Vevent@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z ??4?$OwnerLessBase@Vevent@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z ??4?$OwnerLessBase@Vexecutable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z @@ -3938,8 +3935,6 @@ ?ext_oneapi_memset2d_impl@handler@_V1@sycl@@AEAAXPEAX_KH11@Z ?ext_oneapi_owner_before@?$OwnerLessBase@Vcontext@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBV?$weak_object_base@Vcontext@_V1@sycl@@@2oneapi@ext@34@@Z ?ext_oneapi_owner_before@?$OwnerLessBase@Vcontext@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVcontext@34@@Z -?ext_oneapi_owner_before@?$OwnerLessBase@Vdevice@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBV?$weak_object_base@Vdevice@_V1@sycl@@@2oneapi@ext@34@@Z -?ext_oneapi_owner_before@?$OwnerLessBase@Vdevice@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVdevice@34@@Z ?ext_oneapi_owner_before@?$OwnerLessBase@Vevent@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBV?$weak_object_base@Vevent@_V1@sycl@@@2oneapi@ext@34@@Z ?ext_oneapi_owner_before@?$OwnerLessBase@Vevent@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVevent@34@@Z ?ext_oneapi_owner_before@?$OwnerLessBase@Vexecutable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBV?$weak_object_base@Vexecutable_command_graph@detail@experimental@oneapi@ext@_V1@sycl@@@2oneapi@ext@34@@Z From f2abf715ddb9bad326997a9a533192440321a1be Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Thu, 4 Dec 2025 08:52:29 -0800 Subject: [PATCH 3/3] Update win symbols --- sycl/test/abi/sycl_symbols_windows.dump | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sycl/test/abi/sycl_symbols_windows.dump b/sycl/test/abi/sycl_symbols_windows.dump index a644550e251b6..6f92dcbe547d6 100644 --- a/sycl/test/abi/sycl_symbols_windows.dump +++ b/sycl/test/abi/sycl_symbols_windows.dump @@ -3953,6 +3953,8 @@ ?ext_oneapi_owner_before@?$OwnerLessBase@Vqueue@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVqueue@34@@Z ?ext_oneapi_owner_before@?$OwnerLessBase@Vstream@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBV?$weak_object_base@Vstream@_V1@sycl@@@2oneapi@ext@34@@Z ?ext_oneapi_owner_before@?$OwnerLessBase@Vstream@_V1@sycl@@@detail@_V1@sycl@@QEBA_NAEBVstream@34@@Z +?ext_oneapi_owner_before@device@_V1@sycl@@QEBA_NAEBV123@@Z +?ext_oneapi_owner_before@device@_V1@sycl@@QEBA_NAEBV?$weak_object@Vdevice@_V1@sycl@@@oneapi@ext@23@@Z ?ext_oneapi_prod@queue@_V1@sycl@@QEAAXXZ ?ext_oneapi_set_external_event@queue@_V1@sycl@@QEAAXAEBVevent@23@@Z ?ext_oneapi_signal_external_semaphore@handler@_V1@sycl@@QEAAXUexternal_semaphore@experimental@oneapi@ext@23@@Z