DPC++ Runtime
Runtime libraries for oneAPI DPC++
kernel_info.hpp
Go to the documentation of this file.
1 //==-------- kernel_info.hpp - SYCL kernel info methods --------------------==//
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 
12 #include <sycl/detail/common.hpp>
14 #include <sycl/detail/pi.hpp>
15 #include <sycl/device.hpp>
16 #include <sycl/info/info_desc.hpp>
17 
18 #include <type_traits>
19 
20 namespace sycl {
21 inline namespace _V1 {
22 namespace detail {
23 
24 template <typename Param>
25 typename std::enable_if<
26  std::is_same<typename Param::return_type, std::string>::value,
27  std::string>::type
30  "Invalid kernel information descriptor");
31  size_t ResultSize = 0;
32 
33  // TODO catch an exception and put it to list of asynchronous exceptions
35  nullptr, &ResultSize);
36  if (ResultSize == 0) {
37  return "";
38  }
39  std::vector<char> Result(ResultSize);
40  // TODO catch an exception and put it to list of asynchronous exceptions
42  ResultSize, Result.data(), nullptr);
43  return std::string(Result.data());
44 }
45 
46 template <typename Param>
47 typename std::enable_if<
48  std::is_same<typename Param::return_type, uint32_t>::value, uint32_t>::type
50  uint32_t Result = 0;
51 
52  // TODO catch an exception and put it to list of asynchronous exceptions
54  sizeof(uint32_t), &Result, nullptr);
55  return Result;
56 }
57 
58 // Device-specific methods
59 template <typename Param>
60 typename std::enable_if<IsSubGroupInfo<Param>::value>::type
63  const PluginPtr &Plugin, void *Result,
64  size_t Size) {
66  Kernel, Device, PiInfoCode<Param>::value, 0, nullptr, Size, Result,
67  nullptr);
68 }
69 
70 template <typename Param>
71 typename std::enable_if<!IsSubGroupInfo<Param>::value>::type
74  const PluginPtr &Plugin, void *Result,
75  size_t Size) {
77  Plugin->call_nocheck<PiApiKind::piKernelGetGroupInfo>(
78  Kernel, Device, PiInfoCode<Param>::value, Size, Result, nullptr);
79  if (Error != PI_SUCCESS)
81  Plugin);
82 }
83 
84 template <typename Param>
85 typename std::enable_if<
86  !std::is_same<typename Param::return_type, sycl::range<3>>::value,
87  typename Param::return_type>::type
90  const PluginPtr &Plugin) {
92  "Unexpected kernel_device_specific information descriptor");
93  typename Param::return_type Result = {};
94  // TODO catch an exception and put it to list of asynchronous exceptions
95  get_kernel_device_specific_info_helper<Param>(
96  Kernel, Device, Plugin, &Result, sizeof(typename Param::return_type));
97  return Result;
98 }
99 
100 template <typename Param>
101 typename std::enable_if<
102  std::is_same<typename Param::return_type, sycl::range<3>>::value,
103  sycl::range<3>>::type
106  const PluginPtr &Plugin) {
108  "Unexpected kernel_device_specific information descriptor");
109  size_t Result[3] = {0, 0, 0};
110  // TODO catch an exception and put it to list of asynchronous exceptions
111  get_kernel_device_specific_info_helper<Param>(Kernel, Device, Plugin, Result,
112  sizeof(size_t) * 3);
113  return sycl::range<3>(Result[0], Result[1], Result[2]);
114 }
115 
116 // TODO: This is used by a deprecated version of
117 // info::kernel_device_specific::max_sub_group_size taking an input paramter.
118 // This should be removed when the deprecated info query is removed.
119 template <typename Param>
122  sycl::range<3> In, const PluginPtr &Plugin) {
124  "Unexpected kernel_device_specific information descriptor");
125  static_assert(std::is_same<typename Param::return_type, uint32_t>::value,
126  "Unexpected return type");
127  static_assert(IsSubGroupInfo<Param>::value,
128  "Unexpected kernel_device_specific information descriptor for "
129  "query with input");
130  size_t Input[3] = {In[0], In[1], In[2]};
131  uint32_t Result = 0;
132  // TODO catch an exception and put it to list of asynchronous exceptions
134  Kernel, Device, PiInfoCode<Param>::value, sizeof(size_t) * 3, Input,
135  sizeof(uint32_t), &Result, nullptr);
136 
137  return Result;
138 }
139 
140 template <typename Param>
141 inline typename Param::return_type
143 
144 template <>
146  info::kernel_device_specific::global_work_size>(const sycl::device &) {
147  throw invalid_object_error("This instance of kernel is a host instance",
148  PI_ERROR_INVALID_KERNEL);
149 }
150 
151 template <>
154  return Dev.get_info<info::device::max_work_group_size>();
155 }
156 
157 template <>
159  info::kernel_device_specific::compile_work_group_size>(
160  const sycl::device &) {
161  return {0, 0, 0};
162 }
163 
164 template <>
166  info::kernel_device_specific::preferred_work_group_size_multiple>(
167  const sycl::device &Dev) {
170 }
171 
172 template <>
174  info::kernel_device_specific::private_mem_size>(const sycl::device &) {
175  return 0;
176 }
177 
178 template <>
180  info::kernel_device_specific::ext_codeplay_num_regs>(const sycl::device &) {
181  return 0;
182 }
183 
184 template <>
186  info::kernel_device_specific::max_num_sub_groups>(const sycl::device &) {
187  throw invalid_object_error("This instance of kernel is a host instance",
188  PI_ERROR_INVALID_KERNEL);
189 }
190 
191 template <>
193  info::kernel_device_specific::max_sub_group_size>(const sycl::device &) {
194  throw invalid_object_error("This instance of kernel is a host instance",
195  PI_ERROR_INVALID_KERNEL);
196 }
197 
198 template <>
200  info::kernel_device_specific::compile_num_sub_groups>(
201  const sycl::device &) {
202  throw invalid_object_error("This instance of kernel is a host instance",
203  PI_ERROR_INVALID_KERNEL);
204 }
205 
206 template <>
208  info::kernel_device_specific::compile_sub_group_size>(
209  const sycl::device &) {
210  throw invalid_object_error("This instance of kernel is a host instance",
211  PI_ERROR_INVALID_KERNEL);
212 }
213 } // namespace detail
214 } // namespace _V1
215 } // namespace sycl
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:64
Defines the iteration domain of either a single work-group in a parallel dispatch,...
Definition: range.hpp:26
void handleErrorOrWarning(pi_result Error, pi_kernel_group_info Descriptor, const PluginPtr &Plugin)
Analyzes error code of piKernelGetGroupInfo.
uint32_t get_kernel_device_specific_info_with_input(sycl::detail::pi::PiKernel Kernel, sycl::detail::pi::PiDevice Device, sycl::range< 3 > In, const PluginPtr &Plugin)
std::enable_if< !std::is_same< typename Param::return_type, sycl::range< 3 > >::value, typename Param::return_type >::type get_kernel_device_specific_info(sycl::detail::pi::PiKernel Kernel, sycl::detail::pi::PiDevice Device, const PluginPtr &Plugin)
Definition: kernel_info.hpp:88
Param::return_type get_kernel_device_specific_info_host(const sycl::device &Device)=delete
std::shared_ptr< plugin > PluginPtr
Definition: pi.hpp:48
std::enable_if< IsSubGroupInfo< Param >::value >::type get_kernel_device_specific_info_helper(sycl::detail::pi::PiKernel Kernel, sycl::detail::pi::PiDevice Device, const PluginPtr &Plugin, void *Result, size_t Size)
Definition: kernel_info.hpp:61
std::enable_if< std::is_same< typename Param::return_type, std::string >::value, std::string >::type get_kernel_info(sycl::detail::pi::PiKernel Kernel, const PluginPtr &Plugin)
Definition: kernel_info.hpp:28
constexpr work_group_size_key::value_t< Dim0, Dims... > work_group_size
Definition: properties.hpp:117
Definition: access.hpp:18
_pi_result
Definition: pi.h:224
pi_result piKernelGetSubGroupInfo(pi_kernel kernel, pi_device device, pi_kernel_sub_group_info param_name, size_t input_value_size, const void *input_value, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
API to query information from the sub-group from a kernel.
Definition: pi_cuda.cpp:516
pi_result piKernelGetInfo(pi_kernel kernel, pi_kernel_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
Definition: pi_cuda.cpp:366
pi_result piKernelGetGroupInfo(pi_kernel kernel, pi_device device, pi_kernel_group_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
Definition: pi_cuda.cpp:508
C++ wrapper of extern "C" PI interfaces.