Skip to content

Commit c87f6b2

Browse files
[SYCL] Use built-ins to retrieve kernel information (#15070)
Using built-ins is going to be the preferred way to fetch kernel information, while integration headers are still going to be used for cases where built-ins are unavailable (i.e., different host compiler). Additionally, switch to the new entry point attribute when using the built-ins.
1 parent ad494e9 commit c87f6b2

File tree

7 files changed

+207
-80
lines changed

7 files changed

+207
-80
lines changed

sycl/include/sycl/detail/kernel_desc.hpp

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,26 @@
1010

1111
// FIXME: include export.hpp because integration header emitted by the compiler
1212
// uses the macro defined in this header, but it doesn't explicitly include it.
13+
#include <sycl/detail/defines_elementary.hpp>
1314
#include <sycl/detail/export.hpp>
14-
1515
// This header file must not include any standard C++ header files.
1616

17+
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
18+
#if __has_builtin(__builtin_sycl_kernel_name)
19+
static_assert(__has_builtin(__builtin_sycl_kernel_param_count) &&
20+
__has_builtin(__builtin_sycl_kernel_name) &&
21+
__has_builtin(__builtin_sycl_kernel_param_access_target) &&
22+
__has_builtin(__builtin_sycl_kernel_param_size) &&
23+
__has_builtin(__builtin_sycl_kernel_param_offset) &&
24+
__has_builtin(__builtin_sycl_kernel_file_name) &&
25+
__has_builtin(__builtin_sycl_kernel_function_name) &&
26+
__has_builtin(__builtin_sycl_kernel_line_number) &&
27+
__has_builtin(__builtin_sycl_kernel_column_number));
28+
#else
29+
#define __INTEL_SYCL_USE_INTEGRATION_HEADERS 1
30+
#endif
31+
#endif
32+
1733
namespace sycl {
1834
inline namespace _V1 {
1935
namespace detail {
@@ -151,6 +167,92 @@ template <class KernelNameType> struct KernelInfo {
151167
};
152168
#endif //__SYCL_UNNAMED_LAMBDA__
153169

170+
// Built-ins accept an object due to lacking infrastructure support for
171+
// accepting types. The kernel name type itself isn't used because it might be
172+
// incomplete, cv-qualified, or not default constructible. Passing an object
173+
// also allows future extension for SYCL kernels defined as free functions.
174+
template <typename KNT> struct KernelIdentity {
175+
using type = KNT;
176+
};
177+
178+
template <typename KernelNameType> constexpr unsigned getKernelNumParams() {
179+
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
180+
return __builtin_sycl_kernel_param_count(KernelIdentity<KernelNameType>());
181+
#else
182+
return KernelInfo<KernelNameType>::getNumParams();
183+
#endif
184+
}
185+
186+
template <typename KernelNameType>
187+
kernel_param_desc_t getKernelParamDesc(int Idx) {
188+
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
189+
kernel_param_desc_t ParamDesc;
190+
ParamDesc.kind =
191+
__builtin_sycl_kernel_param_kind(KernelIdentity<KernelNameType>(), Idx);
192+
ParamDesc.info = ParamDesc.kind == kernel_param_kind_t::kind_accessor
193+
? __builtin_sycl_kernel_param_access_target(
194+
KernelIdentity<KernelNameType>(), Idx)
195+
: __builtin_sycl_kernel_param_size(
196+
KernelIdentity<KernelNameType>(), Idx);
197+
ParamDesc.offset =
198+
__builtin_sycl_kernel_param_offset(KernelIdentity<KernelNameType>(), Idx);
199+
return ParamDesc;
200+
#else
201+
return KernelInfo<KernelNameType>::getParamDesc(Idx);
202+
#endif
203+
}
204+
205+
template <typename KernelNameType> constexpr const char *getKernelName() {
206+
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
207+
return __builtin_sycl_kernel_name(KernelIdentity<KernelNameType>());
208+
#else
209+
return KernelInfo<KernelNameType>::getName();
210+
#endif
211+
}
212+
213+
template <typename KernelNameType> constexpr bool isKernelESIMD() {
214+
// TODO Needs a builtin counterpart
215+
return KernelInfo<KernelNameType>::isESIMD();
216+
}
217+
218+
template <typename KernelNameType> constexpr const char *getKernelFileName() {
219+
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
220+
return __builtin_sycl_kernel_file_name(KernelIdentity<KernelNameType>());
221+
#else
222+
return KernelInfo<KernelNameType>::getFileName();
223+
#endif
224+
}
225+
226+
template <typename KernelNameType>
227+
constexpr const char *getKernelFunctionName() {
228+
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
229+
return __builtin_sycl_kernel_function_name(KernelIdentity<KernelNameType>());
230+
#else
231+
return KernelInfo<KernelNameType>::getFunctionName();
232+
#endif
233+
}
234+
235+
template <typename KernelNameType> constexpr unsigned getKernelLineNumber() {
236+
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
237+
return __builtin_sycl_kernel_line_number(KernelIdentity<KernelNameType>());
238+
#else
239+
return KernelInfo<KernelNameType>::getLineNumber();
240+
#endif
241+
}
242+
243+
template <typename KernelNameType> constexpr unsigned getKernelColumnNumber() {
244+
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
245+
return __builtin_sycl_kernel_column_number(KernelIdentity<KernelNameType>());
246+
#else
247+
return KernelInfo<KernelNameType>::getColumnNumber();
248+
#endif
249+
}
250+
251+
template <typename KernelNameType> constexpr int64_t getKernelSize() {
252+
// TODO needs a builtin counterpart, but is currently only used for checking
253+
// cases with external host compiler, which use integration headers.
254+
return KernelInfo<KernelNameType>::getKernelSize();
255+
}
154256
} // namespace detail
155257
} // namespace _V1
156258
} // namespace sycl

0 commit comments

Comments
 (0)