Skip to content

Commit 0b59341

Browse files
[SYCL] Remove deprecated interop interfaces (#13306)
1 parent 94f6b2f commit 0b59341

File tree

12 files changed

+79
-309
lines changed

12 files changed

+79
-309
lines changed

sycl/include/sycl/backend.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ __SYCL_EXPORT device make_device(pi_native_handle NativeHandle,
263263
backend Backend);
264264
__SYCL_EXPORT context make_context(pi_native_handle NativeHandle,
265265
const async_handler &Handler,
266-
backend Backend);
266+
backend Backend, bool KeepOwnership,
267+
const std::vector<device> &DeviceList = {});
267268
__SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle,
268269
int32_t nativeHandleDesc,
269270
const context &TargetContext,
@@ -328,7 +329,7 @@ make_context(
328329
&BackendObject,
329330
const async_handler &Handler = {}) {
330331
return detail::make_context(detail::pi::cast<pi_native_handle>(BackendObject),
331-
Handler, Backend);
332+
Handler, Backend, false /* KeepOwnership */);
332333
}
333334

334335
template <backend Backend>

sycl/include/sycl/backend/opencl.hpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,54 +24,10 @@
2424
namespace sycl {
2525
inline namespace _V1 {
2626
namespace opencl {
27-
// Implementation of various "make" functions resides in SYCL RT because
28-
// creating SYCL objects requires knowing details not accessible here.
29-
// Note that they take opaque pi_native_handle that real OpenCL handles
30-
// are casted to.
31-
//
32-
__SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle);
33-
__SYCL_EXPORT device make_device(pi_native_handle NativeHandle);
34-
__SYCL_EXPORT context make_context(pi_native_handle NativeHandle);
35-
__SYCL_EXPORT queue make_queue(const context &Context,
36-
pi_native_handle InteropHandle);
37-
3827
__SYCL_EXPORT bool has_extension(const sycl::platform &SyclPlatform,
3928
const std::string &Extension);
4029
__SYCL_EXPORT bool has_extension(const sycl::device &SyclDevice,
4130
const std::string &Extension);
42-
43-
// Construction of SYCL platform.
44-
template <typename T,
45-
typename std::enable_if_t<std::is_same_v<T, platform>> * = nullptr>
46-
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_platform free function")
47-
T make(typename detail::interop<backend::opencl, T>::type Interop) {
48-
return make_platform(detail::pi::cast<pi_native_handle>(Interop));
49-
}
50-
51-
// Construction of SYCL device.
52-
template <typename T,
53-
typename std::enable_if_t<std::is_same_v<T, device>> * = nullptr>
54-
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_device free function")
55-
T make(typename detail::interop<backend::opencl, T>::type Interop) {
56-
return make_device(detail::pi::cast<pi_native_handle>(Interop));
57-
}
58-
59-
// Construction of SYCL context.
60-
template <typename T,
61-
typename std::enable_if_t<std::is_same_v<T, context>> * = nullptr>
62-
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_context free function")
63-
T make(typename detail::interop<backend::opencl, T>::type Interop) {
64-
return make_context(detail::pi::cast<pi_native_handle>(Interop));
65-
}
66-
67-
// Construction of SYCL queue.
68-
template <typename T,
69-
typename std::enable_if_t<std::is_same_v<T, queue>> * = nullptr>
70-
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_queue free function")
71-
T make(const context &Context,
72-
typename detail::interop<backend::opencl, T>::type Interop) {
73-
return make_queue(Context, detail::pi::cast<pi_native_handle>(Interop));
74-
}
7531
} // namespace opencl
7632
} // namespace _V1
7733
} // namespace sycl

sycl/include/sycl/ext/oneapi/backend/level_zero.hpp

Lines changed: 20 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -41,88 +41,27 @@
4141

