Skip to content

Commit 34a5b8e

Browse files
[NFCI][SYCL] Stop owning platform_impl from device_impl (#19613)
Refactoring has started in #18143 #18251 but this final step wasn't performed before due to some unittests failing. Seems not to be the case anymore.
1 parent 00d49b9 commit 34a5b8e

File tree

6 files changed

+11
-23
lines changed

6 files changed

+11
-23
lines changed

sycl/source/detail/device_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace detail {
2323
/// UR device instance.
2424
device_impl::device_impl(ur_device_handle_t Device, platform_impl &Platform,
2525
device_impl::private_tag)
26-
: MDevice(Device), MPlatform(Platform.shared_from_this()),
26+
: MDevice(Device), MPlatform(Platform),
2727
// No need to set MRootDevice when MAlwaysRootDevice is true
2828
MRootDevice(Platform.MAlwaysRootDevice
2929
? nullptr
@@ -143,7 +143,7 @@ std::vector<device> device_impl::create_sub_devices(
143143
std::for_each(SubDevices.begin(), SubDevices.end(),
144144
[&res, this](const ur_device_handle_t &a_ur_device) {
145145
device sycl_device = detail::createSyclObjFromImpl<device>(
146-
MPlatform->getOrMakeDeviceImpl(a_ur_device));
146+
MPlatform.getOrMakeDeviceImpl(a_ur_device));
147147
res.push_back(sycl_device);
148148
});
149149
return res;

sycl/source/detail/device_impl.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
467467
platform get_platform() const;
468468

469469
/// \return the associated adapter with this device.
470-
adapter_impl &getAdapter() const { return MPlatform->getAdapter(); }
470+
adapter_impl &getAdapter() const { return MPlatform.getAdapter(); }
471471

472472
/// Check SYCL extension support by device
473473
///
@@ -832,7 +832,7 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
832832
// We claim, that all Intel FPGA devices support kernel to kernel pipe
833833
// feature (at least at the scope of SYCL_INTEL_data_flow_pipes
834834
// extension).
835-
std::string platform_name = MPlatform->get_info<info::platform::name>();
835+
std::string platform_name = MPlatform.get_info<info::platform::name>();
836836
if (platform_name == "Intel(R) FPGA Emulation Platform for OpenCL(TM)" ||
837837
platform_name == "Intel(R) FPGA SDK for OpenCL(TM)")
838838
return true;
@@ -1017,7 +1017,7 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
10171017
Result.reserve(Devs.value().size());
10181018
for (const auto &d : Devs.value())
10191019
Result.push_back(
1020-
createSyclObjFromImpl<device>(MPlatform->getOrMakeDeviceImpl(d)));
1020+
createSyclObjFromImpl<device>(MPlatform.getOrMakeDeviceImpl(d)));
10211021

10221022
return Result;
10231023
}
@@ -1031,7 +1031,7 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
10311031
if (ur_device_handle_t Result =
10321032
get_info_impl<UR_DEVICE_INFO_COMPOSITE_DEVICE>())
10331033
return createSyclObjFromImpl<device>(
1034-
MPlatform->getOrMakeDeviceImpl(Result));
1034+
MPlatform.getOrMakeDeviceImpl(Result));
10351035

10361036
throw sycl::exception(make_error_code(errc::invalid),
10371037
"A component with aspect::ext_oneapi_is_component "
@@ -1702,10 +1702,10 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
17021702
uint64_t getCurrentDeviceTime();
17031703

17041704
/// Get the backend of this device
1705-
backend getBackend() const { return MPlatform->getBackend(); }
1705+
backend getBackend() const { return MPlatform.getBackend(); }
17061706

17071707
/// @brief Get the platform impl serving this device
1708-
platform_impl &getPlatformImpl() const { return *MPlatform; }
1708+
platform_impl &getPlatformImpl() const { return MPlatform; }
17091709

17101710
template <ur_device_info_t Desc>
17111711
std::vector<info::fp_config> get_fp_config() const {
@@ -2254,7 +2254,7 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
22542254
private:
22552255
ur_device_handle_t MDevice = 0;
22562256
// This is used for getAdapter so should be above other properties.
2257-
std::shared_ptr<platform_impl> MPlatform;
2257+
platform_impl &MPlatform;
22582258

22592259
std::shared_mutex MDeviceHostBaseTimeMutex;
22602260
std::pair<uint64_t, uint64_t> MDeviceHostBaseTime{0, 0};

sycl/source/detail/global_handler.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,6 @@ std::vector<std::shared_ptr<platform_impl>> &GlobalHandler::getPlatformCache() {
216216
return PlatformCache;
217217
}
218218

219-
void GlobalHandler::clearPlatforms() {
220-
if (!MPlatformCache.Inst)
221-
return;
222-
for (auto &PltSmartPtr : *MPlatformCache.Inst)
223-
PltSmartPtr->MDevices.clear();
224-
MPlatformCache.Inst->clear();
225-
}
226-
227219
std::mutex &GlobalHandler::getPlatformMapMutex() {
228220
static std::mutex &PlatformMapMutex = getOrCreate(MPlatformMapMutex);
229221
return PlatformMapMutex;
@@ -392,7 +384,6 @@ void shutdown_late() {
392384
#endif
393385

394386
// First, release resources, that may access adapters.
395-
Handler->clearPlatforms(); // includes dropping platforms' devices ownership.
396387
Handler->MPlatformCache.Inst.reset(nullptr);
397388
Handler->MScheduler.Inst.reset(nullptr);
398389
Handler->MProgramManager.Inst.reset(nullptr);

sycl/source/detail/global_handler.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ class GlobalHandler {
6363
Sync &getSync();
6464
std::vector<std::shared_ptr<platform_impl>> &getPlatformCache();
6565

66-
void clearPlatforms();
67-
6866
std::unordered_map<platform_impl *, std::shared_ptr<context_impl>> &
6967
getPlatformToDefaultContextCache();
7068

sycl/test/gdb/printers.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ sycl::range<1> r(3);
6363
// CHECK: 32 | backend MBackend
6464

6565
// CHECK: 0 | class sycl::detail::device_impl
66-
// CHECK: 24 | class std::shared_ptr<class sycl::detail::platform_impl> MPlatform
67-
// CHECK: 24 | element_type * _M_ptr
66+
// CHECK: 24 | platform_impl & MPlatform
6867

6968
// DEVICE: 0 | class sycl::detail::AccessorImplDevice<1>
7069
// DEVICE: 0 | class sycl::id<1> Offset

sycl/unittests/helpers/UrMock.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ template <sycl::backend Backend = backend::opencl> class UrMock {
613613
// This also erases each platform's devices (normally done in the library
614614
// shutdown) so that platforms/devices' lifetimes could work in unittests
615615
// scenario.
616-
detail::GlobalHandler::instance().clearPlatforms();
616+
detail::GlobalHandler::instance().getPlatformCache().clear();
617617
mock::getCallbacks().resetCallbacks();
618618
}
619619

0 commit comments

Comments
 (0)