Skip to content

Commit dd7f82c

Browse files
[SYCL] Make Level-Zero interop API SYCL-2020 compliant for queue, event, and kernel_bundle(was program). (#4512)
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent ebbd568 commit dd7f82c

File tree

12 files changed

+181
-40
lines changed

12 files changed

+181
-40
lines changed

sycl/include/CL/sycl/backend.hpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ using backend_return_t =
6666
typename backend_traits<Backend>::template return_type<SyclType>;
6767

6868
template <backend BackendName, class SyclObjectT>
69-
auto get_native(const SyclObjectT &Obj) ->
70-
typename interop<BackendName, SyclObjectT>::type {
69+
auto get_native(const SyclObjectT &Obj)
70+
-> backend_return_t<BackendName, SyclObjectT> {
7171
// TODO use SYCL 2020 exception when implemented
7272
if (Obj.get_backend() != BackendName)
7373
throw runtime_error("Backends mismatch", PI_INVALID_OPERATION);
@@ -146,17 +146,18 @@ make_context(
146146
}
147147

148148
template <backend Backend>
149+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_queue free function")
149150
typename std::enable_if<
150151
detail::InteropFeatureSupportMap<Backend>::MakeQueue == true, queue>::type
151-
make_queue(const typename backend_traits<Backend>::template input_type<queue>
152-
&BackendObject,
153-
const context &TargetContext, bool KeepOwnership,
154-
const async_handler Handler = {}) {
152+
make_queue(
153+
const typename backend_traits<Backend>::template input_type<queue>
154+
&BackendObject,
155+
const context &TargetContext, bool KeepOwnership,
156+
const async_handler Handler = {}) {
155157
return detail::make_queue(detail::pi::cast<pi_native_handle>(BackendObject),
156158
TargetContext, KeepOwnership, Handler, Backend);
157159
}
158160

159-
// TODO: remove this version (without ownership) when allowed to break ABI.
160161
template <backend Backend>
161162
typename std::enable_if<
162163
detail::InteropFeatureSupportMap<Backend>::MakeQueue == true, queue>::type
@@ -178,11 +179,13 @@ make_event(const typename backend_traits<Backend>::template input_type<event>
178179
}
179180

180181
template <backend Backend>
182+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_event free function")
181183
typename std::enable_if<
182184
detail::InteropFeatureSupportMap<Backend>::MakeEvent == true, event>::type
183-
make_event(const typename backend_traits<Backend>::template input_type<event>
184-
&BackendObject,
185-
const context &TargetContext, bool KeepOwnership) {
185+
make_event(
186+
const typename backend_traits<Backend>::template input_type<event>
187+
&BackendObject,
188+
const context &TargetContext, bool KeepOwnership) {
186189
return detail::make_event(detail::pi::cast<pi_native_handle>(BackendObject),
187190
TargetContext, KeepOwnership, Backend);
188191
}

sycl/include/CL/sycl/backend/opencl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct BackendInput<backend::opencl, kernel_bundle<State>> {
7575

7676
template <bundle_state State>
7777
struct BackendReturn<backend::opencl, kernel_bundle<State>> {
78+
// TODO: Per SYCL 2020 this should be std::vector<cl_program>
7879
using type = cl_program;
7980
};
8081

sycl/include/CL/sycl/context.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class __SYCL_EXPORT context {
216216
///
217217
/// \return a native handle, the type of which defined by the backend.
218218
template <backend BackendName>
219-
__SYCL_DEPRECATED("Use SYCL-2020 sycl::get_native free function")
219+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
220220
auto get_native() const -> typename interop<BackendName, context>::type {
221221
return reinterpret_cast<typename interop<BackendName, context>::type>(
222222
getNative());

sycl/include/CL/sycl/device.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class __SYCL_EXPORT device {
184184
///
185185
/// \return a native handle, the type of which defined by the backend.
186186
template <backend BackendName>
187-
__SYCL_DEPRECATED("Use SYCL-2020 sycl::get_native free function")
187+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
188188
auto get_native() const -> typename interop<BackendName, device>::type {
189189
return (typename interop<BackendName, device>::type)getNative();
190190
}

sycl/include/CL/sycl/event.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,12 @@ class __SYCL_EXPORT event {
129129
///
130130
/// \return a native handle, the type of which defined by the backend.
131131
template <backend BackendName>
132+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
132133
auto get_native() const -> typename interop<BackendName, event>::type {
133134
return reinterpret_cast<typename interop<BackendName, event>::type>(
134135
getNative());
135136
}
137+
136138
private:
137139
event(std::shared_ptr<detail::event_impl> EventImpl);
138140

sycl/include/CL/sycl/interop_handle.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class interop_handle {
8686
template <backend Backend = backend::opencl>
8787
backend_return_t<Backend, queue> get_native_queue() const {
8888
#ifndef __SYCL_DEVICE_ONLY__
89-
// TODO: replace the exception thrown below with the SYCL-2020 exception
89+
// TODO: replace the exception thrown below with the SYCL 2020 exception
9090
// with the error code 'errc::backend_mismatch' when those new exceptions
9191
// are ready to be used.
9292
if (Backend != get_backend())
@@ -107,7 +107,7 @@ class interop_handle {
107107
template <backend Backend = backend::opencl>
108108
backend_return_t<Backend, device> get_native_device() const {
109109
#ifndef __SYCL_DEVICE_ONLY__
110-
// TODO: replace the exception thrown below with the SYCL-2020 exception
110+
// TODO: replace the exception thrown below with the SYCL 2020 exception
111111
// with the error code 'errc::backend_mismatch' when those new exceptions
112112
// are ready to be used.
113113
if (Backend != get_backend())
@@ -129,7 +129,7 @@ class interop_handle {
129129
template <backend Backend = backend::opencl>
130130
backend_return_t<Backend, context> get_native_context() const {
131131
#ifndef __SYCL_DEVICE_ONLY__
132-
// TODO: replace the exception thrown below with the SYCL-2020 exception
132+
// TODO: replace the exception thrown below with the SYCL 2020 exception
133133
// with the error code 'errc::backend_mismatch' when those new exceptions
134134
// are ready to be used.
135135
if (Backend != get_backend())

sycl/include/CL/sycl/kernel_bundle.hpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ __SYCL_INLINE_NAMESPACE(cl) {
2525
namespace sycl {
2626
// Forward declaration
2727
template <backend Backend> class backend_traits;
28+
template <backend Backend, class SyclT>
29+
auto get_native(const SyclT &Obj) -> backend_return_t<Backend, SyclT>;
2830

2931
namespace detail {
3032
class kernel_id_impl;
@@ -176,8 +178,8 @@ class __SYCL_EXPORT kernel_bundle_plain {
176178
void set_specialization_constant_impl(const char *SpecName, void *Value,
177179
size_t Size) noexcept;
178180

179-
void get_specialization_constant_impl(const char *SpecName, void *Value) const
180-
noexcept;
181+
void get_specialization_constant_impl(const char *SpecName,
182+
void *Value) const noexcept;
181183

182184
bool is_specialization_constant_set(const char *SpecName) const noexcept;
183185

@@ -308,9 +310,9 @@ class kernel_bundle : public detail::kernel_bundle_plain {
308310
}
309311

310312
template <backend Backend>
313+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
311314
std::vector<typename backend_traits<Backend>::template return_type<
312-
kernel_bundle<State>>>
313-
get_native() {
315+
kernel_bundle<State>>> get_native() {
314316
std::vector<typename backend_traits<Backend>::template return_type<
315317
kernel_bundle<State>>>
316318
ReturnValue;
@@ -335,6 +337,25 @@ class kernel_bundle : public detail::kernel_bundle_plain {
335337

336338
template <class T>
337339
friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
340+
341+
template <backend Backend, class SyclT>
342+
friend auto get_native(const SyclT &Obj) -> backend_return_t<Backend, SyclT>;
343+
344+
template <backend Backend>
345+
backend_return_t<Backend, kernel_bundle<State>> getNative() const {
346+
// NOTE: implementation assumes that the return type is a
347+
// derivative of std::vector.
348+
backend_return_t<Backend, kernel_bundle<State>> ReturnValue;
349+
ReturnValue.reserve(std::distance(begin(), end()));
350+
351+
for (const device_image<State> &DevImg : *this) {
352+
ReturnValue.push_back(
353+
detail::pi::cast<typename decltype(ReturnValue)::value_type>(
354+
DevImg.getNative()));
355+
}
356+
357+
return ReturnValue;
358+
}
338359
};
339360

340361
/////////////////////////
@@ -604,7 +625,7 @@ __SYCL_EXPORT std::vector<sycl::device> find_device_intersection(
604625
__SYCL_EXPORT std::shared_ptr<detail::kernel_bundle_impl>
605626
link_impl(const std::vector<kernel_bundle<bundle_state::object>> &ObjectBundles,
606627
const std::vector<device> &Devs, const property_list &PropList);
607-
}
628+
} // namespace detail
608629

609630
/// \returns a new kernel_bundle which contains the device images from the
610631
/// ObjectBundles that are translated into one or more new device images of

sycl/include/CL/sycl/platform.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class __SYCL_EXPORT platform {
121121
///
122122
/// \return a native handle, the type of which defined by the backend.
123123
template <backend BackendName>
124-
__SYCL_DEPRECATED("Use SYCL-2020 sycl::get_native free function")
124+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
125125
auto get_native() const -> typename interop<BackendName, platform>::type {
126126
return reinterpret_cast<typename interop<BackendName, platform>::type>(
127127
getNative());

sycl/include/CL/sycl/program.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ class __SYCL_EXPORT __SYCL2020_DEPRECATED(
365365
///
366366
/// \return a native handle, the type of which defined by the backend.
367367
template <backend BackendName>
368+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
368369
auto get_native() const -> typename interop<BackendName, program>::type {
369370
return reinterpret_cast<typename interop<BackendName, program>::type>(
370371
getNative());

sycl/include/CL/sycl/queue.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class AssertInfoCopier;
8383
static event submitAssertCapture(queue &, event &, queue *,
8484
const detail::code_location &);
8585
#endif
86-
}
86+
} // namespace detail
8787

8888
/// Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
8989
///
@@ -1024,6 +1024,7 @@ class __SYCL_EXPORT queue {
10241024
///
10251025
/// \return a native handle, the type of which defined by the backend.
10261026
template <backend BackendName>
1027+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
10271028
auto get_native() const -> typename interop<BackendName, queue>::type {
10281029
return reinterpret_cast<typename interop<BackendName, queue>::type>(
10291030
getNative());

0 commit comments

Comments
 (0)