Skip to content

Commit d3aeb4a

Browse files
authored
[SYCL] Add caching when using interop constructor (#3327)
When interop constructor is used it creates new impl every time. This patch allows to use already created impls in the constructor. Signed-off-by: mdimakov <[email protected]>
1 parent dc82826 commit d3aeb4a

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

sycl/source/device.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ void force_type(info::device_type &t, const info::device_type &ft) {
3030

3131
device::device() : impl(detail::device_impl::getHostDeviceImpl()) {}
3232

33-
device::device(cl_device_id deviceId)
34-
: impl(std::make_shared<detail::device_impl>(
35-
detail::pi::cast<pi_native_handle>(deviceId),
36-
RT::getPlugin<backend::opencl>())) {
33+
device::device(cl_device_id DeviceId) {
3734
// The implementation constructor takes ownership of the native handle so we
3835
// must retain it in order to adhere to SYCL 1.2.1 spec (Rev6, section 4.3.1.)
39-
clRetainDevice(deviceId);
36+
detail::RT::PiDevice Device;
37+
auto Plugin = detail::RT::getPlugin<backend::opencl>();
38+
Plugin.call<detail::PiApiKind::piextDeviceCreateWithNativeHandle>(
39+
detail::pi::cast<pi_native_handle>(DeviceId), nullptr, &Device);
40+
auto Platform =
41+
detail::platform_impl::getPlatformFromPiDevice(Device, Plugin);
42+
impl = Platform->getOrMakeDeviceImpl(Device, Platform);
43+
clRetainDevice(DeviceId);
4044
}
4145

4246
device::device(const device_selector &deviceSelector) {

sycl/source/platform.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ namespace sycl {
1919

2020
platform::platform() : impl(detail::platform_impl::getHostPlatformImpl()) {}
2121

22-
platform::platform(cl_platform_id PlatformId)
23-
: impl(std::make_shared<detail::platform_impl>(
24-
detail::pi::cast<detail::RT::PiPlatform>(PlatformId),
25-
RT::getPlugin<backend::opencl>())) {}
22+
platform::platform(cl_platform_id PlatformId) {
23+
impl = detail::platform_impl::getOrMakePlatformImpl(
24+
detail::pi::cast<detail::RT::PiPlatform>(PlatformId),
25+
detail::RT::getPlugin<backend::opencl>());
26+
}
2627

2728
platform::platform(const device_selector &dev_selector) {
2829
*this = dev_selector.select_device().get_platform();

0 commit comments

Comments
 (0)