diff --git a/sycl/source/device.cpp b/sycl/source/device.cpp index 57ca9f6190615..4bdb2d9a1a154 100644 --- a/sycl/source/device.cpp +++ b/sycl/source/device.cpp @@ -29,13 +29,17 @@ void force_type(info::device_type &t, const info::device_type &ft) { device::device() : impl(detail::device_impl::getHostDeviceImpl()) {} -device::device(cl_device_id deviceId) - : impl(std::make_shared( - detail::pi::cast(deviceId), - RT::getPlugin())) { +device::device(cl_device_id DeviceId) { // The implementation constructor takes ownership of the native handle so we // must retain it in order to adhere to SYCL 1.2.1 spec (Rev6, section 4.3.1.) - clRetainDevice(deviceId); + detail::RT::PiDevice Device; + auto Plugin = detail::RT::getPlugin(); + Plugin.call( + detail::pi::cast(DeviceId), nullptr, &Device); + auto Platform = + detail::platform_impl::getPlatformFromPiDevice(Device, Plugin); + impl = Platform->getOrMakeDeviceImpl(Device, Platform); + clRetainDevice(DeviceId); } device::device(const device_selector &deviceSelector) { diff --git a/sycl/source/platform.cpp b/sycl/source/platform.cpp index 3ab9f5b020d6d..bcda122e345a0 100644 --- a/sycl/source/platform.cpp +++ b/sycl/source/platform.cpp @@ -18,10 +18,11 @@ namespace sycl { platform::platform() : impl(detail::platform_impl::getHostPlatformImpl()) {} -platform::platform(cl_platform_id PlatformId) - : impl(std::make_shared( - detail::pi::cast(PlatformId), - RT::getPlugin())) {} +platform::platform(cl_platform_id PlatformId) { + impl = detail::platform_impl::getOrMakePlatformImpl( + detail::pi::cast(PlatformId), + detail::RT::getPlugin()); +} platform::platform(const device_selector &dev_selector) { *this = dev_selector.select_device().get_platform();