Skip to content

Commit 483aeca

Browse files
committed
Revert "[SYCL] Drop get_native class functions (intel#6483)"
This reverts commit 282e774.
1 parent 82aa804 commit 483aeca

File tree

13 files changed

+135
-74
lines changed

13 files changed

+135
-74
lines changed

sycl/include/sycl/backend.hpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,7 @@ auto get_native(const SyclObjectT &Obj)
125125
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
126126
PI_ERROR_INVALID_OPERATION);
127127
}
128-
return reinterpret_cast<backend_return_t<BackendName, SyclObjectT>>(
129-
Obj.getNative());
130-
}
131-
132-
template <backend BackendName, bundle_state State>
133-
auto get_native(const kernel_bundle<State> &Obj)
134-
-> backend_return_t<BackendName, kernel_bundle<State>> {
135-
// TODO use SYCL 2020 exception when implemented
136-
if (Obj.get_backend() != BackendName) {
137-
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
138-
PI_ERROR_INVALID_OPERATION);
139-
}
140-
return Obj.template getNative<BackendName>();
128+
return Obj.template get_native<BackendName>();
141129
}
142130

143131
template <backend BackendName, typename DataT, int Dimensions,

sycl/include/sycl/context.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ class __SYCL_EXPORT context {
217217
/// \return a vector of valid SYCL device instances.
218218
std::vector<device> get_devices() const;
219219

220+
/// Gets the native handle of the SYCL context.
221+
///
222+
/// \return a native handle, the type of which defined by the backend.
223+
template <backend Backend>
224+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
225+
backend_return_t<Backend, context> get_native() const {
226+
return reinterpret_cast<backend_return_t<Backend, context>>(getNative());
227+
}
228+
220229
private:
221230
/// Constructs a SYCL context object from a valid context_impl instance.
222231
context(std::shared_ptr<detail::context_impl> Impl);

sycl/include/sycl/device.hpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ namespace sycl {
2525
__SYCL_INLINE_VER_NAMESPACE(_V1) {
2626
// Forward declarations
2727
class device_selector;
28-
template <backend BackendName, class SyclObjectT>
29-
auto get_native(const SyclObjectT &Obj)
30-
-> backend_return_t<BackendName, SyclObjectT>;
3128
namespace detail {
3229
class device_impl;
3330
auto getDeviceComparisonLambda();
@@ -205,6 +202,19 @@ class __SYCL_EXPORT device {
205202
/// \return the backend associated with this device.
206203
backend get_backend() const noexcept;
207204

205+
/// Gets the native handle of the SYCL device.
206+
///
207+
/// \return a native handle, the type of which defined by the backend.
208+
template <backend Backend>
209+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
210+
backend_return_t<Backend, device> get_native() const {
211+
// In CUDA CUdevice isn't an opaque pointer, unlike a lot of the others,
212+
// but instead a 32-bit int (on all relevant systems). Different
213+
// backends use the same function for this purpose so static_cast is
214+
// needed in some cases but not others, so a C-style cast was chosen.
215+
return (backend_return_t<Backend, device>)getNative();
216+
}
217+
208218
/// Indicates if the SYCL device has the given feature.
209219
///
210220
/// \param Aspect is one of the values in Table 4.20 of the SYCL 2020
@@ -231,10 +241,6 @@ class __SYCL_EXPORT device {
231241
friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
232242

233243
friend auto detail::getDeviceComparisonLambda();
234-
235-
template <backend BackendName, class SyclObjectT>
236-
friend auto get_native(const SyclObjectT &Obj)
237-
-> backend_return_t<BackendName, SyclObjectT>;
238244
};
239245

240246
} // __SYCL_INLINE_VER_NAMESPACE(_V1)

sycl/include/sycl/event.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ namespace sycl {
2222
__SYCL_INLINE_VER_NAMESPACE(_V1) {
2323
// Forward declaration
2424
class context;
25-
26-
template <backend BackendName, class SyclObjectT>
27-
auto get_native(const SyclObjectT &Obj)
28-
-> backend_return_t<BackendName, SyclObjectT>;
29-
3025
namespace detail {
3126
class event_impl;
3227
}
@@ -127,6 +122,15 @@ class __SYCL_EXPORT event {
127122
/// \return the backend associated with this platform
128123
backend get_backend() const noexcept;
129124

125+
/// Gets the native handle of the SYCL event.
126+
///
127+
/// \return a native handle, the type of which defined by the backend.
128+
template <backend Backend>
129+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
130+
backend_return_t<Backend, event> get_native() const {
131+
return reinterpret_cast<backend_return_t<Backend, event>>(getNative());
132+
}
133+
130134
private:
131135
event(std::shared_ptr<detail::event_impl> EventImpl);
132136

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,21 @@ make_buffer(
221221
!(BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep));
222222
}
223223

224+
// TODO: remove this specialization when generic is changed to call
225+
// .GetNative() instead of .get_native() member of kernel_bundle.
226+
template <>
227+
inline auto get_native<backend::ext_oneapi_level_zero>(
228+
const kernel_bundle<bundle_state::executable> &Obj)
229+
-> backend_return_t<backend::ext_oneapi_level_zero,
230+
kernel_bundle<bundle_state::executable>> {
231+
// TODO use SYCL 2020 exception when implemented
232+
if (Obj.get_backend() != backend::ext_oneapi_level_zero)
233+
throw runtime_error(errc::backend_mismatch, "Backends mismatch",
234+
PI_ERROR_INVALID_OPERATION);
235+
236+
return Obj.template getNative<backend::ext_oneapi_level_zero>();
237+
}
238+
224239
namespace __SYCL2020_DEPRECATED("use 'ext::oneapi::level_zero' instead")
225240
level_zero {
226241
using namespace ext::oneapi::level_zero;

sycl/include/sycl/ext/oneapi/experimental/backend/cuda.hpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <sycl/backend.hpp>
1212
#include <sycl/context.hpp>
13-
#include <sycl/ext/oneapi/experimental/backend/backend_traits_cuda.hpp>
1413

1514
#include <vector>
1615

@@ -53,6 +52,13 @@ inline auto get_native<backend::ext_oneapi_cuda, context>(const context &C)
5352
return ret;
5453
}
5554

55+
// Specialisation of non-free context get_native
56+
template <>
57+
inline backend_return_t<backend::ext_oneapi_cuda, context>
58+
context::get_native<backend::ext_oneapi_cuda>() const {
59+
return sycl::get_native<backend::ext_oneapi_cuda, context>(*this);
60+
}
61+
5662
// Specialisation of interop_handles get_native_context
5763
template <>
5864
inline backend_return_t<backend::ext_oneapi_cuda, context>
@@ -73,20 +79,6 @@ inline device make_device<backend::ext_oneapi_cuda>(
7379
return ext::oneapi::cuda::make_device(NativeHandle);
7480
}
7581

76-
template <>
77-
backend_return_t<backend::ext_oneapi_cuda, device>
78-
get_native<backend::ext_oneapi_cuda, device>(const device &Obj) {
79-
// TODO use SYCL 2020 exception when implemented
80-
if (Obj.get_backend() != backend::ext_oneapi_cuda) {
81-
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
82-
PI_ERROR_INVALID_OPERATION);
83-
}
84-
// CUDA uses a 32-bit int instead of an opaque pointer like other backends,
85-
// so we need a specialization with static_cast instead of reinterpret_cast.
86-
return static_cast<backend_return_t<backend::ext_oneapi_cuda, device>>(
87-
Obj.getNative());
88-
}
89-
9082
// CUDA event specialization
9183
template <>
9284
inline event make_event<backend::ext_oneapi_cuda>(

sycl/include/sycl/kernel.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ class program;
2828
class context;
2929
template <backend Backend> class backend_traits;
3030
template <bundle_state State> class kernel_bundle;
31-
template <backend BackendName, class SyclObjectT>
32-
auto get_native(const SyclObjectT &Obj)
33-
-> backend_return_t<BackendName, SyclObjectT>;
3431

3532
namespace detail {
3633
class kernel_impl;
@@ -166,6 +163,12 @@ class __SYCL_EXPORT kernel {
166163
Param>::with_input_return_type
167164
get_info(const device &Device, const range<3> &WGSize) const;
168165

166+
template <backend Backend>
167+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
168+
backend_return_t<Backend, kernel> get_native() const {
169+
return detail::pi::cast<backend_return_t<Backend, kernel>>(getNative());
170+
}
171+
169172
private:
170173
/// Constructs a SYCL kernel object from a valid kernel_impl instance.
171174
kernel(std::shared_ptr<detail::kernel_impl> Impl);
@@ -181,9 +184,6 @@ class __SYCL_EXPORT kernel {
181184
friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
182185
template <class T>
183186
friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
184-
template <backend BackendName, class SyclObjectT>
185-
friend auto get_native(const SyclObjectT &Obj)
186-
-> backend_return_t<BackendName, SyclObjectT>;
187187
};
188188
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
189189
} // namespace sycl

sycl/include/sycl/kernel_bundle.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ namespace sycl {
2626
__SYCL_INLINE_VER_NAMESPACE(_V1) {
2727
// Forward declaration
2828
template <backend Backend> class backend_traits;
29-
template <backend Backend, bundle_state State>
30-
auto get_native(const kernel_bundle<State> &Obj)
31-
-> backend_return_t<Backend, kernel_bundle<State>>;
29+
template <backend Backend, class SyclT>
30+
auto get_native(const SyclT &Obj) -> backend_return_t<Backend, SyclT>;
3231

3332
namespace detail {
3433
class kernel_id_impl;
@@ -311,6 +310,12 @@ class kernel_bundle : public detail::kernel_bundle_plain {
311310
return reinterpret_cast<device_image_iterator>(kernel_bundle_plain::end());
312311
}
313312

313+
template <backend Backend>
314+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
315+
backend_return_t<Backend, kernel_bundle<State>> get_native() const {
316+
return getNative<Backend>();
317+
}
318+
314319
private:
315320
kernel_bundle(detail::KernelBundleImplPtr Impl)
316321
: kernel_bundle_plain(std::move(Impl)) {}
@@ -321,9 +326,8 @@ class kernel_bundle : public detail::kernel_bundle_plain {
321326
template <class T>
322327
friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
323328

324-
template <backend Backend, bundle_state StateB>
325-
friend auto get_native(const kernel_bundle<StateB> &Obj)
326-
-> backend_return_t<Backend, kernel_bundle<StateB>>;
329+
template <backend Backend, class SyclT>
330+
friend auto get_native(const SyclT &Obj) -> backend_return_t<Backend, SyclT>;
327331

328332
template <backend Backend>
329333
backend_return_t<Backend, kernel_bundle<State>> getNative() const {

sycl/include/sycl/platform.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) {
2626
// Forward declaration
2727
class device_selector;
2828
class device;
29-
template <backend BackendName, class SyclObjectT>
30-
auto get_native(const SyclObjectT &Obj)
31-
-> backend_return_t<BackendName, SyclObjectT>;
3229
namespace detail {
3330
class platform_impl;
3431
}
@@ -138,6 +135,15 @@ class __SYCL_EXPORT platform {
138135
/// \return the backend associated with this platform
139136
backend get_backend() const noexcept;
140137

138+
/// Gets the native handle of the SYCL platform.
139+
///
140+
/// \return a native handle, the type of which defined by the backend.
141+
template <backend Backend>
142+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
143+
backend_return_t<Backend, platform> get_native() const {
144+
return reinterpret_cast<backend_return_t<Backend, platform>>(getNative());
145+
}
146+
141147
/// Indicates if all of the SYCL devices on this platform have the
142148
/// given feature.
143149
///
@@ -166,9 +172,6 @@ class __SYCL_EXPORT platform {
166172
template <class Obj>
167173
friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
168174

169-
template <backend BackendName, class SyclObjectT>
170-
friend auto get_native(const SyclObjectT &Obj)
171-
-> backend_return_t<BackendName, SyclObjectT>;
172175
}; // class platform
173176
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
174177
} // namespace sycl

sycl/include/sycl/program.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) {
2828
// Forward declarations
2929
class context;
3030
class device;
31-
template <backend BackendName, class SyclObjectT>
32-
auto get_native(const SyclObjectT &Obj)
33-
-> backend_return_t<BackendName, SyclObjectT>;
34-
3531
namespace detail {
3632
class program_impl;
3733
}
@@ -369,6 +365,15 @@ class __SYCL_EXPORT __SYCL2020_DEPRECATED(
369365
/// \return the backend associated with this program.
370366
backend get_backend() const noexcept;
371367

368+
/// Gets the native handle of the SYCL platform.
369+
///
370+
/// \return a native handle, the type of which defined by the backend.
371+
template <backend Backend>
372+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
373+
backend_return_t<Backend, program> get_native() const {
374+
return reinterpret_cast<backend_return_t<Backend, program>>(getNative());
375+
}
376+
372377
private:
373378
pi_native_handle getNative() const;
374379
program(std::shared_ptr<detail::program_impl> impl);
@@ -414,9 +419,6 @@ class __SYCL_EXPORT __SYCL2020_DEPRECATED(
414419
friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
415420
template <class T>
416421
friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
417-
template <backend BackendName, class SyclObjectT>
418-
friend auto get_native(const SyclObjectT &Obj)
419-
-> backend_return_t<BackendName, SyclObjectT>;
420422
};
421423
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
422424
} // namespace sycl

sycl/include/sycl/queue.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,8 @@ class context;
5959
class device;
6060
class queue;
6161

62-
template <backend BackendName, class SyclObjectT>
63-
auto get_native(const SyclObjectT &Obj)
64-
-> backend_return_t<BackendName, SyclObjectT>;
65-
6662
namespace detail {
6763
class queue_impl;
68-
6964
#if __SYCL_USE_FALLBACK_ASSERT
7065
static event submitAssertCapture(queue &, event &, queue *,
7166
const detail::code_location &);
@@ -1069,6 +1064,15 @@ class __SYCL_EXPORT queue {
10691064
/// \return the backend associated with this queue.
10701065
backend get_backend() const noexcept;
10711066

1067+
/// Gets the native handle of the SYCL queue.
1068+
///
1069+
/// \return a native handle, the type of which defined by the backend.
1070+
template <backend Backend>
1071+
__SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
1072+
backend_return_t<Backend, queue> get_native() const {
1073+
return reinterpret_cast<backend_return_t<Backend, queue>>(getNative());
1074+
}
1075+
10721076
private:
10731077
pi_native_handle getNative() const;
10741078

@@ -1080,10 +1084,6 @@ class __SYCL_EXPORT queue {
10801084
template <class T>
10811085
friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
10821086

1083-
template <backend BackendName, class SyclObjectT>
1084-
friend auto get_native(const SyclObjectT &Obj)
1085-
-> backend_return_t<BackendName, SyclObjectT>;
1086-
10871087
#if __SYCL_USE_FALLBACK_ASSERT
10881088
friend event detail::submitAssertCapture(queue &, event &, queue *,
10891089
const detail::code_location &);

sycl/test/basic_tests/interop-cuda-experimental.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ int main() {
5757
cu_event = get_native<backend::ext_oneapi_cuda>(Event);
5858
cu_queue = get_native<backend::ext_oneapi_cuda>(Queue);
5959

60+
// Check deprecated
61+
// expected-warning@+2 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}}
62+
// expected-warning@+1 {{'get_native<sycl::backend::ext_oneapi_cuda>' is deprecated: Use SYCL 2020 sycl::get_native free function}}
63+
cu_device = Device.get_native<backend::ext_oneapi_cuda>();
64+
// expected-warning@+2 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}}
65+
// expected-warning@+1 {{'get_native<sycl::backend::ext_oneapi_cuda>' is deprecated: Use SYCL 2020 sycl::get_native free function}}
66+
cu_context = Context.get_native<backend::ext_oneapi_cuda>();
67+
// expected-warning@+2 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}}
68+
// expected-warning@+1 {{'get_native<sycl::backend::ext_oneapi_cuda>' is deprecated: Use SYCL 2020 sycl::get_native free function}}
69+
cu_event = Event.get_native<backend::ext_oneapi_cuda>();
70+
// expected-warning@+2 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}}
71+
// expected-warning@+1 {{'get_native<sycl::backend::ext_oneapi_cuda>' is deprecated: Use SYCL 2020 sycl::get_native free function}}
72+
cu_queue = Queue.get_native<backend::ext_oneapi_cuda>();
73+
6074
// 4.5.1.1 For each SYCL runtime class T which supports SYCL application
6175
// interoperability with the SYCL backend, a specialization of input_type must
6276
// be defined as the type of SYCL application interoperability native backend

0 commit comments

Comments
 (0)