4242
namespace sycl {
4343
inline namespace _V1 {
44-
namespace ext::oneapi::level_zero {
45-
// Implementation of various "make" functions resides in libsycl.so and thus
46-
// their interface needs to be backend agnostic.
47-
// TODO: remove/merge with similar functions in sycl::detail
48-
__SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle);
44+
namespace ext::oneapi::level_zero::detail {
4945
__SYCL_EXPORT device make_device(const platform &Platform,
5046
pi_native_handle NativeHandle);
51-
__SYCL_EXPORT context make_context(const std::vector<device> &DeviceList,
52-
pi_native_handle NativeHandle,
53-
bool keep_ownership = false);
54-
__SYCL_EXPORT queue make_queue(const context &Context, const device &Device,
55-
pi_native_handle InteropHandle,
56-
bool IsImmCmdList, bool keep_ownership,
57-
const property_list &Properties);
58-
__SYCL_EXPORT event make_event(const context &Context,
59-
pi_native_handle InteropHandle,
60-
bool keep_ownership = false);
61-
62-
// Construction of SYCL platform.
63-
template <typename T,
64-
typename std::enable_if_t<std::is_same_v<T, platform>> * = nullptr>
65-
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_platform free function")
66-
T make(typename sycl::detail::interop<backend::ext_oneapi_level_zero, T>::type
67-
Interop) {
68-
return make_platform(reinterpret_cast<pi_native_handle>(Interop));
69-
}
70-
71-
// Construction of SYCL device.
72-
template <typename T,
73-
typename std::enable_if_t<std::is_same_v<T, device>> * = nullptr>
74-
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_device free function")
75-
T make(const platform &Platform,
76-
typename sycl::detail::interop<backend::ext_oneapi_level_zero, T>::type
77-
Interop) {
78-
return make_device(Platform, reinterpret_cast<pi_native_handle>(Interop));
79-
}
80-
81-
/// Construction of SYCL context.
82-
/// \param DeviceList is a vector of devices which must be encapsulated by
83-
/// created SYCL context. Provided devices and native context handle must
84-
/// be associated with the same platform.
85-
/// \param Interop is a Level Zero native context handle.
86-
/// \param Ownership (optional) specifies who will assume ownership of the
87-
/// native context handle. Default is that SYCL RT does, so it destroys
88-
/// the native handle when the created SYCL object goes out of life.
89-
///
90-
template <typename T, std::enable_if_t<std::is_same_v<T, context>> * = nullptr>
91-
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_context free function")
92-
T make(const std::vector<device> &DeviceList,
93-
typename sycl::detail::interop<backend::ext_oneapi_level_zero, T>::type
94-
Interop,
95-
ownership Ownership = ownership::transfer) {
96-
return make_context(DeviceList,
97-
sycl::detail::pi::cast<pi_native_handle>(Interop),
98-
Ownership == ownership::keep);
99-
}
100-
101-
// Construction of SYCL event.
102-
template <typename T,
103-
typename std::enable_if_t<std::is_same_v<T, event>> * = nullptr>
104-
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_event free function")
105-
T make(const context &Context,
106-
typename sycl::detail::interop<backend::ext_oneapi_level_zero, T>::type
107-
Interop,
108-
ownership Ownership = ownership::transfer) {
109-
return make_event(Context, reinterpret_cast<pi_native_handle>(Interop),
110-
Ownership == ownership::keep);
111-
}
112-
113-
} // namespace ext::oneapi::level_zero
47+
} // namespace ext::oneapi::level_zero::detail
11448

11549
// Specialization of sycl::make_context for Level-Zero backend.
11650
template <>
11751
inline context make_context<backend::ext_oneapi_level_zero>(
11852
const backend_input_t<backend::ext_oneapi_level_zero, context>
11953
&BackendObject,
12054
const async_handler &Handler) {
121-
(void)Handler;
122-
return ext::oneapi::level_zero::make_context(
123-
BackendObject.DeviceList,
124-
detail::pi::cast<pi_native_handle>(BackendObject.NativeHandle),
125-
BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep);
55+
56+
const std::vector<device> &DeviceList = BackendObject.DeviceList;
57+
pi_native_handle NativeHandle =
58+
detail::pi::cast<pi_native_handle>(BackendObject.NativeHandle);
59+
bool KeepOwnership =
60+
BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep;
61+
62+
return sycl::detail::make_context(NativeHandle, Handler,
63+
backend::ext_oneapi_level_zero,
64+
KeepOwnership, DeviceList);
12665
}
12766

12867
namespace detail {
@@ -191,7 +130,6 @@ template <>
191130
inline queue make_queue<backend::ext_oneapi_level_zero>(
192131
const backend_input_t<backend::ext_oneapi_level_zero, queue> &BackendObject,
193132
const context &TargetContext, const async_handler Handler) {
194-
(void)Handler;
195133
const device Device = device{BackendObject.Device};
196134
bool IsImmCmdList = std::holds_alternative<ze_command_list_handle_t>(
197135
BackendObject.NativeHandle);
@@ -202,10 +140,11 @@ inline queue make_queue<backend::ext_oneapi_level_zero>(
202140
: reinterpret_cast<pi_native_handle>(
203141
*(std::get_if<ze_command_queue_handle_t>(
204142
&BackendObject.NativeHandle)));
205-
return ext::oneapi::level_zero::make_queue(
206-
TargetContext, Device, Handle, IsImmCmdList,
143+
144+
return sycl::detail::make_queue(
145+
Handle, IsImmCmdList, TargetContext, &Device,
207146
BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep,
208-
BackendObject.Properties);
147+
BackendObject.Properties, Handler, backend::ext_oneapi_level_zero);
209148
}
210149

211150
// Specialization of sycl::get_native for Level-Zero backend.
@@ -227,10 +166,11 @@ template <>
227166
inline event make_event<backend::ext_oneapi_level_zero>(
228167
const backend_input_t<backend::ext_oneapi_level_zero, event> &BackendObject,
229168
const context &TargetContext) {
230-
return ext::oneapi::level_zero::make_event(
231-
TargetContext,
169+
return sycl::detail::make_event(
232170
detail::pi::cast<pi_native_handle>(BackendObject.NativeHandle),
233-
BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep);
171+
TargetContext,
172+
BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep,
173+
backend::ext_oneapi_level_zero);
234174
}
235175

236176
// Specialization of sycl::make_kernel_bundle for Level-Zero backend.

sycl/source/backend.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,21 @@ __SYCL_EXPORT device make_device(pi_native_handle NativeHandle,
9191

9292
__SYCL_EXPORT context make_context(pi_native_handle NativeHandle,
9393
const async_handler &Handler,
94-
backend Backend) {
94+
backend Backend, bool KeepOwnership,
95+
const std::vector<device> &DeviceList) {
9596
const auto &Plugin = getPlugin(Backend);
9697

9798
pi::PiContext PiContext = nullptr;
99+
std::vector<pi_device> DeviceHandles;
100+
for (auto Dev : DeviceList) {
101+
DeviceHandles.push_back(detail::getSyclObjImpl(Dev)->getHandleRef());
102+
}
98103
Plugin->call<PiApiKind::piextContextCreateWithNativeHandle>(
99-
NativeHandle, 0, nullptr, false, &PiContext);
104+
NativeHandle, DeviceHandles.size(), DeviceHandles.data(), false,
105+
&PiContext);
100106
// Construct the SYCL context from PI context.
101-
return detail::createSyclObjFromImpl<context>(
102-
std::make_shared<context_impl>(PiContext, Handler, Plugin));
107+
return detail::createSyclObjFromImpl<context>(std::make_shared<context_impl>(
108+
PiContext, Handler, Plugin, DeviceList, !KeepOwnership));
103109
}
104110

105111
__SYCL_EXPORT queue make_queue(pi_native_handle NativeHandle,

sycl/source/backend/level_zero.cpp

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,9 @@
1515

1616
namespace sycl {
1717
inline namespace _V1 {
18-
namespace ext::oneapi::level_zero {
19-
using namespace detail;
18+
namespace ext::oneapi::level_zero::detail {
19+
using namespace sycl::detail;
2020

21-
//----------------------------------------------------------------------------
22-
// Implementation of level_zero::make<platform>
23-
__SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle) {
24-
return detail::make_platform(NativeHandle, backend::ext_oneapi_level_zero);
25-
}
26-
27-
//----------------------------------------------------------------------------
28-
// Implementation of level_zero::make<device>
2921
__SYCL_EXPORT device make_device(const platform &Platform,
3022
pi_native_handle NativeHandle) {
3123
const auto &Plugin = pi::getPlugin<backend::ext_oneapi_level_zero>();
@@ -39,48 +31,6 @@ __SYCL_EXPORT device make_device(const platform &Platform,
3931
PlatformImpl->getOrMakeDeviceImpl(PiDevice, PlatformImpl));
4032
}
4133

42-
//----------------------------------------------------------------------------
43-
// Implementation of level_zero::make<context>
44-
__SYCL_EXPORT context make_context(const std::vector<device> &DeviceList,
45-
pi_native_handle NativeHandle,
46-
bool KeepOwnership) {
47-
const auto &Plugin = pi::getPlugin<backend::ext_oneapi_level_zero>();
48-
// Create PI context first.
49-
pi_context PiContext;
50-
std::vector<pi_device> DeviceHandles;
51-
for (auto Dev : DeviceList) {
52-
DeviceHandles.push_back(detail::getSyclObjImpl(Dev)->getHandleRef());
53-
}
54-
Plugin->call<PiApiKind::piextContextCreateWithNativeHandle>(
55-
NativeHandle, DeviceHandles.size(), DeviceHandles.data(), !KeepOwnership,
56-
&PiContext);
57-
// Construct the SYCL context from PI context.
58-
return detail::createSyclObjFromImpl<context>(
59-
std::make_shared<context_impl>(PiContext, detail::defaultAsyncHandler,
60-
Plugin, DeviceList, !KeepOwnership));
61-
}
62-
63-
//----------------------------------------------------------------------------
64-
// Implementation of level_zero::make<queue>
65-
__SYCL_EXPORT queue make_queue(const context &Context, const device &Device,
66-
pi_native_handle NativeHandle, bool IsImmCmdList,
67-
bool KeepOwnership,
68-
const property_list &Properties) {
69-
const auto &ContextImpl = getSyclObjImpl(Context);
70-
return detail::make_queue(
71-
NativeHandle, IsImmCmdList, Context, &Device, KeepOwnership, Properties,
72-
ContextImpl->get_async_handler(), backend::ext_oneapi_level_zero);
73-
}
74-
75-
//----------------------------------------------------------------------------
76-
// Implementation of level_zero::make<event>
77-
__SYCL_EXPORT event make_event(const context &Context,
78-
pi_native_handle NativeHandle,
79-
bool KeepOwnership) {
80-
return detail::make_event(NativeHandle, Context, KeepOwnership,
81-
backend::ext_oneapi_level_zero);
82-
}
83-
84-
} // namespace ext::oneapi::level_zero
34+
} // namespace ext::oneapi::level_zero::detail
8535
} // namespace _V1
8636
} // namespace sycl

sycl/source/backend/opencl.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,6 @@ inline namespace _V1 {
2121
namespace opencl {
2222
using namespace detail;
2323

24-
//----------------------------------------------------------------------------
25-
// Implementation of opencl::make<platform>
26-
__SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle) {
27-
return detail::make_platform(NativeHandle, backend::opencl);
28-
}
29-
30-
//----------------------------------------------------------------------------
31-
// Implementation of opencl::make<device>
32-
__SYCL_EXPORT device make_device(pi_native_handle NativeHandle) {
33-
return detail::make_device(NativeHandle, backend::opencl);
34-
}
35-
36-
//----------------------------------------------------------------------------
37-
// Implementation of opencl::make<context>
38-
__SYCL_EXPORT context make_context(pi_native_handle NativeHandle) {
39-
return detail::make_context(NativeHandle, detail::defaultAsyncHandler,
40-
backend::opencl);
41-
}
42-
43-
//----------------------------------------------------------------------------
44-
// Implementation of opencl::make<queue>
45-
__SYCL_EXPORT queue make_queue(const context &Context,
46-
pi_native_handle NativeHandle) {
47-
const auto &ContextImpl = getSyclObjImpl(Context);
48-
return detail::make_queue(NativeHandle, 0, Context, nullptr, false, {},
49-
ContextImpl->get_async_handler(), backend::opencl);
50-
}
51-
5224
//----------------------------------------------------------------------------
5325
// Free functions to query OpenCL backend extensions
5426
__SYCL_EXPORT bool has_extension(const sycl::platform &SyclPlatform,

sycl/test-e2e/Plugin/interop-level-zero-keep-ownership.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ int main() {
3030
{ // Scope in which SYCL interop context object is live
3131
std::vector<device> Devices{};
3232
Devices.push_back(Device);
33-
auto Context = level_zero::make<context>(Devices, ZeContext,
34-
level_zero::ownership::keep);
33+
auto Context = make_context<backend::ext_oneapi_level_zero>(
34+
backend_input_t<backend::ext_oneapi_level_zero, context>{
35+
ZeContext, Devices, ext::oneapi::level_zero::ownership::keep});
3536

3637
// Create L0 event pool
3738
ze_event_pool_handle_t ZeEventPool;
@@ -52,8 +53,10 @@ int main() {
5253

5354
{ // Scope in which SYCL interop event is alive
5455
int i = 0;
55-
event Event = level_zero::make<event>(Context, ZeEvent,
56-
level_zero::ownership::keep);
56+
event Event = make_event<backend::ext_oneapi_level_zero>(
57+
backend_input_t<backend::ext_oneapi_level_zero, event>{
58+
ZeEvent, ext::oneapi::level_zero::ownership::keep},
59+
Context);
5760

5861
info::event_command_status status;
5962
do {

sycl/test-e2e/Plugin/interop-opencl.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ int main() {
4747
assert(ocl_buffers.size() == 1);
4848

4949
// Re-create SYCL objects from native OpenCL handles
50-
auto PlatformInterop = opencl::make<platform>(ocl_platform);
51-
auto DeviceInterop = opencl::make<device>(ocl_device);
52-
auto ContextInterop = opencl::make<context>(ocl_context);
53-
auto QueueInterop = opencl::make<queue>(ContextInterop, ocl_queue);
50+
auto PlatformInterop = sycl::make_platform<backend::opencl>(ocl_platform);
51+
auto DeviceInterop = sycl::make_device<backend::opencl>(ocl_device);
52+
auto ContextInterop = sycl::make_context<backend::opencl>(ocl_context);
53+
auto QueueInterop =
54+
sycl::make_queue<backend::opencl>(ocl_queue, ContextInterop);
5455
auto BufferInterop =
5556
sycl::make_buffer<backend::opencl, int>(ocl_buffers[0], ContextInterop);
5657

0 commit comments

Comments
 (0)