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 {
18 
19 kernel::kernel(cl_kernel ClKernel, const context &SyclContext)
20  : impl(std::make_shared<detail::kernel_impl>(
21  detail::pi::cast<detail::RT::PiKernel>(ClKernel),
22  detail::getSyclObjImpl(SyclContext), nullptr)) {
23  // This is a special interop constructor for OpenCL, so the kernel must be
24  // retained.
25  impl->getPlugin().call<detail::PiApiKind::piKernelRetain>(
26  detail::pi::cast<detail::RT::PiKernel>(ClKernel));
27 }
28 
29 cl_kernel kernel::get() const { return impl->get(); }
30 
31 bool kernel::is_host() const {
32  bool IsHost = impl->is_host();
33  assert(!IsHost && "kernel::is_host should not be called in implementation.");
34  return IsHost;
35 }
36 
38  return impl->get_info<info::kernel::context>();
39 }
40 
41 backend kernel::get_backend() const noexcept { return getImplBackend(impl); }
42 
46  kernel_bundle<sycl::bundle_state::executable>>(impl->get_kernel_bundle());
47 }
48 
49 template <typename Param>
52  return impl->get_info<Param>();
53 }
54 
55 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
56  template __SYCL_EXPORT ReturnT kernel::get_info<info::kernel::Desc>() const;
57 
58 #include <sycl/info/kernel_traits.def>
59 
60 #undef __SYCL_PARAM_TRAITS_SPEC
61 
62 template <typename Param>
64 kernel::get_info(const device &Dev) const {
65  return impl->get_info<Param>(Dev);
66 }
67 
68 // Deprecated overload for kernel_device_specific::max_sub_group_size taking
69 // an extra argument.
70 template <typename Param>
72 kernel::get_info(const device &Device, const range<3> &WGSize) const {
73  static_assert(
74  std::is_same_v<Param, info::kernel_device_specific::max_sub_group_size>,
75  "Unexpected param for kernel::get_info with range argument.");
76  return impl->get_info<Param>(Device, WGSize);
77 }
78 
79 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
80  template __SYCL_EXPORT ReturnT kernel::get_info<info::DescType::Desc>( \
81  const device &) const;
82 
83 #include <sycl/info/kernel_device_specific_traits.def>
84 
85 #undef __SYCL_PARAM_TRAITS_SPEC
86 
87 template __SYCL_EXPORT uint32_t
88 kernel::get_info<info::kernel_device_specific::max_sub_group_size>(
89  const device &, const sycl::range<3> &) const;
90 
91 kernel::kernel(std::shared_ptr<detail::kernel_impl> Impl) : impl(Impl) {}
92 
93 pi_native_handle kernel::getNative() const { return impl->getNative(); }
94 
95 pi_native_handle kernel::getNativeImpl() const { return impl->getNative(); }
96 
97 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
98 } // namespace sycl
pi.h
sycl::_V1::backend
backend
Definition: backend_types.hpp:21
__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
cast
To cast(From value)
Definition: pi_opencl.cpp:42
sycl::_V1::kernel::get_kernel_bundle
kernel_bundle< bundle_state::executable > get_kernel_bundle() const
Get the kernel_bundle associated with this kernel.
Definition: kernel.cpp:44
sycl::_V1::detail::getImplBackend
backend getImplBackend(const T &Impl)
Definition: backend_impl.hpp:17
sycl::_V1::range< 3 >
export.hpp
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
kernel.hpp
piKernelRetain
pi_result piKernelRetain(pi_kernel kernel)
Definition: pi_esimd_emulator.cpp:1398
sycl::_V1::kernel_bundle
The kernel_bundle class represents collection of device images in a particular state.
Definition: kernel.hpp:29
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
sycl::_V1::detail::is_kernel_device_specific_info_desc
Definition: info_desc_helpers.hpp:25
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:133
sycl::_V1::detail::pi::PiKernel
::pi_kernel PiKernel
Definition: pi.hpp:131
sycl::_V1::kernel::kernel
kernel(const kernel &RHS)=default
Constructs a SYCL kernel instance from an OpenCL cl_kernel.
std
Definition: accessor.hpp:3230
sycl::_V1::detail::is_kernel_info_desc
Definition: info_desc_helpers.hpp:23
kernel_bundle_impl.hpp
backend_impl.hpp
kernel_impl.hpp
sycl::_V1::kernel::get_context
context get_context() const
Get the context that this kernel is defined for.
Definition: kernel.cpp:37
sycl::_V1::kernel::get_backend
backend get_backend() const noexcept
Returns the backend associated with this kernel.
Definition: kernel.cpp:41
sycl::_V1::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:300
sycl::_V1::kernel::get_info
detail::is_kernel_info_desc< Param >::return_type get_info() const
Query information from the kernel object using the info::kernel_info descriptor.
Definition: kernel.cpp:51
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:41