Skip to content

Commit 8c01408

Browse files
committed
rebase
Signed-off-by: Sergey V Maslov <sergey.v.maslov@intel.com>
1 parent d6bf2b6 commit 8c01408

File tree

9 files changed

+424
-35
lines changed

9 files changed

+424
-35
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/level_zero.hpp

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,246 @@
1313
__SYCL_WARNING("CL/sycl/backend/level_zero.hpp usage is deprecated, include "
1414
"sycl/ext/oneapi/backend/level_zero.hpp instead")
1515

16+
<<<<<<< HEAD
1617
#include <sycl/ext/oneapi/backend/level_zero.hpp>
18+
=======
19+
template <> struct interop<backend::level_zero, platform> {
20+
using type = ze_driver_handle_t;
21+
};
22+
23+
template <> struct interop<backend::level_zero, device> {
24+
using type = ze_device_handle_t;
25+
};
26+
27+
template <> struct interop<backend::level_zero, context> {
28+
using type = ze_context_handle_t;
29+
};
30+
31+
template <> struct interop<backend::level_zero, queue> {
32+
using type = ze_command_queue_handle_t;
33+
};
34+
35+
template <> struct interop<backend::level_zero, event> {
36+
using type = ze_event_handle_t;
37+
};
38+
39+
template <> struct interop<backend::level_zero, program> {
40+
using type = ze_module_handle_t;
41+
};
42+
43+
template <typename DataT, int Dimensions, access::mode AccessMode>
44+
struct interop<backend::level_zero, accessor<DataT, Dimensions, AccessMode,
45+
access::target::global_buffer,
46+
access::placeholder::false_t>> {
47+
using type = char *;
48+
};
49+
50+
template <typename DataT, int Dimensions, access::mode AccessMode>
51+
struct interop<backend::level_zero, accessor<DataT, Dimensions, AccessMode,
52+
access::target::constant_buffer,
53+
access::placeholder::false_t>> {
54+
using type = char *;
55+
};
56+
57+
template <typename DataT, int Dimensions, access::mode AccessMode>
58+
struct interop<backend::level_zero,
59+
accessor<DataT, Dimensions, AccessMode, access::target::image,
60+
access::placeholder::false_t>> {
61+
using type = ze_image_handle_t;
62+
};
63+
64+
namespace level_zero {
65+
// Since Level-Zero is not doing any reference counting itself, we have to
66+
// be explicit about the ownership of the native handles used in the
67+
// interop functions below.
68+
//
69+
enum class ownership { transfer, keep };
70+
} // namespace level_zero
71+
72+
namespace detail {
73+
74+
template <> struct BackendInput<backend::level_zero, context> {
75+
using type = struct {
76+
interop<backend::level_zero, context>::type NativeHandle;
77+
std::vector<device> DeviceList;
78+
level_zero::ownership Ownership;
79+
};
80+
};
81+
82+
template <> struct BackendInput<backend::level_zero, queue> {
83+
using type = struct {
84+
interop<backend::level_zero, queue>::type NativeHandle;
85+
level_zero::ownership Ownership;
86+
};
87+
};
88+
89+
template <> struct BackendInput<backend::level_zero, event> {
90+
using type = struct {
91+
interop<backend::level_zero, event>::type NativeHandle;
92+
level_zero::ownership Ownership;
93+
};
94+
};
95+
96+
template <bundle_state State>
97+
struct BackendInput<backend::level_zero, kernel_bundle<State>> {
98+
using type = ze_module_handle_t;
99+
};
100+
101+
template <bundle_state State>
102+
struct BackendReturn<backend::level_zero, kernel_bundle<State>> {
103+
using type = std::vector<ze_module_handle_t>;
104+
};
105+
106+
template <> struct BackendReturn<backend::level_zero, kernel> {
107+
using type = ze_kernel_handle_t;
108+
};
109+
110+
template <> struct InteropFeatureSupportMap<backend::level_zero> {
111+
static constexpr bool MakePlatform = true;
112+
static constexpr bool MakeDevice = true;
113+
static constexpr bool MakeContext = true;
114+
static constexpr bool MakeQueue = true;
115+
static constexpr bool MakeEvent = true;
116+
static constexpr bool MakeKernelBundle = true;
117+
static constexpr bool MakeBuffer = false;
118+
static constexpr bool MakeKernel = false;
119+
};
120+
} // namespace detail
121+
122+
namespace level_zero {
123+
// Implementation of various "make" functions resides in libsycl.so and thus
124+
// their interface needs to be backend agnostic.
125+
// TODO: remove/merge with similar functions in sycl::detail
126+
__SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle);
127+
__SYCL_EXPORT device make_device(const platform &Platform,
128+
pi_native_handle NativeHandle);
129+
__SYCL_EXPORT context make_context(const std::vector<device> &DeviceList,
130+
pi_native_handle NativeHandle,
131+
bool keep_ownership = false);
132+
__SYCL_EXPORT program make_program(const context &Context,
133+
pi_native_handle NativeHandle);
134+
__SYCL_EXPORT queue make_queue(const context &Context,
135+
pi_native_handle InteropHandle,
136+
bool keep_ownership = false);
137+
__SYCL_EXPORT event make_event(const context &Context,
138+
pi_native_handle InteropHandle,
139+
bool keep_ownership = false);
140+
141+
// Construction of SYCL platform.
142+
template <typename T, typename detail::enable_if_t<
143+
std::is_same<T, platform>::value> * = nullptr>
144+
__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_platform free function")
145+
T make(typename interop<backend::level_zero, T>::type Interop) {
146+
return make_platform(reinterpret_cast<pi_native_handle>(Interop));
147+
}
148+
149+
// Construction of SYCL device.
150+
template <typename T, typename detail::enable_if_t<
151+
std::is_same<T, device>::value> * = nullptr>
152+
__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_device free function")
153+
T make(const platform &Platform,
154+
typename interop<backend::level_zero, T>::type Interop) {
155+
return make_device(Platform, reinterpret_cast<pi_native_handle>(Interop));
156+
}
157+
158+
/// Construction of SYCL context.
159+
/// \param DeviceList is a vector of devices which must be encapsulated by
160+
/// created SYCL context. Provided devices and native context handle must
161+
/// be associated with the same platform.
162+
/// \param Interop is a Level Zero native context handle.
163+
/// \param Ownership (optional) specifies who will assume ownership of the
164+
/// native context handle. Default is that SYCL RT does, so it destroys
165+
/// the native handle when the created SYCL object goes out of life.
166+
///
167+
template <typename T, typename std::enable_if<
168+
std::is_same<T, context>::value>::type * = nullptr>
169+
__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_context free function")
170+
T make(const std::vector<device> &DeviceList,
171+
typename interop<backend::level_zero, T>::type Interop,
172+
ownership Ownership = ownership::transfer) {
173+
return make_context(DeviceList, detail::pi::cast<pi_native_handle>(Interop),
174+
Ownership == ownership::keep);
175+
}
176+
177+
// Construction of SYCL program.
178+
template <typename T, typename detail::enable_if_t<
179+
std::is_same<T, program>::value> * = nullptr>
180+
__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_kernel_bundle free function")
181+
T make(const context &Context,
182+
typename interop<backend::level_zero, T>::type Interop) {
183+
return make_program(Context, reinterpret_cast<pi_native_handle>(Interop));
184+
}
185+
186+
// Construction of SYCL queue.
187+
template <typename T, typename detail::enable_if_t<
188+
std::is_same<T, queue>::value> * = nullptr>
189+
__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_queue free function")
190+
T make(const context &Context,
191+
typename interop<backend::level_zero, T>::type Interop,
192+
ownership Ownership = ownership::transfer) {
193+
return make_queue(Context, reinterpret_cast<pi_native_handle>(Interop),
194+
Ownership == ownership::keep);
195+
}
196+
197+
// Construction of SYCL event.
198+
template <typename T, typename detail::enable_if_t<
199+
std::is_same<T, event>::value> * = nullptr>
200+
__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_event free function")
201+
T make(const context &Context,
202+
typename interop<backend::level_zero, T>::type Interop,
203+
ownership Ownership = ownership::transfer) {
204+
return make_event(Context, reinterpret_cast<pi_native_handle>(Interop),
205+
Ownership == ownership::keep);
206+
}
207+
} // namespace level_zero
208+
209+
// Specialization of sycl::make_context for Level-Zero backend.
210+
template <>
211+
context make_context<backend::level_zero>(
212+
const backend_input_t<backend::level_zero, context> &BackendObject,
213+
const async_handler &Handler) {
214+
return level_zero::make_context(
215+
BackendObject.DeviceList,
216+
detail::pi::cast<pi_native_handle>(BackendObject.NativeHandle),
217+
BackendObject.Ownership == level_zero::ownership::keep);
218+
}
219+
220+
// Specialization of sycl::make_queue for Level-Zero backend.
221+
template <>
222+
queue make_queue<backend::level_zero>(
223+
const backend_input_t<backend::level_zero, queue> &BackendObject,
224+
const context &TargetContext, const async_handler Handler) {
225+
return level_zero::make_queue(
226+
TargetContext,
227+
detail::pi::cast<pi_native_handle>(BackendObject.NativeHandle),
228+
BackendObject.Ownership == level_zero::ownership::keep);
229+
}
230+
231+
// Specialization of sycl::make_event for Level-Zero backend.
232+
template <>
233+
event make_event<backend::level_zero>(
234+
const backend_input_t<backend::level_zero, event> &BackendObject,
235+
const context &TargetContext) {
236+
return level_zero::make_event(
237+
TargetContext,
238+
detail::pi::cast<pi_native_handle>(BackendObject.NativeHandle),
239+
BackendObject.Ownership == level_zero::ownership::keep);
240+
}
241+
242+
// TODO: remove this specialization when generic is changed to call
243+
// .GetNative() instead of .get_native() member of kernel_bundle.
244+
template <>
245+
auto get_native<backend::level_zero>(
246+
const kernel_bundle<bundle_state::executable> &Obj)
247+
-> backend_return_t<backend::level_zero,
248+
kernel_bundle<bundle_state::executable>> {
249+
// TODO use SYCL 2020 exception when implemented
250+
if (Obj.get_backend() != backend::level_zero)
251+
throw runtime_error("Backends mismatch", PI_INVALID_OPERATION);
252+
253+
return Obj.template getNative<backend::level_zero>();
254+
}
255+
256+
} // namespace sycl
257+
} // __SYCL_INLINE_NAMESPACE(cl)
258+
>>>>>>> 6c9a8addf701 ([SYCL] Make Level-Zero interop API SYCL-2020 compliant for queue, event, and kernel_bundle(was program).)

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/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/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/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());

0 commit comments

Comments
 (0)