diff --git a/sycl/source/detail/device_impl.cpp b/sycl/source/detail/device_impl.cpp index 708b4a5c3e2ac..67a5c917ab7aa 100644 --- a/sycl/source/detail/device_impl.cpp +++ b/sycl/source/detail/device_impl.cpp @@ -23,7 +23,7 @@ namespace detail { /// UR device instance. device_impl::device_impl(ur_device_handle_t Device, platform_impl &Platform, device_impl::private_tag) - : MDevice(Device), MPlatform(Platform.shared_from_this()), + : MDevice(Device), MPlatform(Platform), // No need to set MRootDevice when MAlwaysRootDevice is true MRootDevice(Platform.MAlwaysRootDevice ? nullptr @@ -143,7 +143,7 @@ std::vector device_impl::create_sub_devices( std::for_each(SubDevices.begin(), SubDevices.end(), [&res, this](const ur_device_handle_t &a_ur_device) { device sycl_device = detail::createSyclObjFromImpl( - MPlatform->getOrMakeDeviceImpl(a_ur_device)); + MPlatform.getOrMakeDeviceImpl(a_ur_device)); res.push_back(sycl_device); }); return res; diff --git a/sycl/source/detail/device_impl.hpp b/sycl/source/detail/device_impl.hpp index 022a187ed409c..a9f39635aa04f 100644 --- a/sycl/source/detail/device_impl.hpp +++ b/sycl/source/detail/device_impl.hpp @@ -467,7 +467,7 @@ class device_impl : public std::enable_shared_from_this { platform get_platform() const; /// \return the associated adapter with this device. - adapter_impl &getAdapter() const { return MPlatform->getAdapter(); } + adapter_impl &getAdapter() const { return MPlatform.getAdapter(); } /// Check SYCL extension support by device /// @@ -832,7 +832,7 @@ class device_impl : public std::enable_shared_from_this { // We claim, that all Intel FPGA devices support kernel to kernel pipe // feature (at least at the scope of SYCL_INTEL_data_flow_pipes // extension). - std::string platform_name = MPlatform->get_info(); + std::string platform_name = MPlatform.get_info(); if (platform_name == "Intel(R) FPGA Emulation Platform for OpenCL(TM)" || platform_name == "Intel(R) FPGA SDK for OpenCL(TM)") return true; @@ -1017,7 +1017,7 @@ class device_impl : public std::enable_shared_from_this { Result.reserve(Devs.value().size()); for (const auto &d : Devs.value()) Result.push_back( - createSyclObjFromImpl(MPlatform->getOrMakeDeviceImpl(d))); + createSyclObjFromImpl(MPlatform.getOrMakeDeviceImpl(d))); return Result; } @@ -1031,7 +1031,7 @@ class device_impl : public std::enable_shared_from_this { if (ur_device_handle_t Result = get_info_impl()) return createSyclObjFromImpl( - MPlatform->getOrMakeDeviceImpl(Result)); + MPlatform.getOrMakeDeviceImpl(Result)); throw sycl::exception(make_error_code(errc::invalid), "A component with aspect::ext_oneapi_is_component " @@ -1702,10 +1702,10 @@ class device_impl : public std::enable_shared_from_this { uint64_t getCurrentDeviceTime(); /// Get the backend of this device - backend getBackend() const { return MPlatform->getBackend(); } + backend getBackend() const { return MPlatform.getBackend(); } /// @brief Get the platform impl serving this device - platform_impl &getPlatformImpl() const { return *MPlatform; } + platform_impl &getPlatformImpl() const { return MPlatform; } template std::vector get_fp_config() const { @@ -2254,7 +2254,7 @@ class device_impl : public std::enable_shared_from_this { private: ur_device_handle_t MDevice = 0; // This is used for getAdapter so should be above other properties. - std::shared_ptr MPlatform; + platform_impl &MPlatform; std::shared_mutex MDeviceHostBaseTimeMutex; std::pair MDeviceHostBaseTime{0, 0}; diff --git a/sycl/source/detail/global_handler.cpp b/sycl/source/detail/global_handler.cpp index 8392aeed3a230..ff89080ad19eb 100644 --- a/sycl/source/detail/global_handler.cpp +++ b/sycl/source/detail/global_handler.cpp @@ -216,14 +216,6 @@ std::vector> &GlobalHandler::getPlatformCache() { return PlatformCache; } -void GlobalHandler::clearPlatforms() { - if (!MPlatformCache.Inst) - return; - for (auto &PltSmartPtr : *MPlatformCache.Inst) - PltSmartPtr->MDevices.clear(); - MPlatformCache.Inst->clear(); -} - std::mutex &GlobalHandler::getPlatformMapMutex() { static std::mutex &PlatformMapMutex = getOrCreate(MPlatformMapMutex); return PlatformMapMutex; @@ -392,7 +384,6 @@ void shutdown_late() { #endif // First, release resources, that may access adapters. - Handler->clearPlatforms(); // includes dropping platforms' devices ownership. Handler->MPlatformCache.Inst.reset(nullptr); Handler->MScheduler.Inst.reset(nullptr); Handler->MProgramManager.Inst.reset(nullptr); diff --git a/sycl/source/detail/global_handler.hpp b/sycl/source/detail/global_handler.hpp index 125dd39b742db..5be68ef065720 100644 --- a/sycl/source/detail/global_handler.hpp +++ b/sycl/source/detail/global_handler.hpp @@ -63,8 +63,6 @@ class GlobalHandler { Sync &getSync(); std::vector> &getPlatformCache(); - void clearPlatforms(); - std::unordered_map> & getPlatformToDefaultContextCache(); diff --git a/sycl/test/gdb/printers.cpp b/sycl/test/gdb/printers.cpp index c6740f5ff19d5..91c1457b93c7f 100644 --- a/sycl/test/gdb/printers.cpp +++ b/sycl/test/gdb/printers.cpp @@ -63,8 +63,7 @@ sycl::range<1> r(3); // CHECK: 32 | backend MBackend // CHECK: 0 | class sycl::detail::device_impl -// CHECK: 24 | class std::shared_ptr MPlatform -// CHECK: 24 | element_type * _M_ptr +// CHECK: 24 | platform_impl & MPlatform // DEVICE: 0 | class sycl::detail::AccessorImplDevice<1> // DEVICE: 0 | class sycl::id<1> Offset diff --git a/sycl/unittests/helpers/UrMock.hpp b/sycl/unittests/helpers/UrMock.hpp index df44d5ea56a76..697df02bceb53 100644 --- a/sycl/unittests/helpers/UrMock.hpp +++ b/sycl/unittests/helpers/UrMock.hpp @@ -613,7 +613,7 @@ template class UrMock { // This also erases each platform's devices (normally done in the library // shutdown) so that platforms/devices' lifetimes could work in unittests // scenario. - detail::GlobalHandler::instance().clearPlatforms(); + detail::GlobalHandler::instance().getPlatformCache().clear(); mock::getCallbacks().resetCallbacks(); }