diff --git a/sycl/include/CL/sycl/backend.hpp b/sycl/include/CL/sycl/backend.hpp index c4a21266ec1f4..9a1fd0e007932 100644 --- a/sycl/include/CL/sycl/backend.hpp +++ b/sycl/include/CL/sycl/backend.hpp @@ -66,8 +66,8 @@ using backend_return_t = typename backend_traits::template return_type; template -auto get_native(const SyclObjectT &Obj) -> - typename interop::type { +auto get_native(const SyclObjectT &Obj) + -> backend_return_t { // TODO use SYCL 2020 exception when implemented if (Obj.get_backend() != BackendName) throw runtime_error("Backends mismatch", PI_INVALID_OPERATION); @@ -146,17 +146,18 @@ make_context( } template +__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_queue free function") typename std::enable_if< detail::InteropFeatureSupportMap::MakeQueue == true, queue>::type -make_queue(const typename backend_traits::template input_type - &BackendObject, - const context &TargetContext, bool KeepOwnership, - const async_handler Handler = {}) { + make_queue( + const typename backend_traits::template input_type + &BackendObject, + const context &TargetContext, bool KeepOwnership, + const async_handler Handler = {}) { return detail::make_queue(detail::pi::cast(BackendObject), TargetContext, KeepOwnership, Handler, Backend); } -// TODO: remove this version (without ownership) when allowed to break ABI. template typename std::enable_if< detail::InteropFeatureSupportMap::MakeQueue == true, queue>::type @@ -178,11 +179,13 @@ make_event(const typename backend_traits::template input_type } template +__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_event free function") typename std::enable_if< detail::InteropFeatureSupportMap::MakeEvent == true, event>::type -make_event(const typename backend_traits::template input_type - &BackendObject, - const context &TargetContext, bool KeepOwnership) { + make_event( + const typename backend_traits::template input_type + &BackendObject, + const context &TargetContext, bool KeepOwnership) { return detail::make_event(detail::pi::cast(BackendObject), TargetContext, KeepOwnership, Backend); } diff --git a/sycl/include/CL/sycl/backend/opencl.hpp b/sycl/include/CL/sycl/backend/opencl.hpp index 0c0fc33d3712c..c051ca0f0a4ce 100644 --- a/sycl/include/CL/sycl/backend/opencl.hpp +++ b/sycl/include/CL/sycl/backend/opencl.hpp @@ -75,6 +75,7 @@ struct BackendInput> { template struct BackendReturn> { + // TODO: Per SYCL 2020 this should be std::vector using type = cl_program; }; diff --git a/sycl/include/CL/sycl/context.hpp b/sycl/include/CL/sycl/context.hpp index 4b2a27f774789..7fd2e1f343580 100644 --- a/sycl/include/CL/sycl/context.hpp +++ b/sycl/include/CL/sycl/context.hpp @@ -216,7 +216,7 @@ class __SYCL_EXPORT context { /// /// \return a native handle, the type of which defined by the backend. template - __SYCL_DEPRECATED("Use SYCL-2020 sycl::get_native free function") + __SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function") auto get_native() const -> typename interop::type { return reinterpret_cast::type>( getNative()); diff --git a/sycl/include/CL/sycl/device.hpp b/sycl/include/CL/sycl/device.hpp index 96f35d24a49de..378a9d8860cda 100644 --- a/sycl/include/CL/sycl/device.hpp +++ b/sycl/include/CL/sycl/device.hpp @@ -184,7 +184,7 @@ class __SYCL_EXPORT device { /// /// \return a native handle, the type of which defined by the backend. template - __SYCL_DEPRECATED("Use SYCL-2020 sycl::get_native free function") + __SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function") auto get_native() const -> typename interop::type { return (typename interop::type)getNative(); } diff --git a/sycl/include/CL/sycl/event.hpp b/sycl/include/CL/sycl/event.hpp index 70e70d13ad28b..7b01a4bc78540 100644 --- a/sycl/include/CL/sycl/event.hpp +++ b/sycl/include/CL/sycl/event.hpp @@ -129,10 +129,12 @@ class __SYCL_EXPORT event { /// /// \return a native handle, the type of which defined by the backend. template + __SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function") auto get_native() const -> typename interop::type { return reinterpret_cast::type>( getNative()); } + private: event(std::shared_ptr EventImpl); diff --git a/sycl/include/CL/sycl/interop_handle.hpp b/sycl/include/CL/sycl/interop_handle.hpp index 9d1e537a127fd..27d3f6195f638 100644 --- a/sycl/include/CL/sycl/interop_handle.hpp +++ b/sycl/include/CL/sycl/interop_handle.hpp @@ -86,7 +86,7 @@ class interop_handle { template backend_return_t get_native_queue() const { #ifndef __SYCL_DEVICE_ONLY__ - // TODO: replace the exception thrown below with the SYCL-2020 exception + // TODO: replace the exception thrown below with the SYCL 2020 exception // with the error code 'errc::backend_mismatch' when those new exceptions // are ready to be used. if (Backend != get_backend()) @@ -107,7 +107,7 @@ class interop_handle { template backend_return_t get_native_device() const { #ifndef __SYCL_DEVICE_ONLY__ - // TODO: replace the exception thrown below with the SYCL-2020 exception + // TODO: replace the exception thrown below with the SYCL 2020 exception // with the error code 'errc::backend_mismatch' when those new exceptions // are ready to be used. if (Backend != get_backend()) @@ -129,7 +129,7 @@ class interop_handle { template backend_return_t get_native_context() const { #ifndef __SYCL_DEVICE_ONLY__ - // TODO: replace the exception thrown below with the SYCL-2020 exception + // TODO: replace the exception thrown below with the SYCL 2020 exception // with the error code 'errc::backend_mismatch' when those new exceptions // are ready to be used. if (Backend != get_backend()) diff --git a/sycl/include/CL/sycl/kernel_bundle.hpp b/sycl/include/CL/sycl/kernel_bundle.hpp index 8f67aaf1034f4..21398c232aa9e 100644 --- a/sycl/include/CL/sycl/kernel_bundle.hpp +++ b/sycl/include/CL/sycl/kernel_bundle.hpp @@ -25,6 +25,8 @@ __SYCL_INLINE_NAMESPACE(cl) { namespace sycl { // Forward declaration template class backend_traits; +template +auto get_native(const SyclT &Obj) -> backend_return_t; namespace detail { class kernel_id_impl; @@ -176,8 +178,8 @@ class __SYCL_EXPORT kernel_bundle_plain { void set_specialization_constant_impl(const char *SpecName, void *Value, size_t Size) noexcept; - void get_specialization_constant_impl(const char *SpecName, void *Value) const - noexcept; + void get_specialization_constant_impl(const char *SpecName, + void *Value) const noexcept; bool is_specialization_constant_set(const char *SpecName) const noexcept; @@ -308,9 +310,9 @@ class kernel_bundle : public detail::kernel_bundle_plain { } template + __SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function") std::vector::template return_type< - kernel_bundle>> - get_native() { + kernel_bundle>> get_native() { std::vector::template return_type< kernel_bundle>> ReturnValue; @@ -335,6 +337,25 @@ class kernel_bundle : public detail::kernel_bundle_plain { template friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj); + + template + friend auto get_native(const SyclT &Obj) -> backend_return_t; + + template + backend_return_t> getNative() const { + // NOTE: implementation assumes that the return type is a + // derivative of std::vector. + backend_return_t> ReturnValue; + ReturnValue.reserve(std::distance(begin(), end())); + + for (const device_image &DevImg : *this) { + ReturnValue.push_back( + detail::pi::cast( + DevImg.getNative())); + } + + return ReturnValue; + } }; ///////////////////////// @@ -604,7 +625,7 @@ __SYCL_EXPORT std::vector find_device_intersection( __SYCL_EXPORT std::shared_ptr link_impl(const std::vector> &ObjectBundles, const std::vector &Devs, const property_list &PropList); -} +} // namespace detail /// \returns a new kernel_bundle which contains the device images from the /// ObjectBundles that are translated into one or more new device images of diff --git a/sycl/include/CL/sycl/platform.hpp b/sycl/include/CL/sycl/platform.hpp index 16c8d46b0c148..cb2eb2b4d73de 100644 --- a/sycl/include/CL/sycl/platform.hpp +++ b/sycl/include/CL/sycl/platform.hpp @@ -116,7 +116,7 @@ class __SYCL_EXPORT platform { /// /// \return a native handle, the type of which defined by the backend. template - __SYCL_DEPRECATED("Use SYCL-2020 sycl::get_native free function") + __SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function") auto get_native() const -> typename interop::type { return reinterpret_cast::type>( getNative()); diff --git a/sycl/include/CL/sycl/program.hpp b/sycl/include/CL/sycl/program.hpp index 6b70b47259af4..7973ff03cf273 100644 --- a/sycl/include/CL/sycl/program.hpp +++ b/sycl/include/CL/sycl/program.hpp @@ -365,6 +365,7 @@ class __SYCL_EXPORT __SYCL2020_DEPRECATED( /// /// \return a native handle, the type of which defined by the backend. template + __SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function") auto get_native() const -> typename interop::type { return reinterpret_cast::type>( getNative()); diff --git a/sycl/include/CL/sycl/queue.hpp b/sycl/include/CL/sycl/queue.hpp index 01f6cbc99015e..0df54566d1b46 100644 --- a/sycl/include/CL/sycl/queue.hpp +++ b/sycl/include/CL/sycl/queue.hpp @@ -83,7 +83,7 @@ class AssertInfoCopier; static event submitAssertCapture(queue &, event &, queue *, const detail::code_location &); #endif -} +} // namespace detail /// Encapsulates a single SYCL queue which schedules kernels on a SYCL device. /// @@ -1020,6 +1020,7 @@ class __SYCL_EXPORT queue { /// /// \return a native handle, the type of which defined by the backend. template + __SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function") auto get_native() const -> typename interop::type { return reinterpret_cast::type>( getNative()); diff --git a/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp b/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp index cb41cc34447f3..9cc87f424326e 100644 --- a/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp +++ b/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp @@ -82,6 +82,30 @@ template <> struct BackendInput { }; }; +template <> struct BackendInput { + using type = struct { + interop::type NativeHandle; + ext::oneapi::level_zero::ownership Ownership; + }; +}; + +template <> struct BackendInput { + using type = struct { + interop::type NativeHandle; + ext::oneapi::level_zero::ownership Ownership; + }; +}; + +template +struct BackendInput> { + using type = ze_module_handle_t; +}; + +template +struct BackendReturn> { + using type = std::vector; +}; + template <> struct BackendReturn { using type = ze_kernel_handle_t; }; @@ -90,11 +114,11 @@ template <> struct InteropFeatureSupportMap { static constexpr bool MakePlatform = true; static constexpr bool MakeDevice = true; static constexpr bool MakeContext = true; - static constexpr bool MakeQueue = false; + static constexpr bool MakeQueue = true; static constexpr bool MakeEvent = true; + static constexpr bool MakeKernelBundle = true; static constexpr bool MakeBuffer = false; static constexpr bool MakeKernel = false; - static constexpr bool MakeKernelBundle = false; }; } // namespace detail @@ -122,7 +146,7 @@ __SYCL_EXPORT event make_event(const context &Context, // Construction of SYCL platform. template ::value> * = nullptr> -__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_platform free function") +__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_platform free function") T make(typename interop::type Interop) { return make_platform(reinterpret_cast(Interop)); } @@ -130,7 +154,7 @@ T make(typename interop::type Interop) { // Construction of SYCL device. template ::value> * = nullptr> -__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_device free function") +__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_device free function") T make(const platform &Platform, typename interop::type Interop) { return make_device(Platform, reinterpret_cast(Interop)); @@ -147,7 +171,7 @@ T make(const platform &Platform, /// template ::value>::type * = nullptr> -__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_context free function") +__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_context free function") T make(const std::vector &DeviceList, typename interop::type Interop, ownership Ownership = ownership::transfer) { @@ -158,6 +182,7 @@ T make(const std::vector &DeviceList, // Construction of SYCL program. template ::value> * = nullptr> +__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_kernel_bundle free function") T make(const context &Context, typename interop::type Interop) { return make_program(Context, reinterpret_cast(Interop)); @@ -166,6 +191,7 @@ T make(const context &Context, // Construction of SYCL queue. template ::value> * = nullptr> +__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_queue free function") T make(const context &Context, typename interop::type Interop, ownership Ownership = ownership::transfer) { @@ -176,6 +202,7 @@ T make(const context &Context, // Construction of SYCL event. template ::value> * = nullptr> +__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_event free function") T make(const context &Context, typename interop::type Interop, ownership Ownership = ownership::transfer) { @@ -197,9 +224,46 @@ context make_context( BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep); } +// Specialization of sycl::make_queue for Level-Zero backend. +template <> +queue make_queue( + const backend_input_t &BackendObject, + const context &TargetContext, const async_handler Handler) { + return ext::oneapi::level_zero::make_queue( + TargetContext, + detail::pi::cast(BackendObject.NativeHandle), + BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep); +} + +// Specialization of sycl::make_event for Level-Zero backend. +template <> +event make_event( + const backend_input_t &BackendObject, + const context &TargetContext) { + return ext::oneapi::level_zero::make_event( + TargetContext, + detail::pi::cast(BackendObject.NativeHandle), + BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep); +} + +// TODO: remove this specialization when generic is changed to call +// .GetNative() instead of .get_native() member of kernel_bundle. +template <> +auto get_native( + const kernel_bundle &Obj) + -> backend_return_t> { + // TODO use SYCL 2020 exception when implemented + if (Obj.get_backend() != backend::level_zero) + throw runtime_error("Backends mismatch", PI_INVALID_OPERATION); + + return Obj.template getNative(); +} + namespace __SYCL2020_DEPRECATED("use 'ext::oneapi::level_zero' instead") level_zero { using namespace ext::oneapi::level_zero; } + } // namespace sycl } // __SYCL_INLINE_NAMESPACE(cl) diff --git a/sycl/test/basic_tests/interop-level-zero-2020.cpp b/sycl/test/basic_tests/interop-level-zero-2020.cpp index 4e40829cffca3..611e7b2a24cff 100644 --- a/sycl/test/basic_tests/interop-level-zero-2020.cpp +++ b/sycl/test/basic_tests/interop-level-zero-2020.cpp @@ -5,7 +5,7 @@ #include // clang-format off #include -#include +#include // clang-format on using namespace sycl; @@ -15,13 +15,13 @@ using namespace sycl; // platform, // device, // context, +// queue, +// event, +// kernel_bundle, // TODO: // buffer, // device_image, -// event, // kernel, -// kernel_bundle, -// queue, // sampled_image, // unsampled_image. @@ -31,6 +31,12 @@ int main() { device Device; platform Platform = Device.get_info(); context Context(Device); + queue Queue(Device); + event Event; + // expected-warning@+1 {{'program' is deprecated: program class is deprecated, use kernel_bundle instead}} + program Program(Context); + kernel_bundle KernelBundle = + get_kernel_bundle(Context); // 4.5.1.1 For each SYCL runtime class T which supports SYCL application // interoperability with the SYCL backend, a specialization of return_type @@ -46,6 +52,14 @@ int main() { backend_traits::return_type ZeDevice; backend_traits::return_type ZeContext; + backend_traits::return_type ZeQueue; + backend_traits::return_type ZeEvent; + // expected-warning@+1 {{'program' is deprecated: program class is deprecated, use kernel_bundle instead}} + backend_traits::return_type + ZeProgram; + backend_traits::return_type< + kernel_bundle> + ZeKernelBundle; // 4.5.1.2 For each SYCL runtime class T which supports SYCL application // interoperability, a specialization of get_native must be defined, which @@ -57,17 +71,33 @@ int main() { ZeDriver = get_native(Platform); ZeDevice = get_native(Device); ZeContext = get_native(Context); + ZeQueue = get_native(Queue); + ZeEvent = get_native(Event); + ZeKernelBundle = get_native(KernelBundle); // Check deprecated - // expected-warning@+2 {{'get_native' is deprecated: Use SYCL-2020 sycl::get_native free function}} - // expected-warning@+1 {{'get_native' is deprecated: Use SYCL-2020 sycl::get_native free function}} + // expected-warning@+2 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}} + // expected-warning@+1 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}} ZeDriver = Platform.get_native(); - // expected-warning@+2 {{'get_native' is deprecated: Use SYCL-2020 sycl::get_native free function}} - // expected-warning@+1 {{'get_native' is deprecated: Use SYCL-2020 sycl::get_native free function}} + // expected-warning@+2 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}} + // expected-warning@+1 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}} ZeDevice = Device.get_native(); - // expected-warning@+2 {{'get_native' is deprecated: Use SYCL-2020 sycl::get_native free function}} - // expected-warning@+1 {{'get_native' is deprecated: Use SYCL-2020 sycl::get_native free function}} + // expected-warning@+2 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}} + // expected-warning@+1 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}} ZeContext = Context.get_native(); + // expected-warning@+2 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}} + // expected-warning@+1 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}} + ZeQueue = Queue.get_native(); + // expected-warning@+2 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}} + // expected-warning@+1 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}} + ZeEvent = Event.get_native(); + // expected-warning@+2 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}} + // expected-warning@+1 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}} + ZeProgram = Program.get_native(); + // expected-warning@+3 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}} + // expected-warning@+2 {{'get_native' is deprecated: Use SYCL 2020 sycl::get_native free function}} + /*ZeKernelBundle*/ ( + void)KernelBundle.get_native(); // 4.5.1.1 For each SYCL runtime class T which supports SYCL application // interoperability with the SYCL backend, a specialization of input_type must @@ -101,15 +131,33 @@ int main() { context InteropContext = make_context(InteropContextInput); + queue InteropQueue = make_queue( + {ZeQueue, ext::oneapi::level_zero::ownership::keep}, Context); + event InteropEvent = make_event( + {ZeEvent, ext::oneapi::level_zero::ownership::keep}, Context); + kernel_bundle InteropKernelBundle = + make_kernel_bundle(ZeKernelBundle.front(), + Context); + // Check deprecated - // expected-warning@+1 {{'make' is deprecated: Use SYCL-2020 sycl::make_platform free function}} + // expected-warning@+1 {{'make' is deprecated: Use SYCL 2020 sycl::make_platform free function}} auto P = ext::oneapi::level_zero::make(ZeDriver); - // expected-warning@+1 {{'make' is deprecated: Use SYCL-2020 sycl::make_device free function}} + // expected-warning@+1 {{'make' is deprecated: Use SYCL 2020 sycl::make_device free function}} auto D = ext::oneapi::level_zero::make(P, ZeDevice); - // expected-warning@+1 {{'make' is deprecated: Use SYCL-2020 sycl::make_context free function}} + // expected-warning@+1 {{'make' is deprecated: Use SYCL 2020 sycl::make_context free function}} auto C = ext::oneapi::level_zero::make( std::vector(1, D), ZeContext, ext::oneapi::level_zero::ownership::keep); + // expected-warning@+1 {{'make' is deprecated: Use SYCL 2020 sycl::make_queue free function}} + auto Q = ext::oneapi::level_zero::make( + Context, ZeQueue, ext::oneapi::level_zero::ownership::keep); + // expected-warning@+1 {{'make' is deprecated: Use SYCL 2020 sycl::make_event free function}} + auto E = ext::oneapi::level_zero::make( + Context, ZeEvent, ext::oneapi::level_zero::ownership::keep); + // expected-warning@+2 {{'program' is deprecated: program class is deprecated, use kernel_bundle instead}} + // expected-warning@+1 {{'make' is deprecated: Use SYCL 2020 sycl::make_kernel_bundle free function}} + auto PR = ext::oneapi::level_zero::make(Context, ZeProgram); return 0; }