DPC++ Runtime
Runtime libraries for oneAPI DPC++
kernel.cpp
Go to the documentation of this file.
1 //==--------------- kernel.cpp --- 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 
11 #include <detail/kernel_impl.hpp>
12 #include <sycl/detail/export.hpp>
13 #include <sycl/detail/pi.h>
14 #include <sycl/kernel.hpp>
15 
16 namespace sycl {
17 inline namespace _V1 {
18 
19 kernel::kernel(cl_kernel ClKernel, const context &SyclContext)
20  : impl(std::make_shared<detail::kernel_impl>(
21  detail::pi::cast<sycl::detail::pi::PiKernel>(ClKernel),
22  detail::getSyclObjImpl(SyclContext), nullptr, nullptr)) {
23  // This is a special interop constructor for OpenCL, so the kernel must be
24  // retained.
25  if (get_backend() == backend::opencl) {
26  impl->getPlugin()->call<detail::PiApiKind::piKernelRetain>(
27  detail::pi::cast<sycl::detail::pi::PiKernel>(ClKernel));
28  }
29 }
30 
31 cl_kernel kernel::get() const { return impl->get(); }
32 
33 bool kernel::is_host() const {
34  bool IsHost = impl->is_host();
35  assert(!IsHost && "kernel::is_host should not be called in implementation.");
36  return IsHost;
37 }
38 
39 context kernel::get_context() const {
40  return impl->get_info<info::kernel::context>();
41 }
42 
43 backend kernel::get_backend() const noexcept { return getImplBackend(impl); }
44 
48  kernel_bundle<sycl::bundle_state::executable>>(impl->get_kernel_bundle());
49 }
50 
51 template <typename Param>
53 kernel::get_info_impl() const {
54  return detail::convert_to_abi_neutral(impl->template get_info<Param>());
55 }
56 
57 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
58  template __SYCL_EXPORT detail::ABINeutralT_t<ReturnT> \
59  kernel::get_info_impl<info::kernel::Desc>() const;
60 
61 #include <sycl/info/kernel_traits.def>
62 
63 #undef __SYCL_PARAM_TRAITS_SPEC
64 
65 template <typename Param>
66 typename detail::is_backend_info_desc<Param>::return_type
67 kernel::get_backend_info() const {
68  return impl->get_backend_info<Param>();
69 }
70 
71 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, Picode) \
72  template __SYCL_EXPORT ReturnT \
73  kernel::get_backend_info<info::DescType::Desc>() const;
74 
75 #include <sycl/info/sycl_backend_traits.def>
76 
77 #undef __SYCL_PARAM_TRAITS_SPEC
78 
79 template <typename Param>
81 kernel::get_info(const device &Dev) const {
82  return impl->get_info<Param>(Dev);
83 }
84 
85 // Deprecated overload for kernel_device_specific::max_sub_group_size taking
86 // an extra argument.
87 template <typename Param>
89 kernel::get_info(const device &Device, const range<3> &WGSize) const {
90  static_assert(
91  std::is_same_v<Param, info::kernel_device_specific::max_sub_group_size>,
92  "Unexpected param for kernel::get_info with range argument.");
93  return impl->get_info<Param>(Device, WGSize);
94 }
95 
96 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
97  template __SYCL_EXPORT ReturnT kernel::get_info<info::DescType::Desc>( \
98  const device &) const;
99 
100 #include <sycl/info/kernel_device_specific_traits.def>
101 
102 #undef __SYCL_PARAM_TRAITS_SPEC
103 
104 template __SYCL_EXPORT uint32_t
105 kernel::get_info<info::kernel_device_specific::max_sub_group_size>(
106  const device &, const sycl::range<3> &) const;
107 
108 template <typename Param>
109 typename Param::return_type
110 kernel::ext_oneapi_get_info(const queue &Queue) const {
111  return impl->ext_oneapi_get_info<Param>(Queue);
112 }
113 
114 template __SYCL_EXPORT typename ext::oneapi::experimental::info::
115  kernel_queue_specific::max_num_work_group_sync::return_type
116  kernel::ext_oneapi_get_info<
117  ext::oneapi::experimental::info::kernel_queue_specific::
118  max_num_work_group_sync>(const queue &Queue) const;
119 
120 kernel::kernel(std::shared_ptr<detail::kernel_impl> Impl) : impl(Impl) {}
121 
122 pi_native_handle kernel::getNative() const { return impl->getNative(); }
123 
124 pi_native_handle kernel::getNativeImpl() const { return impl->getNative(); }
125 
126 } // namespace _V1
127 } // namespace sycl
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:51
detail::is_context_info_desc< Param >::return_type get_info() const
Constructs a SYCL context instance from OpenCL cl_context.
Definition: context.cpp:94
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:64
The kernel_bundle class represents collection of device images in a particular state.
kernel(const kernel &RHS)=default
Constructs a SYCL kernel instance from an OpenCL cl_kernel.
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:111
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:198
PiProgram cast(cl_program)=delete
::pi_kernel PiKernel
Definition: pi.hpp:138
auto convert_to_abi_neutral(ParamT &&Info)
Definition: platform.hpp:58
backend getImplBackend(const T &Impl)
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: impl_utils.hpp:30
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: impl_utils.hpp:48
typename ABINeutralT< T >::type ABINeutralT_t
Definition: util.hpp:85
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: access.hpp:18
uintptr_t pi_native_handle
Definition: pi.h:217
pi_result piKernelRetain(pi_kernel kernel)
Definition: pi_cuda.cpp:526
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324