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 
11 #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 {
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
28 get_kernel_info(RT::PiKernel Kernel, const plugin &Plugin) {
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
49 get_kernel_info(RT::PiKernel Kernel, const plugin &Plugin) {
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
62  const plugin &Plugin, void *Result,
63  size_t Size) {
65  Kernel, Device, PiInfoCode<Param>::value, 0, nullptr, Size, Result,
66  nullptr);
67 }
68 
69 template <typename Param>
70 typename std::enable_if<!IsSubGroupInfo<Param>::value>::type
72  const plugin &Plugin, void *Result,
73  size_t Size) {
75  Kernel, Device, PiInfoCode<Param>::value, Size, Result, nullptr);
76 }
77 
78 template <typename Param>
79 typename std::enable_if<
80  !std::is_same<typename Param::return_type, sycl::range<3>>::value,
81  typename Param::return_type>::type
83  const plugin &Plugin) {
85  "Unexpected kernel_device_specific information descriptor");
86  typename Param::return_type Result = {};
87  // TODO catch an exception and put it to list of asynchronous exceptions
88  get_kernel_device_specific_info_helper<Param>(
89  Kernel, Device, Plugin, &Result, sizeof(typename Param::return_type));
90  return Result;
91 }
92 
93 template <typename Param>
94 typename std::enable_if<
95  std::is_same<typename Param::return_type, sycl::range<3>>::value,
96  sycl::range<3>>::type
98  const plugin &Plugin) {
100  "Unexpected kernel_device_specific information descriptor");
101  size_t Result[3] = {0, 0, 0};
102  // TODO catch an exception and put it to list of asynchronous exceptions
103  get_kernel_device_specific_info_helper<Param>(Kernel, Device, Plugin, Result,
104  sizeof(size_t) * 3);
105  return sycl::range<3>(Result[0], Result[1], Result[2]);
106 }
107 
108 // TODO: This is used by a deprecated version of
109 // info::kernel_device_specific::max_sub_group_size taking an input paramter.
110 // This should be removed when the deprecated info query is removed.
111 template <typename Param>
113  RT::PiDevice Device,
114  sycl::range<3> In,
115  const plugin &Plugin) {
117  "Unexpected kernel_device_specific information descriptor");
118  static_assert(std::is_same<typename Param::return_type, uint32_t>::value,
119  "Unexpected return type");
120  static_assert(IsSubGroupInfo<Param>::value,
121  "Unexpected kernel_device_specific information descriptor for "
122  "query with input");
123  size_t Input[3] = {In[0], In[1], In[2]};
124  uint32_t Result = 0;
125  // TODO catch an exception and put it to list of asynchronous exceptions
127  Kernel, Device, PiInfoCode<Param>::value, sizeof(size_t) * 3, Input,
128  sizeof(uint32_t), &Result, nullptr);
129 
130  return Result;
131 }
132 
133 template <typename Param>
134 inline typename Param::return_type
135 get_kernel_device_specific_info_host(const sycl::device &Device) = delete;
136 
137 template <>
138 inline sycl::range<3> get_kernel_device_specific_info_host<
139  info::kernel_device_specific::global_work_size>(const sycl::device &) {
140  throw invalid_object_error("This instance of kernel is a host instance",
141  PI_ERROR_INVALID_KERNEL);
142 }
143 
144 template <>
147  return Dev.get_info<info::device::max_work_group_size>();
148 }
149 
150 template <>
151 inline sycl::range<3> get_kernel_device_specific_info_host<
152  info::kernel_device_specific::compile_work_group_size>(
153  const sycl::device &) {
154  return {0, 0, 0};
155 }
156 
157 template <>
159  info::kernel_device_specific::preferred_work_group_size_multiple>(
160  const sycl::device &Dev) {
163 }
164 
165 template <>
167  info::kernel_device_specific::private_mem_size>(const sycl::device &) {
168  return 0;
169 }
170 
171 template <>
173  info::kernel_device_specific::ext_codeplay_num_regs>(const sycl::device &) {
174  return 0;
175 }
176 
177 template <>
179  info::kernel_device_specific::max_num_sub_groups>(const sycl::device &) {
180  throw invalid_object_error("This instance of kernel is a host instance",
181  PI_ERROR_INVALID_KERNEL);
182 }
183 
184 template <>
186  info::kernel_device_specific::max_sub_group_size>(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::compile_num_sub_groups>(
194  const sycl::device &) {
195  throw invalid_object_error("This instance of kernel is a host instance",
196  PI_ERROR_INVALID_KERNEL);
197 }
198 
199 template <>
201  info::kernel_device_specific::compile_sub_group_size>(
202  const sycl::device &) {
203  throw invalid_object_error("This instance of kernel is a host instance",
204  PI_ERROR_INVALID_KERNEL);
205 }
206 } // namespace detail
207 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
208 } // namespace sycl
sycl::_V1::detail::get_kernel_device_specific_info_helper
std::enable_if<!IsSubGroupInfo< Param >::value >::type get_kernel_device_specific_info_helper(RT::PiKernel Kernel, RT::PiDevice Device, const plugin &Plugin, void *Result, size_t Size)
Definition: kernel_info.hpp:71
sycl::_V1::detail::IsSubGroupInfo
Definition: info_desc_helpers.hpp:60
device.hpp
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl::_V1::detail::pi::PiDevice
::pi_device PiDevice
Definition: pi.hpp:124
sycl::_V1::detail::get_kernel_device_specific_info
std::enable_if< std::is_same< typename Param::return_type, sycl::range< 3 > >::value, sycl::range< 3 > >::type get_kernel_device_specific_info(RT::PiKernel Kernel, RT::PiDevice Device, const plugin &Plugin)
Definition: kernel_info.hpp:97
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
sycl::_V1::detail::PiInfoCode
Definition: info_desc_helpers.hpp:18
piKernelGetSubGroupInfo
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_esimd_emulator.cpp:1389
pi.hpp
sycl::_V1::detail::get_kernel_device_specific_info_host
Param::return_type get_kernel_device_specific_info_host(const sycl::device &Device)=delete
sycl::_V1::detail::plugin
The plugin class provides a unified interface to the underlying low-level runtimes for the device-agn...
Definition: plugin.hpp:90
piKernelGetGroupInfo
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_esimd_emulator.cpp:1384
common.hpp
sycl::_V1::detail::is_kernel_device_specific_info_desc
Definition: info_desc_helpers.hpp:25
sycl::_V1::detail::pi::PiKernel
::pi_kernel PiKernel
Definition: pi.hpp:131
piKernelGetInfo
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_esimd_emulator.cpp:1380
sycl::_V1::detail::plugin::call
void call(ArgsT... Args) const
Calls the API, traces the call, checks the result.
Definition: plugin.hpp:217
info_desc_helpers.hpp
sycl::_V1::detail::get_kernel_device_specific_info_with_input
uint32_t get_kernel_device_specific_info_with_input(RT::PiKernel Kernel, RT::PiDevice Device, sycl::range< 3 > In, const plugin &Plugin)
Definition: kernel_info.hpp:112
sycl::_V1::detail::is_kernel_info_desc
Definition: info_desc_helpers.hpp:23
info_desc.hpp
sycl::_V1::ext::oneapi::experimental::work_group_size
constexpr work_group_size_key::value_t< Dim0, Dims... > work_group_size
Definition: properties.hpp:110
common_info.hpp
sycl::_V1::detail::get_kernel_info
std::enable_if< std::is_same< typename Param::return_type, uint32_t >::value, uint32_t >::type get_kernel_info(RT::PiKernel Kernel, const plugin &Plugin)
Definition: kernel_info.hpp:49