From 8c01408069d828a22f3190c0f20c9742c4b4e52f Mon Sep 17 00:00:00 2001 From: Sergey V Maslov Date: Wed, 8 Sep 2021 11:59:23 -0700 Subject: [PATCH 1/6] rebase Signed-off-by: Sergey V Maslov --- sycl/include/CL/sycl/backend.hpp | 23 +- sycl/include/CL/sycl/backend/level_zero.hpp | 242 ++++++++++++++++++ sycl/include/CL/sycl/backend/opencl.hpp | 1 + sycl/include/CL/sycl/event.hpp | 2 + sycl/include/CL/sycl/kernel_bundle.hpp | 31 ++- sycl/include/CL/sycl/program.hpp | 1 + sycl/include/CL/sycl/queue.hpp | 3 +- .../sycl/ext/oneapi/backend/level_zero.hpp | 83 ++++-- .../basic_tests/interop-level-zero-2020.cpp | 73 +++++- 9 files changed, 424 insertions(+), 35 deletions(-) diff --git a/sycl/include/CL/sycl/backend.hpp b/sycl/include/CL/sycl/backend.hpp index c4a21266ec1f4..1d153d7a05733 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/level_zero.hpp b/sycl/include/CL/sycl/backend/level_zero.hpp index 8d808fec3e5ee..04cd2ad301a5f 100644 --- a/sycl/include/CL/sycl/backend/level_zero.hpp +++ b/sycl/include/CL/sycl/backend/level_zero.hpp @@ -13,4 +13,246 @@ __SYCL_WARNING("CL/sycl/backend/level_zero.hpp usage is deprecated, include " "sycl/ext/oneapi/backend/level_zero.hpp instead") +<<<<<<< HEAD #include +======= +template <> struct interop { + using type = ze_driver_handle_t; +}; + +template <> struct interop { + using type = ze_device_handle_t; +}; + +template <> struct interop { + using type = ze_context_handle_t; +}; + +template <> struct interop { + using type = ze_command_queue_handle_t; +}; + +template <> struct interop { + using type = ze_event_handle_t; +}; + +template <> struct interop { + using type = ze_module_handle_t; +}; + +template +struct interop> { + using type = char *; +}; + +template +struct interop> { + using type = char *; +}; + +template +struct interop> { + using type = ze_image_handle_t; +}; + +namespace level_zero { +// Since Level-Zero is not doing any reference counting itself, we have to +// be explicit about the ownership of the native handles used in the +// interop functions below. +// +enum class ownership { transfer, keep }; +} // namespace level_zero + +namespace detail { + +template <> struct BackendInput { + using type = struct { + interop::type NativeHandle; + std::vector DeviceList; + level_zero::ownership Ownership; + }; +}; + +template <> struct BackendInput { + using type = struct { + interop::type NativeHandle; + level_zero::ownership Ownership; + }; +}; + +template <> struct BackendInput { + using type = struct { + interop::type NativeHandle; + 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; +}; + +template <> struct InteropFeatureSupportMap { + static constexpr bool MakePlatform = true; + static constexpr bool MakeDevice = true; + static constexpr bool MakeContext = true; + 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; +}; +} // namespace detail + +namespace level_zero { +// Implementation of various "make" functions resides in libsycl.so and thus +// their interface needs to be backend agnostic. +// TODO: remove/merge with similar functions in sycl::detail +__SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle); +__SYCL_EXPORT device make_device(const platform &Platform, + pi_native_handle NativeHandle); +__SYCL_EXPORT context make_context(const std::vector &DeviceList, + pi_native_handle NativeHandle, + bool keep_ownership = false); +__SYCL_EXPORT program make_program(const context &Context, + pi_native_handle NativeHandle); +__SYCL_EXPORT queue make_queue(const context &Context, + pi_native_handle InteropHandle, + bool keep_ownership = false); +__SYCL_EXPORT event make_event(const context &Context, + pi_native_handle InteropHandle, + bool keep_ownership = false); + +// Construction of SYCL platform. +template ::value> * = nullptr> +__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_platform free function") +T make(typename interop::type Interop) { + return make_platform(reinterpret_cast(Interop)); +} + +// Construction of SYCL device. +template ::value> * = nullptr> +__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)); +} + +/// Construction of SYCL context. +/// \param DeviceList is a vector of devices which must be encapsulated by +/// created SYCL context. Provided devices and native context handle must +/// be associated with the same platform. +/// \param Interop is a Level Zero native context handle. +/// \param Ownership (optional) specifies who will assume ownership of the +/// native context handle. Default is that SYCL RT does, so it destroys +/// the native handle when the created SYCL object goes out of life. +/// +template ::value>::type * = nullptr> +__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_context free function") +T make(const std::vector &DeviceList, + typename interop::type Interop, + ownership Ownership = ownership::transfer) { + return make_context(DeviceList, detail::pi::cast(Interop), + Ownership == ownership::keep); +} + +// 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)); +} + +// 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) { + return make_queue(Context, reinterpret_cast(Interop), + Ownership == ownership::keep); +} + +// 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) { + return make_event(Context, reinterpret_cast(Interop), + Ownership == ownership::keep); +} +} // namespace level_zero + +// Specialization of sycl::make_context for Level-Zero backend. +template <> +context make_context( + const backend_input_t &BackendObject, + const async_handler &Handler) { + return level_zero::make_context( + BackendObject.DeviceList, + detail::pi::cast(BackendObject.NativeHandle), + BackendObject.Ownership == 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 level_zero::make_queue( + TargetContext, + detail::pi::cast(BackendObject.NativeHandle), + BackendObject.Ownership == 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 level_zero::make_event( + TargetContext, + detail::pi::cast(BackendObject.NativeHandle), + BackendObject.Ownership == 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 sycl +} // __SYCL_INLINE_NAMESPACE(cl) +>>>>>>> 6c9a8addf701 ([SYCL] Make Level-Zero interop API SYCL-2020 compliant for queue, event, and kernel_bundle(was program).) diff --git a/sycl/include/CL/sycl/backend/opencl.hpp b/sycl/include/CL/sycl/backend/opencl.hpp index 0c0fc33d3712c..d88e09598883e 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/event.hpp b/sycl/include/CL/sycl/event.hpp index 70e70d13ad28b..edb0c43a049bf 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/kernel_bundle.hpp b/sycl/include/CL/sycl/kernel_bundle.hpp index 8f67aaf1034f4..3b4fd754802dc 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/program.hpp b/sycl/include/CL/sycl/program.hpp index 6b70b47259af4..6a6cfd2de20b7 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..3132dbfb501d6 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..1aaa96870bd9f 100644 --- a/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp +++ b/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp @@ -60,8 +60,6 @@ struct interop struct BackendInput { using type = struct { interop::type NativeHandle; std::vector DeviceList; - ext::oneapi::level_zero::ownership Ownership; + level_zero::ownership Ownership; }; }; +template <> struct BackendInput { + using type = struct { + interop::type NativeHandle; + level_zero::ownership Ownership; + }; +}; + +template <> struct BackendInput { + using type = struct { + interop::type NativeHandle; + 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,16 +110,14 @@ 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 -namespace ext { -namespace oneapi { namespace level_zero { // Implementation of various "make" functions resides in libsycl.so and thus // their interface needs to be backend agnostic. @@ -158,6 +176,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 +185,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 +196,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) { @@ -183,23 +204,53 @@ T make(const context &Context, Ownership == ownership::keep); } } // namespace level_zero -} // namespace oneapi -} // namespace ext // Specialization of sycl::make_context for Level-Zero backend. template <> context make_context( const backend_input_t &BackendObject, const async_handler &Handler) { - return ext::oneapi::level_zero::make_context( + return level_zero::make_context( BackendObject.DeviceList, detail::pi::cast(BackendObject.NativeHandle), - BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep); + BackendObject.Ownership == 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 level_zero::make_queue( + TargetContext, + detail::pi::cast(BackendObject.NativeHandle), + BackendObject.Ownership == 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 level_zero::make_event( + TargetContext, + detail::pi::cast(BackendObject.NativeHandle), + BackendObject.Ownership == level_zero::ownership::keep); } -namespace __SYCL2020_DEPRECATED("use 'ext::oneapi::level_zero' instead") - level_zero { - using namespace ext::oneapi::level_zero; +// 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 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..90ee77300d9fc 100644 --- a/sycl/test/basic_tests/interop-level-zero-2020.cpp +++ b/sycl/test/basic_tests/interop-level-zero-2020.cpp @@ -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 @@ -41,11 +47,24 @@ int main() { // return_type is used when retrieving the backend specific native object from // a SYCL object. See the relevant backend specification for details. +<<<<<<< HEAD backend_traits::return_type ZeDriver; backend_traits::return_type ZeDevice; backend_traits::return_type ZeContext; +======= + backend_traits::return_type ZeDriver; + 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; +>>>>>>> 6c9a8addf701 ([SYCL] Make Level-Zero interop API SYCL-2020 compliant for queue, event, and kernel_bundle(was program).) // 4.5.1.2 For each SYCL runtime class T which supports SYCL application // interoperability, a specialization of get_native must be defined, which @@ -54,9 +73,18 @@ int main() { // application interoperability. The lifetime of the object returned are // backend-defined and specified in the backend specification. +<<<<<<< HEAD ZeDriver = get_native(Platform); ZeDevice = get_native(Device); ZeContext = get_native(Context); +======= + ZeDriver = get_native(Platform); + ZeDevice = get_native(Device); + ZeContext = get_native(Context); + ZeQueue = get_native(Queue); + ZeEvent = get_native(Event); + ZeKernelBundle = get_native(KernelBundle); +>>>>>>> 6c9a8addf701 ([SYCL] Make Level-Zero interop API SYCL-2020 compliant for queue, event, and kernel_bundle(was program).) // Check deprecated // expected-warning@+2 {{'get_native' is deprecated: Use SYCL-2020 sycl::get_native free function}} @@ -66,8 +94,25 @@ int main() { // 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}} +<<<<<<< HEAD // expected-warning@+1 {{'get_native' is deprecated: Use SYCL-2020 sycl::get_native free function}} ZeContext = Context.get_native(); +======= + // 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@+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}} + /*ZeKernelBundle*/ (void)KernelBundle.get_native(); +>>>>>>> 6c9a8addf701 ([SYCL] Make Level-Zero interop API SYCL-2020 compliant for queue, event, and kernel_bundle(was program).) // 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 +146,37 @@ int main() { context InteropContext = make_context(InteropContextInput); + queue InteropQueue = make_queue( + {ZeQueue, level_zero::ownership::keep}, Context); + event InteropEvent = make_event( + {ZeEvent, 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}} auto P = ext::oneapi::level_zero::make(ZeDriver); // 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}} +<<<<<<< HEAD auto C = ext::oneapi::level_zero::make( std::vector(1, D), ZeContext, ext::oneapi::level_zero::ownership::keep); +======= + auto C = level_zero::make(std::vector(1, D), ZeContext, + level_zero::ownership::keep); + // expected-warning@+1 {{'make' is deprecated: Use SYCL-2020 sycl::make_queue free function}} + auto Q = + level_zero::make(Context, ZeQueue, level_zero::ownership::keep); + // expected-warning@+1 {{'make' is deprecated: Use SYCL-2020 sycl::make_event free function}} + auto E = + level_zero::make(Context, ZeEvent, 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 = level_zero::make(Context, ZeProgram); +>>>>>>> 6c9a8addf701 ([SYCL] Make Level-Zero interop API SYCL-2020 compliant for queue, event, and kernel_bundle(was program).) return 0; } From ca26fac4a83ea920dcef9153995e0940369c2480 Mon Sep 17 00:00:00 2001 From: Sergey V Maslov Date: Wed, 8 Sep 2021 09:08:04 -0700 Subject: [PATCH 2/6] address review comments Signed-off-by: Sergey V Maslov --- sycl/include/CL/sycl/backend.hpp | 4 ++-- sycl/include/CL/sycl/backend/level_zero.hpp | 12 ++++++------ sycl/include/CL/sycl/backend/opencl.hpp | 2 +- sycl/include/CL/sycl/context.hpp | 2 +- sycl/include/CL/sycl/device.hpp | 2 +- sycl/include/CL/sycl/event.hpp | 2 +- sycl/include/CL/sycl/interop_handle.hpp | 6 +++--- sycl/include/CL/sycl/kernel_bundle.hpp | 2 +- sycl/include/CL/sycl/platform.hpp | 2 +- sycl/include/CL/sycl/program.hpp | 2 +- sycl/include/CL/sycl/queue.hpp | 2 +- sycl/test/basic_tests/interop-level-zero-2020.cpp | 4 ++-- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/sycl/include/CL/sycl/backend.hpp b/sycl/include/CL/sycl/backend.hpp index 1d153d7a05733..9a1fd0e007932 100644 --- a/sycl/include/CL/sycl/backend.hpp +++ b/sycl/include/CL/sycl/backend.hpp @@ -146,7 +146,7 @@ make_context( } template -__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_queue free function") +__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_queue free function") typename std::enable_if< detail::InteropFeatureSupportMap::MakeQueue == true, queue>::type make_queue( @@ -179,7 +179,7 @@ make_event(const typename backend_traits::template input_type } template -__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_event free function") +__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_event free function") typename std::enable_if< detail::InteropFeatureSupportMap::MakeEvent == true, event>::type make_event( diff --git a/sycl/include/CL/sycl/backend/level_zero.hpp b/sycl/include/CL/sycl/backend/level_zero.hpp index 04cd2ad301a5f..603f8153252e6 100644 --- a/sycl/include/CL/sycl/backend/level_zero.hpp +++ b/sycl/include/CL/sycl/backend/level_zero.hpp @@ -141,7 +141,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)); } @@ -149,7 +149,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)); @@ -166,7 +166,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) { @@ -177,7 +177,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") +__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)); @@ -186,7 +186,7 @@ T make(const context &Context, // Construction of SYCL queue. template ::value> * = nullptr> -__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_queue free function") +__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_queue free function") T make(const context &Context, typename interop::type Interop, ownership Ownership = ownership::transfer) { @@ -197,7 +197,7 @@ T make(const context &Context, // Construction of SYCL event. template ::value> * = nullptr> -__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_event free function") +__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_event free function") T make(const context &Context, typename interop::type Interop, ownership Ownership = ownership::transfer) { diff --git a/sycl/include/CL/sycl/backend/opencl.hpp b/sycl/include/CL/sycl/backend/opencl.hpp index d88e09598883e..c051ca0f0a4ce 100644 --- a/sycl/include/CL/sycl/backend/opencl.hpp +++ b/sycl/include/CL/sycl/backend/opencl.hpp @@ -75,7 +75,7 @@ struct BackendInput> { template struct BackendReturn> { - // TODO: Per SYCL-2020 this should be std::vector + // 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 edb0c43a049bf..7b01a4bc78540 100644 --- a/sycl/include/CL/sycl/event.hpp +++ b/sycl/include/CL/sycl/event.hpp @@ -129,7 +129,7 @@ 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") + __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/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 3b4fd754802dc..21398c232aa9e 100644 --- a/sycl/include/CL/sycl/kernel_bundle.hpp +++ b/sycl/include/CL/sycl/kernel_bundle.hpp @@ -310,7 +310,7 @@ class kernel_bundle : public detail::kernel_bundle_plain { } template - __SYCL_DEPRECATED("Use SYCL-2020 sycl::get_native free function") + __SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function") std::vector::template return_type< kernel_bundle>> get_native() { std::vector::template return_type< 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 6a6cfd2de20b7..7973ff03cf273 100644 --- a/sycl/include/CL/sycl/program.hpp +++ b/sycl/include/CL/sycl/program.hpp @@ -365,7 +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") + __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 3132dbfb501d6..0df54566d1b46 100644 --- a/sycl/include/CL/sycl/queue.hpp +++ b/sycl/include/CL/sycl/queue.hpp @@ -1020,7 +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") + __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/test/basic_tests/interop-level-zero-2020.cpp b/sycl/test/basic_tests/interop-level-zero-2020.cpp index 90ee77300d9fc..8d9f422ff272f 100644 --- a/sycl/test/basic_tests/interop-level-zero-2020.cpp +++ b/sycl/test/basic_tests/interop-level-zero-2020.cpp @@ -167,10 +167,10 @@ int main() { ======= auto C = level_zero::make(std::vector(1, D), ZeContext, level_zero::ownership::keep); - // expected-warning@+1 {{'make' is deprecated: Use SYCL-2020 sycl::make_queue free function}} + // expected-warning@+2 {{'make' is deprecated: Use SYCL-2020 sycl::make_queue free function}} auto Q = level_zero::make(Context, ZeQueue, level_zero::ownership::keep); - // expected-warning@+1 {{'make' is deprecated: Use SYCL-2020 sycl::make_event free function}} + // expected-warning@+2 {{'make' is deprecated: Use SYCL-2020 sycl::make_event free function}} auto E = level_zero::make(Context, ZeEvent, level_zero::ownership::keep); // expected-warning@+2 {{'program' is deprecated: program class is deprecated, use kernel_bundle instead}} From 20c49d848060fd5daf7e156204b820e567ebcc51 Mon Sep 17 00:00:00 2001 From: Sergey V Maslov Date: Wed, 8 Sep 2021 12:23:11 -0700 Subject: [PATCH 3/6] rebase Signed-off-by: Sergey V Maslov --- .../sycl/ext/oneapi/backend/level_zero.hpp | 12 +- .../basic_tests/interop-level-zero-2020.cpp | 104 +++++++----------- 2 files changed, 48 insertions(+), 68 deletions(-) diff --git a/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp b/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp index 1aaa96870bd9f..7358cb15301a8 100644 --- a/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp +++ b/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp @@ -140,7 +140,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)); } @@ -148,7 +148,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)); @@ -165,7 +165,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) { @@ -176,7 +176,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") +__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)); @@ -185,7 +185,7 @@ T make(const context &Context, // Construction of SYCL queue. template ::value> * = nullptr> -__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_queue free function") +__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_queue free function") T make(const context &Context, typename interop::type Interop, ownership Ownership = ownership::transfer) { @@ -196,7 +196,7 @@ T make(const context &Context, // Construction of SYCL event. template ::value> * = nullptr> -__SYCL_DEPRECATED("Use SYCL-2020 sycl::make_event free function") +__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_event free function") T make(const context &Context, typename interop::type Interop, ownership Ownership = ownership::transfer) { diff --git a/sycl/test/basic_tests/interop-level-zero-2020.cpp b/sycl/test/basic_tests/interop-level-zero-2020.cpp index 8d9f422ff272f..e2e2317bf28ed 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; @@ -47,24 +47,19 @@ int main() { // return_type is used when retrieving the backend specific native object from // a SYCL object. See the relevant backend specification for details. -<<<<<<< HEAD backend_traits::return_type ZeDriver; backend_traits::return_type ZeDevice; backend_traits::return_type ZeContext; -======= - backend_traits::return_type ZeDriver; - backend_traits::return_type ZeDevice; - backend_traits::return_type ZeContext; - backend_traits::return_type ZeQueue; - backend_traits::return_type ZeEvent; + 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< + backend_traits::return_type + ZeProgram; + backend_traits::return_type< kernel_bundle> ZeKernelBundle; ->>>>>>> 6c9a8addf701 ([SYCL] Make Level-Zero interop API SYCL-2020 compliant for queue, event, and kernel_bundle(was program).) // 4.5.1.2 For each SYCL runtime class T which supports SYCL application // interoperability, a specialization of get_native must be defined, which @@ -73,46 +68,36 @@ int main() { // application interoperability. The lifetime of the object returned are // backend-defined and specified in the backend specification. -<<<<<<< HEAD ZeDriver = get_native(Platform); ZeDevice = get_native(Device); ZeContext = get_native(Context); -======= - ZeDriver = get_native(Platform); - ZeDevice = get_native(Device); - ZeContext = get_native(Context); - ZeQueue = get_native(Queue); - ZeEvent = get_native(Event); - ZeKernelBundle = get_native(KernelBundle); ->>>>>>> 6c9a8addf701 ([SYCL] Make Level-Zero interop API SYCL-2020 compliant for queue, event, and kernel_bundle(was program).) + 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}} -<<<<<<< HEAD - // 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@+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@+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}} - /*ZeKernelBundle*/ (void)KernelBundle.get_native(); ->>>>>>> 6c9a8addf701 ([SYCL] Make Level-Zero interop API SYCL-2020 compliant for queue, event, and kernel_bundle(was program).) + // 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@+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}} + /*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 @@ -142,41 +127,36 @@ int main() { backend_input_t InteropContextInput{ ZeContext, std::vector(1, InteropDevice), - ext::oneapi::level_zero::ownership::keep}; + level_zero::ownership::keep}; context InteropContext = make_context(InteropContextInput); - queue InteropQueue = make_queue( + queue InteropQueue = make_queue( {ZeQueue, level_zero::ownership::keep}, Context); - event InteropEvent = make_event( + event InteropEvent = make_event( {ZeEvent, level_zero::ownership::keep}, Context); kernel_bundle InteropKernelBundle = - make_kernel_bundle( - ZeKernelBundle.front(), Context); + make_kernel_bundle(ZeKernelBundle.front(), + Context); // Check deprecated - // 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}} - auto D = ext::oneapi::level_zero::make(P, ZeDevice); - // expected-warning@+1 {{'make' is deprecated: Use SYCL-2020 sycl::make_context free function}} -<<<<<<< HEAD - 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_platform free function}} + auto P = level_zero::make(ZeDriver); + // expected-warning@+1 {{'make' is deprecated: Use SYCL 2020 sycl::make_device free function}} + auto D = level_zero::make(P, ZeDevice); + // expected-warning@+1 {{'make' is deprecated: Use SYCL 2020 sycl::make_context free function}} auto C = level_zero::make(std::vector(1, D), ZeContext, level_zero::ownership::keep); - // expected-warning@+2 {{'make' is deprecated: Use SYCL-2020 sycl::make_queue free function}} + // expected-warning@+2 {{'make' is deprecated: Use SYCL 2020 sycl::make_queue free function}} auto Q = level_zero::make(Context, ZeQueue, level_zero::ownership::keep); - // expected-warning@+2 {{'make' is deprecated: Use SYCL-2020 sycl::make_event free function}} + // expected-warning@+2 {{'make' is deprecated: Use SYCL 2020 sycl::make_event free function}} auto E = level_zero::make(Context, ZeEvent, 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}} + // expected-warning@+1 {{'make' is deprecated: Use SYCL 2020 sycl::make_kernel_bundle free function}} auto PR = level_zero::make(Context, ZeProgram); ->>>>>>> 6c9a8addf701 ([SYCL] Make Level-Zero interop API SYCL-2020 compliant for queue, event, and kernel_bundle(was program).) return 0; } From c8567c7d1554f515428c88f22295a05313f7a9ab Mon Sep 17 00:00:00 2001 From: Sergey V Maslov Date: Wed, 8 Sep 2021 12:47:37 -0700 Subject: [PATCH 4/6] rebase Signed-off-by: Sergey V Maslov --- .../sycl/ext/oneapi/backend/level_zero.hpp | 26 ++++++++++----- .../basic_tests/interop-level-zero-2020.cpp | 33 ++++++++++--------- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp b/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp index 7358cb15301a8..4a6cfe1f78b37 100644 --- a/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp +++ b/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp @@ -60,6 +60,8 @@ struct interop struct BackendInput { using type = struct { interop::type NativeHandle; std::vector DeviceList; - level_zero::ownership Ownership; + ext::oneapi::level_zero::ownership Ownership; }; }; template <> struct BackendInput { using type = struct { interop::type NativeHandle; - level_zero::ownership Ownership; + ext::oneapi::level_zero::ownership Ownership; }; }; template <> struct BackendInput { using type = struct { interop::type NativeHandle; - level_zero::ownership Ownership; + ext::oneapi::level_zero::ownership Ownership; }; }; @@ -118,6 +122,8 @@ template <> struct InteropFeatureSupportMap { }; } // namespace detail +namespace ext { +namespace oneapi { namespace level_zero { // Implementation of various "make" functions resides in libsycl.so and thus // their interface needs to be backend agnostic. @@ -204,16 +210,18 @@ T make(const context &Context, Ownership == ownership::keep); } } // namespace level_zero +} // namespace oneapi +} // namespace ext // Specialization of sycl::make_context for Level-Zero backend. template <> context make_context( const backend_input_t &BackendObject, const async_handler &Handler) { - return level_zero::make_context( + return ext::oneapi::level_zero::make_context( BackendObject.DeviceList, detail::pi::cast(BackendObject.NativeHandle), - BackendObject.Ownership == level_zero::ownership::keep); + BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep); } // Specialization of sycl::make_queue for Level-Zero backend. @@ -221,10 +229,10 @@ template <> queue make_queue( const backend_input_t &BackendObject, const context &TargetContext, const async_handler Handler) { - return level_zero::make_queue( + return ext::oneapi::level_zero::make_queue( TargetContext, detail::pi::cast(BackendObject.NativeHandle), - BackendObject.Ownership == level_zero::ownership::keep); + BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep); } // Specialization of sycl::make_event for Level-Zero backend. @@ -232,10 +240,10 @@ template <> event make_event( const backend_input_t &BackendObject, const context &TargetContext) { - return level_zero::make_event( + return ext::oneapi::level_zero::make_event( TargetContext, detail::pi::cast(BackendObject.NativeHandle), - BackendObject.Ownership == level_zero::ownership::keep); + BackendObject.Ownership == ext::oneapi::level_zero::ownership::keep); } // TODO: remove this specialization when generic is changed to call diff --git a/sycl/test/basic_tests/interop-level-zero-2020.cpp b/sycl/test/basic_tests/interop-level-zero-2020.cpp index e2e2317bf28ed..611e7b2a24cff 100644 --- a/sycl/test/basic_tests/interop-level-zero-2020.cpp +++ b/sycl/test/basic_tests/interop-level-zero-2020.cpp @@ -94,8 +94,8 @@ int main() { // 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@+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@+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(); @@ -127,14 +127,14 @@ int main() { backend_input_t InteropContextInput{ ZeContext, std::vector(1, InteropDevice), - level_zero::ownership::keep}; + ext::oneapi::level_zero::ownership::keep}; context InteropContext = make_context(InteropContextInput); queue InteropQueue = make_queue( - {ZeQueue, level_zero::ownership::keep}, Context); + {ZeQueue, ext::oneapi::level_zero::ownership::keep}, Context); event InteropEvent = make_event( - {ZeEvent, level_zero::ownership::keep}, Context); + {ZeEvent, ext::oneapi::level_zero::ownership::keep}, Context); kernel_bundle InteropKernelBundle = make_kernel_bundle(ZeKernelBundle.front(), @@ -142,21 +142,22 @@ int main() { // Check deprecated // expected-warning@+1 {{'make' is deprecated: Use SYCL 2020 sycl::make_platform free function}} - auto P = level_zero::make(ZeDriver); + auto P = ext::oneapi::level_zero::make(ZeDriver); // expected-warning@+1 {{'make' is deprecated: Use SYCL 2020 sycl::make_device free function}} - auto D = level_zero::make(P, ZeDevice); + auto D = ext::oneapi::level_zero::make(P, ZeDevice); // expected-warning@+1 {{'make' is deprecated: Use SYCL 2020 sycl::make_context free function}} - auto C = level_zero::make(std::vector(1, D), ZeContext, - level_zero::ownership::keep); - // expected-warning@+2 {{'make' is deprecated: Use SYCL 2020 sycl::make_queue free function}} - auto Q = - level_zero::make(Context, ZeQueue, level_zero::ownership::keep); - // expected-warning@+2 {{'make' is deprecated: Use SYCL 2020 sycl::make_event free function}} - auto E = - level_zero::make(Context, ZeEvent, level_zero::ownership::keep); + 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 = level_zero::make(Context, ZeProgram); + auto PR = ext::oneapi::level_zero::make(Context, ZeProgram); return 0; } From 33f7bb5de86d79d4ee78d30da94f51caf1cb112a Mon Sep 17 00:00:00 2001 From: Sergey V Maslov Date: Wed, 8 Sep 2021 12:57:18 -0700 Subject: [PATCH 5/6] rebase Signed-off-by: Sergey V Maslov --- sycl/include/CL/sycl/backend/level_zero.hpp | 242 -------------------- 1 file changed, 242 deletions(-) diff --git a/sycl/include/CL/sycl/backend/level_zero.hpp b/sycl/include/CL/sycl/backend/level_zero.hpp index 603f8153252e6..8d808fec3e5ee 100644 --- a/sycl/include/CL/sycl/backend/level_zero.hpp +++ b/sycl/include/CL/sycl/backend/level_zero.hpp @@ -13,246 +13,4 @@ __SYCL_WARNING("CL/sycl/backend/level_zero.hpp usage is deprecated, include " "sycl/ext/oneapi/backend/level_zero.hpp instead") -<<<<<<< HEAD #include -======= -template <> struct interop { - using type = ze_driver_handle_t; -}; - -template <> struct interop { - using type = ze_device_handle_t; -}; - -template <> struct interop { - using type = ze_context_handle_t; -}; - -template <> struct interop { - using type = ze_command_queue_handle_t; -}; - -template <> struct interop { - using type = ze_event_handle_t; -}; - -template <> struct interop { - using type = ze_module_handle_t; -}; - -template -struct interop> { - using type = char *; -}; - -template -struct interop> { - using type = char *; -}; - -template -struct interop> { - using type = ze_image_handle_t; -}; - -namespace level_zero { -// Since Level-Zero is not doing any reference counting itself, we have to -// be explicit about the ownership of the native handles used in the -// interop functions below. -// -enum class ownership { transfer, keep }; -} // namespace level_zero - -namespace detail { - -template <> struct BackendInput { - using type = struct { - interop::type NativeHandle; - std::vector DeviceList; - level_zero::ownership Ownership; - }; -}; - -template <> struct BackendInput { - using type = struct { - interop::type NativeHandle; - level_zero::ownership Ownership; - }; -}; - -template <> struct BackendInput { - using type = struct { - interop::type NativeHandle; - 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; -}; - -template <> struct InteropFeatureSupportMap { - static constexpr bool MakePlatform = true; - static constexpr bool MakeDevice = true; - static constexpr bool MakeContext = true; - 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; -}; -} // namespace detail - -namespace level_zero { -// Implementation of various "make" functions resides in libsycl.so and thus -// their interface needs to be backend agnostic. -// TODO: remove/merge with similar functions in sycl::detail -__SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle); -__SYCL_EXPORT device make_device(const platform &Platform, - pi_native_handle NativeHandle); -__SYCL_EXPORT context make_context(const std::vector &DeviceList, - pi_native_handle NativeHandle, - bool keep_ownership = false); -__SYCL_EXPORT program make_program(const context &Context, - pi_native_handle NativeHandle); -__SYCL_EXPORT queue make_queue(const context &Context, - pi_native_handle InteropHandle, - bool keep_ownership = false); -__SYCL_EXPORT event make_event(const context &Context, - pi_native_handle InteropHandle, - bool keep_ownership = false); - -// Construction of SYCL platform. -template ::value> * = nullptr> -__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_platform free function") -T make(typename interop::type Interop) { - return make_platform(reinterpret_cast(Interop)); -} - -// Construction of SYCL device. -template ::value> * = nullptr> -__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)); -} - -/// Construction of SYCL context. -/// \param DeviceList is a vector of devices which must be encapsulated by -/// created SYCL context. Provided devices and native context handle must -/// be associated with the same platform. -/// \param Interop is a Level Zero native context handle. -/// \param Ownership (optional) specifies who will assume ownership of the -/// native context handle. Default is that SYCL RT does, so it destroys -/// the native handle when the created SYCL object goes out of life. -/// -template ::value>::type * = nullptr> -__SYCL_DEPRECATED("Use SYCL 2020 sycl::make_context free function") -T make(const std::vector &DeviceList, - typename interop::type Interop, - ownership Ownership = ownership::transfer) { - return make_context(DeviceList, detail::pi::cast(Interop), - Ownership == ownership::keep); -} - -// 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)); -} - -// 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) { - return make_queue(Context, reinterpret_cast(Interop), - Ownership == ownership::keep); -} - -// 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) { - return make_event(Context, reinterpret_cast(Interop), - Ownership == ownership::keep); -} -} // namespace level_zero - -// Specialization of sycl::make_context for Level-Zero backend. -template <> -context make_context( - const backend_input_t &BackendObject, - const async_handler &Handler) { - return level_zero::make_context( - BackendObject.DeviceList, - detail::pi::cast(BackendObject.NativeHandle), - BackendObject.Ownership == 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 level_zero::make_queue( - TargetContext, - detail::pi::cast(BackendObject.NativeHandle), - BackendObject.Ownership == 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 level_zero::make_event( - TargetContext, - detail::pi::cast(BackendObject.NativeHandle), - BackendObject.Ownership == 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 sycl -} // __SYCL_INLINE_NAMESPACE(cl) ->>>>>>> 6c9a8addf701 ([SYCL] Make Level-Zero interop API SYCL-2020 compliant for queue, event, and kernel_bundle(was program).) From f906788735e2d680c2751857f26eafc196478c7c Mon Sep 17 00:00:00 2001 From: Sergey V Maslov Date: Fri, 10 Sep 2021 09:24:24 -0700 Subject: [PATCH 6/6] address review comments Signed-off-by: Sergey V Maslov --- sycl/include/sycl/ext/oneapi/backend/level_zero.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp b/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp index 4a6cfe1f78b37..9cc87f424326e 100644 --- a/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp +++ b/sycl/include/sycl/ext/oneapi/backend/level_zero.hpp @@ -260,5 +260,10 @@ auto get_native( 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)