Skip to content

[NFCI][SYCL] Stop owning platform_impl from device_impl #19613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sycl/source/detail/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -143,7 +143,7 @@ std::vector<device> 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<device>(
MPlatform->getOrMakeDeviceImpl(a_ur_device));
MPlatform.getOrMakeDeviceImpl(a_ur_device));
res.push_back(sycl_device);
});
return res;
Expand Down
14 changes: 7 additions & 7 deletions sycl/source/detail/device_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
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
///
Expand Down Expand Up @@ -832,7 +832,7 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
// 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<info::platform::name>();
std::string platform_name = MPlatform.get_info<info::platform::name>();
if (platform_name == "Intel(R) FPGA Emulation Platform for OpenCL(TM)" ||
platform_name == "Intel(R) FPGA SDK for OpenCL(TM)")
return true;
Expand Down Expand Up @@ -1017,7 +1017,7 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
Result.reserve(Devs.value().size());
for (const auto &d : Devs.value())
Result.push_back(
createSyclObjFromImpl<device>(MPlatform->getOrMakeDeviceImpl(d)));
createSyclObjFromImpl<device>(MPlatform.getOrMakeDeviceImpl(d)));

return Result;
}
Expand All @@ -1031,7 +1031,7 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
if (ur_device_handle_t Result =
get_info_impl<UR_DEVICE_INFO_COMPOSITE_DEVICE>())
return createSyclObjFromImpl<device>(
MPlatform->getOrMakeDeviceImpl(Result));
MPlatform.getOrMakeDeviceImpl(Result));

throw sycl::exception(make_error_code(errc::invalid),
"A component with aspect::ext_oneapi_is_component "
Expand Down Expand Up @@ -1702,10 +1702,10 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
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 <ur_device_info_t Desc>
std::vector<info::fp_config> get_fp_config() const {
Expand Down Expand Up @@ -2254,7 +2254,7 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
private:
ur_device_handle_t MDevice = 0;
// This is used for getAdapter so should be above other properties.
std::shared_ptr<platform_impl> MPlatform;
platform_impl &MPlatform;

std::shared_mutex MDeviceHostBaseTimeMutex;
std::pair<uint64_t, uint64_t> MDeviceHostBaseTime{0, 0};
Expand Down
9 changes: 0 additions & 9 deletions sycl/source/detail/global_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,6 @@ std::vector<std::shared_ptr<platform_impl>> &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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions sycl/source/detail/global_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ class GlobalHandler {
Sync &getSync();
std::vector<std::shared_ptr<platform_impl>> &getPlatformCache();

void clearPlatforms();

std::unordered_map<platform_impl *, std::shared_ptr<context_impl>> &
getPlatformToDefaultContextCache();

Expand Down
3 changes: 1 addition & 2 deletions sycl/test/gdb/printers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<class sycl::detail::platform_impl> 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
Expand Down
2 changes: 1 addition & 1 deletion sycl/unittests/helpers/UrMock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ template <sycl::backend Backend = backend::opencl> 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();
}

Expand Down