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 
13 #include <CL/sycl/detail/pi.hpp>
14 #include <CL/sycl/device.hpp>
16 
18 namespace sycl {
19 namespace detail {
20 
21 // OpenCL kernel information methods
22 template <typename T, info::kernel Param> struct get_kernel_info {};
23 
24 template <info::kernel Param> struct get_kernel_info<std::string, Param> {
25  static std::string get(RT::PiKernel Kernel, const plugin &Plugin) {
26  size_t ResultSize;
27 
28  // TODO catch an exception and put it to list of asynchronous exceptions
29  Plugin.call<PiApiKind::piKernelGetInfo>(Kernel, pi_kernel_info(Param), 0,
30  nullptr, &ResultSize);
31  if (ResultSize == 0) {
32  return "";
33  }
34  std::vector<char> Result(ResultSize);
35  // TODO catch an exception and put it to list of asynchronous exceptions
36  Plugin.call<PiApiKind::piKernelGetInfo>(Kernel, pi_kernel_info(Param),
37  ResultSize, Result.data(), nullptr);
38  return std::string(Result.data());
39  }
40 };
41 
42 template <info::kernel Param> struct get_kernel_info<cl_uint, Param> {
43  static cl_uint get(RT::PiKernel Kernel, const plugin &Plugin) {
44  cl_uint Result;
45 
46  // TODO catch an exception and put it to list of asynchronous exceptions
47  Plugin.call<PiApiKind::piKernelGetInfo>(Kernel, pi_kernel_info(Param),
48  sizeof(cl_uint), &Result, nullptr);
49  return Result;
50  }
51 };
52 
53 // Device-specific methods
54 
55 template <info::kernel_device_specific Param>
56 struct IsWorkGroupInfo : std::false_type {};
57 
58 template <>
59 struct IsWorkGroupInfo<info::kernel_device_specific::global_work_size>
60  : std::true_type {};
61 template <>
62 struct IsWorkGroupInfo<info::kernel_device_specific::work_group_size>
63  : std::true_type {};
64 template <>
65 struct IsWorkGroupInfo<info::kernel_device_specific::compile_work_group_size>
66  : std::true_type {};
67 template <>
69  info::kernel_device_specific::preferred_work_group_size_multiple>
70  : std::true_type {};
71 template <>
72 struct IsWorkGroupInfo<info::kernel_device_specific::private_mem_size>
73  : std::true_type {};
74 template <>
75 struct IsWorkGroupInfo<info::kernel_device_specific::ext_codeplay_num_regs>
76  : std::true_type {};
77 
78 template <typename T, info::kernel_device_specific Param>
80  static T get(RT::PiKernel Kernel, RT::PiDevice Device, const plugin &Plugin) {
81  T Result;
83  // TODO catch an exception and put it to list of asynchronous exceptions
85  Kernel, Device, pi::cast<pi_kernel_group_info>(Param), sizeof(T),
86  &Result, nullptr);
87  } else {
89  Kernel, Device, pi_kernel_sub_group_info(Param), 0, nullptr,
90  sizeof(T), &Result, nullptr);
91  }
92  return Result;
93  }
94 };
95 
96 template <info::kernel_device_specific Param>
99  const plugin &Plugin) {
100  size_t Result[3];
101  // TODO catch an exception and put it to list of asynchronous exceptions
103  Kernel, Device, pi::cast<pi_kernel_group_info>(Param),
104  sizeof(size_t) * 3, Result, nullptr);
105  return cl::sycl::range<3>(Result[0], Result[1], Result[2]);
106  }
107 };
108 
109 template <info::kernel_device_specific Param>
111  Param>::return_type
113 
114 template <>
116  info::kernel_device_specific::global_work_size>(const cl::sycl::device &) {
117  throw invalid_object_error("This instance of kernel is a host instance",
119 }
120 
121 template <>
123  info::kernel_device_specific::work_group_size>(
124  const cl::sycl::device &Dev) {
125  return Dev.get_info<info::device::max_work_group_size>();
126 }
127 
128 template <>
130  info::kernel_device_specific::compile_work_group_size>(
131  const cl::sycl::device &) {
132  return {0, 0, 0};
133 }
134 
135 template <>
137  info::kernel_device_specific::preferred_work_group_size_multiple>(
138  const cl::sycl::device &Dev) {
140  info::kernel_device_specific::work_group_size>(Dev);
141 }
142 
143 template <>
145  info::kernel_device_specific::private_mem_size>(const cl::sycl::device &) {
146  return 0;
147 }
148 
149 template <>
151  info::kernel_device_specific::ext_codeplay_num_regs>(
152  const cl::sycl::device &) {
153  return 0;
154 }
155 
156 template <>
158  info::kernel_device_specific::max_num_sub_groups>(
159  const cl::sycl::device &) {
160  throw invalid_object_error("This instance of kernel is a host instance",
162 }
163 
164 template <>
166  info::kernel_device_specific::compile_num_sub_groups>(
167  const cl::sycl::device &) {
168  throw invalid_object_error("This instance of kernel is a host instance",
170 }
171 
172 template <>
174  info::kernel_device_specific::compile_sub_group_size>(
175  const cl::sycl::device &) {
176  throw invalid_object_error("This instance of kernel is a host instance",
178 }
179 
180 template <info::kernel_device_specific Param>
182  static uint32_t get(RT::PiKernel Kernel, RT::PiDevice Device,
183  cl::sycl::range<3> In, const plugin &Plugin) {
184  size_t Input[3] = {In[0], In[1], In[2]};
185  uint32_t Result;
186  // TODO catch an exception and put it to list of asynchronous exceptions
188  Kernel, Device, pi_kernel_sub_group_info(Param), sizeof(size_t) * 3,
189  Input, sizeof(uint32_t), &Result, nullptr);
190 
191  return Result;
192  }
193 };
194 } // namespace detail
195 } // namespace sycl
196 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::detail::get_kernel_device_specific_info< cl::sycl::range< 3 >, Param >::get
static cl::sycl::range< 3 > get(RT::PiKernel Kernel, RT::PiDevice Device, const plugin &Plugin)
Definition: kernel_info.hpp:98
PI_INVALID_KERNEL
@ PI_INVALID_KERNEL
Definition: pi.h:89
pi_kernel_sub_group_info
_pi_kernel_sub_group_info pi_kernel_sub_group_info
Definition: pi.h:644
cl::sycl::info::param_traits
Definition: info_desc.hpp:310
cl::sycl::detail::get_kernel_info
Definition: kernel_info.hpp:22
device.hpp
sycl
Definition: invoke_simd.hpp:68
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:1375
cl::sycl::detail::get_kernel_info< cl_uint, Param >::get
static cl_uint get(RT::PiKernel Kernel, const plugin &Plugin)
Definition: kernel_info.hpp:43
pi.hpp
cl::sycl::range
Defines the iteration domain of either a single work-group in a parallel dispatch,...
Definition: buffer.hpp:24
_pi_kernel
Implementation of a PI Kernel for CUDA.
Definition: pi_cuda.hpp:624
pi_kernel_info
_pi_kernel_info pi_kernel_info
Definition: pi.h:642
cl::sycl::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:35
cl::sycl::detail::get_kernel_info< std::string, Param >::get
static std::string get(RT::PiKernel Kernel, const plugin &Plugin)
Definition: kernel_info.hpp:25
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:1370
cl::sycl::detail::get_kernel_device_specific_info_host
info::param_traits< info::kernel_device_specific, Param >::return_type get_kernel_device_specific_info_host(const cl::sycl::device &Device)
cl::sycl::detail::plugin::call
void call(ArgsT... Args) const
Calls the API, traces the call, checks the result.
Definition: plugin.hpp:217
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::plugin
The plugin class provides a unified interface to the underlying low-level runtimes for the device-agn...
Definition: plugin.hpp:90
cl::sycl::cl_ulong
std::uint64_t cl_ulong
Definition: aliases.hpp:85
cl::sycl::detail::get_kernel_device_specific_info_with_input
Definition: kernel_info.hpp:181
cl::sycl::detail::IsWorkGroupInfo
Definition: kernel_info.hpp:56
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:1366
cl::sycl::detail::get_kernel_device_specific_info
Definition: kernel_info.hpp:79
std
Definition: accessor.hpp:2616
cl::sycl::detail::get_kernel_device_specific_info::get
static T get(RT::PiKernel Kernel, RT::PiDevice Device, const plugin &Plugin)
Definition: kernel_info.hpp:80
cl::sycl::cl_uint
std::uint32_t cl_uint
Definition: aliases.hpp:83
info_desc.hpp
common.hpp
common_info.hpp
cl::sycl::info::kernel_device_specific
kernel_device_specific
Definition: info_desc.hpp:265
_pi_device
PI device mapping to a CUdevice.
Definition: pi_cuda.hpp:73
cl::sycl::detail::get_kernel_device_specific_info_with_input::get
static uint32_t get(RT::PiKernel Kernel, RT::PiDevice Device, cl::sycl::range< 3 > In, const plugin &Plugin)
Definition: kernel_info.hpp:182
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12