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