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>
16 #include <sycl/detail/pi.h>
18 #include <sycl/info/info_desc.hpp>
20 #include <sycl/stl.hpp>
21 
22 #include <memory>
23 
24 namespace sycl {
26 // Forward declaration
27 class context;
28 template <backend Backend> class backend_traits;
29 template <bundle_state State> class kernel_bundle;
30 template <backend BackendName, class SyclObjectT>
31 auto get_native(const SyclObjectT &Obj)
33 
34 namespace detail {
35 class kernel_impl;
36 
39 class auto_name {};
40 
44 template <typename Name, typename Type> struct get_kernel_name_t {
45  using name = Name;
46  static_assert(
47  !std::is_same<Name, auto_name>::value,
48  "No kernel name provided without -fsycl-unnamed-lambda enabled!");
49 };
50 
51 #ifdef __SYCL_UNNAMED_LAMBDA__
52 template <typename Type> struct get_kernel_name_t<detail::auto_name, Type> {
58  using name = Type;
59 };
60 #endif // __SYCL_UNNAMED_LAMBDA__
61 
62 } // namespace detail
63 
71 class __SYCL_EXPORT kernel : public detail::OwnerLessBase<kernel> {
72 public:
80 #ifdef __SYCL_INTERNAL_API
81  kernel(cl_kernel ClKernel, const context &SyclContext);
82 #endif
83 
84  kernel(const kernel &RHS) = default;
85 
86  kernel(kernel &&RHS) = default;
87 
88  kernel &operator=(const kernel &RHS) = default;
89 
90  kernel &operator=(kernel &&RHS) = default;
91 
92  bool operator==(const kernel &RHS) const { return impl == RHS.impl; }
93 
94  bool operator!=(const kernel &RHS) const { return !operator==(RHS); }
95 
103 #ifdef __SYCL_INTERNAL_API
104  cl_kernel get() const;
105 #endif
106 
111  "is_host() is deprecated as the host device is no longer supported.")
112  bool is_host() const;
113 
120  context get_context() const;
121 
125  backend get_backend() const noexcept;
126 
130  kernel_bundle<bundle_state::executable> get_kernel_bundle() const;
131 
136  template <typename Param>
137  typename detail::is_kernel_info_desc<Param>::return_type get_info() const;
138 
144  template <typename Param>
145  typename detail::is_kernel_device_specific_info_desc<Param>::return_type
146  get_info(const device &Device) const;
147 
155  template <typename Param>
156  __SYCL2020_DEPRECATED("Use the overload without the second parameter")
157  typename detail::is_kernel_device_specific_info_desc<Param>::return_type
158  get_info(const device &Device, const range<3> &WGSize) const;
159 
160 private:
162  kernel(std::shared_ptr<detail::kernel_impl> Impl);
163 
164  pi_native_handle getNative() const;
165 
166  __SYCL_DEPRECATED("Use getNative() member function")
167  pi_native_handle getNativeImpl() const;
168 
169  std::shared_ptr<detail::kernel_impl> impl;
170 
171  template <class Obj>
172  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
173  template <class T>
174  friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
175  template <backend BackendName, class SyclObjectT>
176  friend auto get_native(const SyclObjectT &Obj)
177  -> backend_return_t<BackendName, SyclObjectT>;
178 };
179 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
180 } // namespace sycl
181 
182 namespace std {
183 template <> struct hash<sycl::kernel> {
184  size_t operator()(const sycl::kernel &Kernel) const {
185  return hash<std::shared_ptr<sycl::detail::kernel_impl>>()(
187  }
188 };
189 } // namespace std
sycl::_V1::get_kernel_bundle
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...
Definition: kernel_bundle.hpp:413
sycl::_V1::__SYCL2020_DEPRECATED
signed char __SYCL2020_DEPRECATED
Definition: aliases.hpp:96
pi.h
sycl::_V1::backend
backend
Definition: backend_types.hpp:21
T
sycl::_V1::detail::auto_name
This class is the default KernelName template parameter type for kernel invocation APIs such as singl...
Definition: kernel.hpp:39
stl.hpp
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
operator==
bool operator==(const Slab &Lhs, const Slab &Rhs)
Definition: usm_allocator.cpp:313
owner_less_base.hpp
sycl::_V1::kernel
Provides an abstraction of a SYCL kernel.
Definition: kernel.hpp:71
sycl::_V1::range
Defines the iteration domain of either a single work-group in a parallel dispatch,...
Definition: buffer.hpp:28
export.hpp
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
cl.h
sycl::_V1::ext::oneapi::experimental::operator=
annotated_arg & operator=(annotated_arg &)=default
kernel_bundle_enums.hpp
sycl::_V1::detail::OwnerLessBase
Definition: owner_less_base.hpp:21
sycl::_V1::kernel_bundle
The kernel_bundle class represents collection of device images in a particular state.
Definition: kernel.hpp:29
common.hpp
sycl::_V1::backend_return_t
typename backend_traits< Backend >::template return_type< SyclType > backend_return_t
Definition: backend.hpp:72
sycl::_V1::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:49
sycl::_V1::detail::createSyclObjFromImpl
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: common.hpp:318
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:133
sycl::_V1::detail::get_kernel_name_t::name
Name name
Definition: kernel.hpp:45
std::hash< sycl::kernel >::operator()
size_t operator()(const sycl::kernel &Kernel) const
Definition: kernel.hpp:184
std
Definition: accessor.hpp:3230
info_desc_helpers.hpp
sycl::_V1::kernel::operator==
bool operator==(const kernel &RHS) const
Definition: kernel.hpp:92
info_desc.hpp
sycl::_V1::bundle_state
bundle_state
Definition: kernel_bundle_enums.hpp:14
sycl::_V1::detail::get_kernel_name_t
Helper struct to get a kernel name type based on given Name and Type types: if Name is undefined (is ...
Definition: kernel.hpp:44
weak_object_base.hpp
sycl::_V1::kernel::operator!=
bool operator!=(const kernel &RHS) const
Definition: kernel.hpp:94
sycl::_V1::get_native
auto get_native(const SyclObjectT &Obj) -> backend_return_t< BackendName, SyclObjectT >
Definition: backend.hpp:123
sycl::_V1::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:300
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:41