DPC++ Runtime
Runtime libraries for oneAPI DPC++
kernel_desc.hpp
Go to the documentation of this file.
1 //==----------------------- kernel_desc.hpp --------------------------------==//
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 // FIXME: include export.hpp because integration header emitted by the compiler
12 // uses the macro defined in this header, but it doesn't explicitly include it.
13 #include <sycl/detail/export.hpp>
14 
15 // This header file must not include any standard C++ header files.
16 
17 namespace sycl {
18 inline namespace _V1 {
19 namespace detail {
20 
21 #ifndef __SYCL_DEVICE_ONLY__
22 #define _Bool bool
23 #endif
24 
25 // As stated above, this header file cannot include any of the standard C++
26 // headers. We need int64_t. Here we are matching the exact definition used by
27 // the SemaSYCL version of kernel_desc.hpp in the FE.
28 template <bool Cond, typename TrueT, typename FalseT> struct conditional {
29  using type = TrueT;
30 };
31 template <typename TrueT, typename FalseT>
32 struct conditional<false, TrueT, FalseT> {
33  using type = FalseT;
34 };
35 using int64_t = conditional<sizeof(long) == 8, long, long long>::type;
36 
37 // kernel parameter kinds
38 enum class kernel_param_kind_t {
39  kind_accessor = 0,
40  kind_std_layout = 1, // standard layout object parameters
41  kind_sampler = 2,
42  kind_pointer = 3,
44  kind_stream = 5,
45  kind_invalid = 0xf, // not a valid kernel kind
46 };
47 
48 // describes a kernel parameter
50  // parameter kind
52  // kind == kind_std_layout
53  // parameter size in bytes (includes padding for structs)
54  // kind == kind_accessor
55  // access target; possible access targets are defined in access/access.hpp
56  int info;
57  // offset of the captured value of the parameter in the lambda or function
58  // object
59  int offset;
60 };
61 
62 // Translates specialization constant type to its name.
63 template <class Name> struct SpecConstantInfo {
64  static constexpr const char *getName() { return ""; }
65 };
66 
67 // Translates SYCL 2020 `specialization_id` to a unique symbolic identifier.
68 // There are no primary definition, only specializations in the integration
69 // footer.
70 template <auto &SpecName> const char *get_spec_constant_symbolic_ID_impl();
71 // Wrapper is needed to delay instantiation of
72 // 'get_spec_constant_symbolic_ID_impl' until after we have encountered all
73 // specializations for it generated by the compiler in the integration footer.
74 // Definition in spec_const_integration.hpp.
75 template <auto &SpecName> const char *get_spec_constant_symbolic_ID();
76 
77 #ifndef __SYCL_UNNAMED_LAMBDA__
78 template <class KernelNameType> struct KernelInfo {
79  static constexpr unsigned getNumParams() { return 0; }
80  static const kernel_param_desc_t &getParamDesc(int) {
81  static kernel_param_desc_t Dummy;
82  return Dummy;
83  }
84  static constexpr const char *getName() { return ""; }
85  static constexpr bool isESIMD() { return 0; }
86  static constexpr const char *getFileName() { return ""; }
87  static constexpr const char *getFunctionName() { return ""; }
88  static constexpr unsigned getLineNumber() { return 0; }
89  static constexpr unsigned getColumnNumber() { return 0; }
90  static constexpr int64_t getKernelSize() { return 0; }
91 };
92 #else
93 template <char...> struct KernelInfoData {
94  static constexpr unsigned getNumParams() { return 0; }
95  static const kernel_param_desc_t &getParamDesc(int) {
96  static kernel_param_desc_t Dummy;
97  return Dummy;
98  }
99  static constexpr const char *getName() { return ""; }
100  static constexpr bool isESIMD() { return 0; }
101  static constexpr const char *getFileName() { return ""; }
102  static constexpr const char *getFunctionName() { return ""; }
103  static constexpr unsigned getLineNumber() { return 0; }
104  static constexpr unsigned getColumnNumber() { return 0; }
105  static constexpr int64_t getKernelSize() { return 0; }
106 };
107 
108 // C++14 like index_sequence and make_index_sequence
109 // not needed C++14 members (value_type, size) not implemented
110 template <class T, T...> struct integer_sequence {};
111 template <unsigned long long... I>
112 using index_sequence = integer_sequence<unsigned long long, I...>;
113 template <unsigned long long N>
114 using make_index_sequence =
115  __make_integer_seq<integer_sequence, unsigned long long, N>;
116 
117 template <typename T> struct KernelInfoImpl {
118 private:
119  static constexpr auto n = __builtin_sycl_unique_stable_name(T);
120  template <unsigned long long... I>
121  static KernelInfoData<n[I]...> impl(index_sequence<I...>) {
122  return {};
123  }
124 
125 public:
126  using type = decltype(impl(make_index_sequence<__builtin_strlen(n)>{}));
127 };
128 
129 // For named kernels, this structure is specialized in the integration header.
130 // For unnamed kernels, KernelInfoData is specialized in the integration header,
131 // and this picks it up via the KernelInfoImpl. For non-existent kernels, this
132 // will also pick up a KernelInfoData (as SubKernelInfo) via KernelInfoImpl, but
133 // it will instead get the unspecialized case, defined above.
134 template <class KernelNameType> struct KernelInfo {
135  using SubKernelInfo = typename KernelInfoImpl<KernelNameType>::type;
136  static constexpr unsigned getNumParams() {
137  return SubKernelInfo::getNumParams();
138  }
139  static const kernel_param_desc_t &getParamDesc(int Idx) {
140  return SubKernelInfo::getParamDesc(Idx);
141  }
142  static constexpr const char *getName() { return SubKernelInfo::getName(); }
143  static constexpr bool isESIMD() { return SubKernelInfo::isESIMD(); }
144  static constexpr const char *getFileName() { return ""; }
145  static constexpr const char *getFunctionName() { return ""; }
146  static constexpr unsigned getLineNumber() { return 0; }
147  static constexpr unsigned getColumnNumber() { return 0; }
148  static constexpr int64_t getKernelSize() {
149  return SubKernelInfo::getKernelSize();
150  }
151 };
152 #endif //__SYCL_UNNAMED_LAMBDA__
153 
154 } // namespace detail
155 } // namespace _V1
156 } // namespace sycl
conditional< sizeof(long)==8, long, long long >::type int64_t
Definition: kernel_desc.hpp:35
const char * get_spec_constant_symbolic_ID()
const char * get_spec_constant_symbolic_ID_impl()
Definition: access.hpp:18
static constexpr unsigned getColumnNumber()
Definition: kernel_desc.hpp:89
static constexpr const char * getName()
Definition: kernel_desc.hpp:84
static constexpr unsigned getNumParams()
Definition: kernel_desc.hpp:79
static const kernel_param_desc_t & getParamDesc(int)
Definition: kernel_desc.hpp:80
static constexpr bool isESIMD()
Definition: kernel_desc.hpp:85
static constexpr const char * getFunctionName()
Definition: kernel_desc.hpp:87
static constexpr const char * getFileName()
Definition: kernel_desc.hpp:86
static constexpr int64_t getKernelSize()
Definition: kernel_desc.hpp:90
static constexpr unsigned getLineNumber()
Definition: kernel_desc.hpp:88
static constexpr const char * getName()
Definition: kernel_desc.hpp:64