DPC++ Runtime
Runtime libraries for oneAPI DPC++
backend_traits_level_zero.hpp
Go to the documentation of this file.
1 //===---- backend_traits_level_zero.hpp - Backend traits for Level Zero ---===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the specializations of the sycl::detail::interop,
10 // sycl::detail::BackendInput, sycl::detail::BackendReturn and
11 // sycl::detail::InteropFeatureSupportMap class templates for the Level Zero
12 // backend.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #pragma once
17 
18 #include <CL/sycl/accessor.hpp>
19 #include <CL/sycl/context.hpp>
22 #include <CL/sycl/device.hpp>
23 #include <CL/sycl/event.hpp>
25 #include <CL/sycl/queue.hpp>
28 
29 typedef struct _ze_command_queue_handle_t *ze_command_queue_handle_t;
30 typedef struct _ze_context_handle_t *ze_context_handle_t;
31 typedef struct _ze_device_handle_t *ze_device_handle_t;
32 typedef struct _ze_driver_handle_t *ze_driver_handle_t;
33 typedef struct _ze_event_handle_t *ze_event_handle_t;
34 typedef struct _ze_image_handle_t *ze_image_handle_t;
35 typedef struct _ze_kernel_handle_t *ze_kernel_handle_t;
36 typedef struct _ze_module_handle_t *ze_module_handle_t;
37 
39 namespace sycl {
40 namespace detail {
41 
42 // Forward declarations
43 class device_impl;
44 
45 // TODO the interops for context, device, event, platform and program
46 // may be removed after removing the deprecated 'get_native()' methods
47 // from the corresponding classes. The interop<backend, queue> specialization
48 // is also used in the get_queue() method of the deprecated class
49 // interop_handler and also can be removed after API cleanup.
52 };
53 
56 };
57 
58 template <> struct interop<backend::ext_oneapi_level_zero, event> {
60 };
61 
62 template <> struct interop<backend::ext_oneapi_level_zero, queue> {
64 };
65 
68 };
69 
70 #ifdef __SYCL_INTERNAL_API
71 template <> struct interop<backend::ext_oneapi_level_zero, program> {
72  using type = ze_module_handle_t;
73 };
74 #endif
75 
76 // TODO the interops for accessor is used in the already deprecated class
77 // interop_handler and can be removed after API cleanup.
78 template <typename DataT, int Dimensions, access::mode AccessMode>
80  accessor<DataT, Dimensions, AccessMode, access::target::device,
81  access::placeholder::false_t>> {
82  using type = char *;
83 };
84 
85 template <typename DataT, int Dimensions, access::mode AccessMode>
86 struct interop<
88  accessor<DataT, Dimensions, AccessMode, access::target::constant_buffer,
89  access::placeholder::false_t>> {
90  using type = char *;
91 };
92 
93 template <typename DataT, int Dimensions, access::mode AccessMode>
95  accessor<DataT, Dimensions, AccessMode, access::target::image,
96  access::placeholder::false_t>> {
98 };
99 
102 };
103 
105  struct type {
107  std::vector<device> DeviceList;
109  ext::oneapi::level_zero::ownership::transfer};
110  };
111 };
112 
115 };
116 
119 };
120 
123 };
124 
126  struct type {
129  ext::oneapi::level_zero::ownership::transfer};
130  };
131 };
132 
135 };
136 
138  OptionalDevice() : DeviceImpl(nullptr) {}
139  OptionalDevice(device dev) : DeviceImpl(getSyclObjImpl(dev)) {}
140 
141  operator device() const {
142  if (!DeviceImpl)
143  throw runtime_error("No device has been set.", PI_INVALID_DEVICE);
144  return createSyclObjFromImpl<device>(DeviceImpl);
145  }
146 
148  DeviceImpl = Other.DeviceImpl;
149  return *this;
150  }
152  DeviceImpl = getSyclObjImpl(Other);
153  return *this;
154  }
155 
156 private:
157  std::shared_ptr<device_impl> DeviceImpl;
158 
159  friend bool OptionalDeviceHasDevice(const OptionalDevice &Dev);
160 };
161 
162 // Inspector function in the detail namespace to avoid exposing
163 // OptionalDevice::hasDevice to user-space.
164 inline bool OptionalDeviceHasDevice(const OptionalDevice &Dev) {
165  return Dev.DeviceImpl != nullptr;
166 }
167 
169  struct type {
172 
173  // TODO: Change this to be device when the deprecated constructor is
174  // removed.
176 
178  : Ownership(ext::oneapi::level_zero::ownership::transfer), Device() {}
179 
180  __SYCL_DEPRECATED("Use backend_input_t<backend::ext_oneapi_level_zero, "
181  "queue> constructor with device parameter")
182  type(interop<backend::ext_oneapi_level_zero, queue>::type nativeHandle,
183  ext::oneapi::level_zero::ownership ownership =
184  ext::oneapi::level_zero::ownership::transfer)
185  : NativeHandle(nativeHandle), Ownership(ownership), Device() {}
186 
188  device dev,
190  ext::oneapi::level_zero::ownership::transfer)
191  : NativeHandle(nativeHandle), Ownership(ownership), Device(dev) {}
192  };
193 };
194 
195 template <typename DataT, int Dimensions, typename AllocatorT>
197  buffer<DataT, Dimensions, AllocatorT>> {
198  struct type {
201  ext::oneapi::level_zero::ownership::transfer};
202  };
203 };
204 
205 template <typename DataT, int Dimensions, typename AllocatorT>
207  buffer<DataT, Dimensions, AllocatorT>> {
208  using type = void *;
209 };
210 
213 };
214 
217 };
218 
221 };
222 
223 #ifdef __SYCL_INTERNAL_API
224 template <> struct BackendInput<backend::ext_oneapi_level_zero, program> {
225  using type = ze_module_handle_t;
226 };
227 
228 template <> struct BackendReturn<backend::ext_oneapi_level_zero, program> {
229  using type = ze_module_handle_t;
230 };
231 #endif
232 
233 template <bundle_state State>
235  struct type {
238  ext::oneapi::level_zero::ownership::transfer};
239  };
240 };
241 
242 template <bundle_state State>
244  using type = std::vector<ze_module_handle_t>;
245 };
246 
248  struct type {
252  ext::oneapi::level_zero::ownership::transfer};
253  };
254 };
255 
258 };
259 
261  static constexpr bool MakePlatform = true;
262  static constexpr bool MakeDevice = true;
263  static constexpr bool MakeContext = true;
264  static constexpr bool MakeQueue = true;
265  static constexpr bool MakeEvent = true;
266  static constexpr bool MakeKernelBundle = true;
267  static constexpr bool MakeKernel = true;
268  static constexpr bool MakeBuffer = true;
269 };
270 
271 } // namespace detail
272 } // namespace sycl
273 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::backend
backend
Definition: backend_types.hpp:21
ze_image_handle_t
struct _ze_image_handle_t * ze_image_handle_t
Definition: backend_traits_level_zero.hpp:34
cl::sycl::detail::OptionalDevice::OptionalDevice
OptionalDevice(device dev)
Definition: backend_traits_level_zero.hpp:139
cl::sycl::detail::BackendReturn< backend::ext_oneapi_level_zero, kernel_bundle< State > >::type
std::vector< ze_module_handle_t > type
Definition: backend_traits_level_zero.hpp:244
cl::sycl::kernel_bundle
The kernel_bundle class represents collection of device images in a particular state.
Definition: kernel.hpp:28
cl::sycl::detail::BackendInput< backend::ext_oneapi_level_zero, queue >::type::NativeHandle
interop< backend::ext_oneapi_level_zero, queue >::type NativeHandle
Definition: backend_traits_level_zero.hpp:170
cl::sycl::event
An event object can be used to synchronize memory transfers, enqueues of kernels and signaling barrie...
Definition: event.hpp:31
ze_module_handle_t
struct _ze_module_handle_t * ze_module_handle_t
Definition: backend_traits_level_zero.hpp:36
cl::sycl::detail::BackendReturn< backend::ext_oneapi_level_zero, platform >::type
ze_driver_handle_t type
Definition: backend_traits_level_zero.hpp:220
cl::sycl::detail::BackendInput< backend::ext_oneapi_level_zero, context >::type::DeviceList
std::vector< device > DeviceList
Definition: backend_traits_level_zero.hpp:107
device.hpp
ze_command_queue_handle_t
struct _ze_command_queue_handle_t * ze_command_queue_handle_t
Definition: backend_traits_level_zero.hpp:29
cl::sycl::detail::BackendReturn< backend::ext_oneapi_level_zero, queue >::type
ze_command_queue_handle_t type
Definition: backend_traits_level_zero.hpp:212
ze_event_handle_t
struct _ze_event_handle_t * ze_event_handle_t
Definition: backend_traits_level_zero.hpp:33
cl::sycl::detail::BackendReturn< backend::ext_oneapi_level_zero, context >::type
ze_context_handle_t type
Definition: backend_traits_level_zero.hpp:114
context.hpp
cl::sycl::detail::BackendInput< backend::ext_oneapi_level_zero, queue >::type::type
type()
Definition: backend_traits_level_zero.hpp:177
event.hpp
ze_device_handle_t
struct _ze_device_handle_t * ze_device_handle_t
Definition: backend_traits_level_zero.hpp:31
cl::sycl::detail::BackendInput< backend::ext_oneapi_level_zero, queue >::type::type
type(interop< backend::ext_oneapi_level_zero, queue >::type nativeHandle, device dev, ext::oneapi::level_zero::ownership ownership=ext::oneapi::level_zero::ownership::transfer)
Definition: backend_traits_level_zero.hpp:187
sycl
Definition: invoke_simd.hpp:68
cl::sycl::detail::BackendReturn< backend::ext_oneapi_level_zero, kernel >::type
ze_kernel_handle_t type
Definition: backend_traits_level_zero.hpp:257
cl::sycl::detail::BackendInput< backend::ext_oneapi_level_zero, event >::type::NativeHandle
interop< backend::ext_oneapi_level_zero, event >::type NativeHandle
Definition: backend_traits_level_zero.hpp:127
cl::sycl::queue
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:103
cl::sycl::buffer
Defines a shared array that can be used by kernels in queues.
Definition: buffer.hpp:58
backend_traits.hpp
cl::sycl::detail::BackendInput< backend::ext_oneapi_level_zero, kernel_bundle< State > >::type::NativeHandle
ze_module_handle_t NativeHandle
Definition: backend_traits_level_zero.hpp:236
cl::sycl::detail::BackendInput< backend::ext_oneapi_level_zero, queue >::type::Ownership
ext::oneapi::level_zero::ownership Ownership
Definition: backend_traits_level_zero.hpp:171
cl::sycl::detail::interop< backend::ext_oneapi_level_zero, accessor< DataT, Dimensions, AccessMode, access::target::image, access::placeholder::false_t > >::type
ze_image_handle_t type
Definition: backend_traits_level_zero.hpp:97
char
filter_selector.hpp
cl::sycl::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:35
kernel_bundle.hpp
cl::sycl::detail::InteropFeatureSupportMap
Definition: backend_traits.hpp:24
cl::sycl::detail::OptionalDevice::operator=
OptionalDevice & operator=(device &Other)
Definition: backend_traits_level_zero.hpp:151
cl::sycl::backend::ext_oneapi_level_zero
@ ext_oneapi_level_zero
cl::sycl::detail::OptionalDevice::OptionalDevice
OptionalDevice()
Definition: backend_traits_level_zero.hpp:138
cl::sycl::detail::BackendInput< backend::ext_oneapi_level_zero, queue >::type::__SYCL_DEPRECATED
__SYCL_DEPRECATED("Use backend_input_t<backend::ext_oneapi_level_zero, " "queue> constructor with device parameter") type(interop< backend
Definition: backend_traits_level_zero.hpp:180
cl::sycl::accessor
Buffer accessor.
Definition: accessor.hpp:223
cl::sycl::detail::BackendInput< backend::ext_oneapi_level_zero, kernel >::type::KernelBundle
kernel_bundle< bundle_state::executable > KernelBundle
Definition: backend_traits_level_zero.hpp:249
cl::sycl::detail::BackendInput< backend::ext_oneapi_level_zero, device >::type
ze_device_handle_t type
Definition: backend_traits_level_zero.hpp:118
defines.hpp
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::BackendReturn< backend::ext_oneapi_level_zero, event >::type
ze_event_handle_t type
Definition: backend_traits_level_zero.hpp:134
cl::sycl::detail::interop< backend::ext_oneapi_level_zero, kernel >::type
ze_kernel_handle_t type
Definition: backend_traits_level_zero.hpp:101
cl::sycl::detail::interop< backend::ext_oneapi_level_zero, event >::type
ze_event_handle_t type
Definition: backend_traits_level_zero.hpp:59
cl::sycl::detail::BackendInput< backend::ext_oneapi_level_zero, buffer< DataT, Dimensions, AllocatorT > >::type::NativeHandle
void * NativeHandle
Definition: backend_traits_level_zero.hpp:199
queue.hpp
cl::sycl::detail::interop
Definition: backend_traits.hpp:18
cl::sycl::detail::interop< backend::ext_oneapi_level_zero, platform >::type
ze_driver_handle_t type
Definition: backend_traits_level_zero.hpp:67
cl::sycl::detail::BackendReturn< backend::ext_oneapi_level_zero, buffer< DataT, Dimensions, AllocatorT > >::type
void * type
Definition: backend_traits_level_zero.hpp:208
cl::sycl::detail::OptionalDevice
Definition: backend_traits_level_zero.hpp:137
level_zero_ownership.hpp
cl::sycl::ext::oneapi::level_zero::ownership
ownership
Definition: level_zero_ownership.hpp:23
cl::sycl::detail::interop< backend::ext_oneapi_level_zero, queue >::type
ze_command_queue_handle_t type
Definition: backend_traits_level_zero.hpp:63
accessor.hpp
cl::sycl::detail::interop< backend::ext_oneapi_level_zero, device >::type
ze_device_handle_t type
Definition: backend_traits_level_zero.hpp:55
cl::sycl::detail::interop< backend::ext_oneapi_level_zero, context >::type
ze_context_handle_t type
Definition: backend_traits_level_zero.hpp:51
ze_context_handle_t
struct _ze_context_handle_t * ze_context_handle_t
Definition: backend_traits_level_zero.hpp:30
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:198
cl::sycl::detail::BackendInput< backend::ext_oneapi_level_zero, context >::type::NativeHandle
interop< backend::ext_oneapi_level_zero, context >::type NativeHandle
Definition: backend_traits_level_zero.hpp:106
cl::sycl::platform
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:34
ze_driver_handle_t
struct _ze_driver_handle_t * ze_driver_handle_t
Definition: backend_traits_level_zero.hpp:32
cl::sycl::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:35
cl::sycl::detail::BackendInput< backend::ext_oneapi_level_zero, platform >::type
ze_driver_handle_t type
Definition: backend_traits_level_zero.hpp:216
cl::sycl::detail::BackendReturn< backend::ext_oneapi_level_zero, device >::type
ze_device_handle_t type
Definition: backend_traits_level_zero.hpp:122
cl::sycl::detail::OptionalDeviceHasDevice
bool OptionalDeviceHasDevice(const OptionalDevice &Dev)
Definition: backend_traits_level_zero.hpp:164
cl::sycl::detail::OptionalDevice::operator=
OptionalDevice & operator=(OptionalDevice &Other)
Definition: backend_traits_level_zero.hpp:147
ze_kernel_handle_t
struct _ze_kernel_handle_t * ze_kernel_handle_t
Definition: backend_traits_level_zero.hpp:35
cl::sycl::kernel
Provides an abstraction of a SYCL kernel.
Definition: kernel.hpp:67
cl::sycl::detail::BackendInput< backend::ext_oneapi_level_zero, kernel >::type::NativeHandle
ze_kernel_handle_t NativeHandle
Definition: backend_traits_level_zero.hpp:250
cl::sycl::detail::BackendInput< backend::ext_oneapi_level_zero, queue >::type::Device
OptionalDevice Device
Definition: backend_traits_level_zero.hpp:175
PI_INVALID_DEVICE
@ PI_INVALID_DEVICE
Definition: pi.h:94
cl::sycl::detail::BackendReturn
Definition: backend_traits.hpp:22
cl::sycl::detail::BackendInput
Definition: backend_traits.hpp:20
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12