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