DPC++ Runtime
Runtime libraries for oneAPI DPC++
kernel.hpp
Go to the documentation of this file.
1 //==--------------- kernel.hpp --- SYCL kernel -----------------------------==//
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 #pragma once
10 
11 #include <sycl/detail/cl.h>
12 #include <sycl/detail/common.hpp>
13 #include <sycl/detail/export.hpp>
15 #include <sycl/detail/pi.h>
16 #include <sycl/info/info_desc.hpp>
18 #include <sycl/stl.hpp>
19 
20 #include <memory>
21 
22 namespace sycl {
24 // Forward declaration
25 class context;
26 template <backend Backend> class backend_traits;
27 template <bundle_state State> class kernel_bundle;
28 template <backend BackendName, class SyclObjectT>
29 auto get_native(const SyclObjectT &Obj)
30  -> backend_return_t<BackendName, SyclObjectT>;
31 
32 namespace detail {
33 class kernel_impl;
34 
37 class auto_name {};
38 
42 template <typename Name, typename Type> struct get_kernel_name_t {
43  using name = Name;
44  static_assert(
45  !std::is_same<Name, auto_name>::value,
46  "No kernel name provided without -fsycl-unnamed-lambda enabled!");
47 };
48 
49 #ifdef __SYCL_UNNAMED_LAMBDA__
55 template <typename Type> struct get_kernel_name_t<detail::auto_name, Type> {
56  using name = Type;
57 };
58 #endif // __SYCL_UNNAMED_LAMBDA__
59 
60 } // namespace detail
61 
69 class __SYCL_EXPORT kernel {
70 public:
78 #ifdef __SYCL_INTERNAL_API
79  kernel(cl_kernel ClKernel, const context &SyclContext);
80 #endif
81 
82  kernel(const kernel &RHS) = default;
83 
84  kernel(kernel &&RHS) = default;
85 
86  kernel &operator=(const kernel &RHS) = default;
87 
88  kernel &operator=(kernel &&RHS) = default;
89 
90  bool operator==(const kernel &RHS) const { return impl == RHS.impl; }
91 
92  bool operator!=(const kernel &RHS) const { return !operator==(RHS); }
93 
101 #ifdef __SYCL_INTERNAL_API
102  cl_kernel get() const;
103 #endif
104 
109  "is_host() is deprecated as the host device is no longer supported.")
110  bool is_host() const;
111 
118  context get_context() const;
119 
123  backend get_backend() const noexcept;
124 
128  kernel_bundle<bundle_state::executable> get_kernel_bundle() const;
129 
134  template <typename Param>
135  typename detail::is_kernel_info_desc<Param>::return_type get_info() const;
136 
142  template <typename Param>
143  typename detail::is_kernel_device_specific_info_desc<Param>::return_type
144  get_info(const device &Device) const;
145 
153  template <typename Param>
154  __SYCL2020_DEPRECATED("Use the overload without the second parameter")
155  typename detail::is_kernel_device_specific_info_desc<Param>::return_type
156  get_info(const device &Device, const range<3> &WGSize) const;
157 
158 private:
160  kernel(std::shared_ptr<detail::kernel_impl> Impl);
161 
162  pi_native_handle getNative() const;
163 
164  __SYCL_DEPRECATED("Use getNative() member function")
165  pi_native_handle getNativeImpl() const;
166 
167  std::shared_ptr<detail::kernel_impl> impl;
168 
169  template <class Obj>
170  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
171  template <class T>
172  friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
173  template <backend BackendName, class SyclObjectT>
174  friend auto get_native(const SyclObjectT &Obj)
175  -> backend_return_t<BackendName, SyclObjectT>;
176 };
177 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
178 } // namespace sycl
179 
180 namespace std {
181 template <> struct hash<sycl::kernel> {
182  size_t operator()(const sycl::kernel &Kernel) const {
183  return hash<std::shared_ptr<sycl::detail::kernel_impl>>()(
185  }
186 };
187 } // namespace std
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:39
This class is the default KernelName template parameter type for kernel invocation APIs such as singl...
Definition: kernel.hpp:37
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:47
The kernel_bundle class represents collection of device images in a particular state.
Provides an abstraction of a SYCL kernel.
Definition: kernel.hpp:69
bool operator==(const kernel &RHS) const
Definition: kernel.hpp:90
kernel(kernel &&RHS)=default
kernel(const kernel &RHS)=default
Constructs a SYCL kernel instance from an OpenCL cl_kernel.
kernel & operator=(const kernel &RHS)=default
__SYCL2020_DEPRECATED("is_host() is deprecated as the host device is no longer supported.") bool is_host() const
Get a valid OpenCL kernel handle.
bool operator!=(const kernel &RHS) const
Definition: kernel.hpp:92
kernel & operator=(kernel &&RHS)=default
Defines the iteration domain of either a single work-group in a parallel dispatch,...
Definition: range.hpp:24
#define __SYCL_INLINE_VER_NAMESPACE(X)
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:240
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: common.hpp:258
kernel_bundle< State > get_kernel_bundle(const context &Ctx, const std::vector< device > &Devs)
A kernel bundle in state State which contains all of the kernels in the application which are compati...
auto get_native(const SyclObjectT &Obj) -> backend_return_t< BackendName, SyclObjectT >
Definition: backend.hpp:123
typename backend_traits< Backend >::template return_type< SyclType > backend_return_t
Definition: backend.hpp:72
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
uintptr_t pi_native_handle
Definition: pi.h:107
@ Device
size_t operator()(const sycl::kernel &Kernel) const
Definition: kernel.hpp:182
Helper struct to get a kernel name type based on given Name and Type types: if Name is undefined (is ...
Definition: kernel.hpp:42
bool operator==(const Slab &Lhs, const Slab &Rhs)