Skip to content

Commit 8e59722

Browse files
[NFC][SYCL] Use CompileTimeKernelInfo instead of individual properties (intel#19968)
Factored out from intel#19929.
1 parent 87cc792 commit 8e59722

File tree

10 files changed

+123
-166
lines changed

10 files changed

+123
-166
lines changed

sycl/include/sycl/detail/compile_time_kernel_info.hpp

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,85 @@
1313
namespace sycl {
1414
inline namespace _V1 {
1515
namespace detail {
16-
inline namespace compile_time_kernel_info_v1 {
1716

17+
template <typename KernelNameType>
18+
constexpr kernel_param_desc_t getKernelParamDesc(int Idx) {
19+
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
20+
kernel_param_desc_t ParamDesc;
21+
ParamDesc.kind =
22+
__builtin_sycl_kernel_param_kind(KernelIdentity<KernelNameType>(), Idx);
23+
ParamDesc.info = ParamDesc.kind == kernel_param_kind_t::kind_accessor
24+
? __builtin_sycl_kernel_param_access_target(
25+
KernelIdentity<KernelNameType>(), Idx)
26+
: __builtin_sycl_kernel_param_size(
27+
KernelIdentity<KernelNameType>(), Idx);
28+
ParamDesc.offset =
29+
__builtin_sycl_kernel_param_offset(KernelIdentity<KernelNameType>(), Idx);
30+
return ParamDesc;
31+
#else
32+
return KernelInfo<KernelNameType>::getParamDesc(Idx);
33+
#endif
34+
}
35+
36+
inline namespace compile_time_kernel_info_v1 {
1837
// This is being passed across ABI boundary, so we don't use std::string_view,
1938
// at least for as long as we support user apps built with GNU libstdc++'s
2039
// pre-C++11 ABI.
2140
struct CompileTimeKernelInfoTy {
22-
detail::string_view Name;
41+
detail::string_view Name{};
2342
unsigned NumParams = 0;
2443
bool IsESIMD = false;
44+
// TODO: Can we just have code_location here?
2545
detail::string_view FileName{};
2646
detail::string_view FunctionName{};
2747
unsigned LineNumber = 0;
2848
unsigned ColumnNumber = 0;
2949
int64_t KernelSize = 0;
3050
using ParamDescGetterT = kernel_param_desc_t (*)(int);
3151
ParamDescGetterT ParamDescGetter = nullptr;
32-
bool HasSpecialCaptures = true;
52+
53+
bool HasSpecialCaptures = [this]() constexpr {
54+
// No-compile time info for the kernel (i.e., kernel_bundle/interop/etc.),
55+
// be conservative:
56+
if (NumParams == 0)
57+
return true;
58+
59+
for (unsigned I = 0; I < NumParams; ++I) {
60+
auto ParamDesc = ParamDescGetter(I);
61+
if (ParamDesc.kind != kernel_param_kind_t::kind_std_layout &&
62+
ParamDesc.kind != kernel_param_kind_t::kind_pointer)
63+
return true;
64+
}
65+
66+
return false;
67+
}();
3368
};
3469

3570
template <class Kernel>
3671
inline constexpr CompileTimeKernelInfoTy CompileTimeKernelInfo{
37-
std::string_view(getKernelName<Kernel>()),
38-
getKernelNumParams<Kernel>(),
39-
isKernelESIMD<Kernel>(),
40-
std::string_view(getKernelFileName<Kernel>()),
41-
std::string_view(getKernelFunctionName<Kernel>()),
42-
getKernelLineNumber<Kernel>(),
43-
getKernelColumnNumber<Kernel>(),
44-
getKernelSize<Kernel>(),
45-
&getKernelParamDesc<Kernel>,
46-
hasSpecialCaptures<Kernel>()};
47-
72+
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
73+
__builtin_sycl_kernel_name(KernelIdentity<Kernel>()),
74+
__builtin_sycl_kernel_param_count(KernelIdentity<Kernel>()),
75+
false /*IsESIMD*/, // TODO needs a builtin counterpart
76+
__builtin_sycl_kernel_file_name(KernelIdentity<Kernel>()),
77+
__builtin_sycl_kernel_function_name(KernelIdentity<Kernel>()),
78+
__builtin_sycl_kernel_line_number(KernelIdentity<Kernel>()),
79+
__builtin_sycl_kernel_column_number(KernelIdentity<Kernel>()),
80+
// TODO needs a builtin counterpart, but is currently only used for checking
81+
// cases with external host compiler, which use integration headers.
82+
0 /* KernelSize */, &getKernelParamDesc<Kernel>
83+
#else
84+
detail::string_view{KernelInfo<Kernel>::getName()},
85+
KernelInfo<Kernel>::getNumParams(), KernelInfo<Kernel>::isESIMD(),
86+
detail::string_view{KernelInfo<Kernel>::getFileName()},
87+
detail::string_view{KernelInfo<Kernel>::getFunctionName()},
88+
KernelInfo<Kernel>::getLineNumber(), KernelInfo<Kernel>::getColumnNumber(),
89+
KernelInfo<Kernel>::getKernelSize(),
90+
// Can't use KernelInfo::getParamDesc due to different return type (const
91+
// ref vs. by val):
92+
&getKernelParamDesc<Kernel>
93+
#endif
94+
};
4895
} // namespace compile_time_kernel_info_v1
4996
} // namespace detail
5097
} // namespace _V1

sycl/include/sycl/detail/kernel_desc.hpp

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -187,96 +187,6 @@ template <typename KNT> struct KernelIdentity {
187187
using type = KNT;
188188
};
189189

190-
template <typename KernelNameType> constexpr unsigned getKernelNumParams() {
191-
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
192-
return __builtin_sycl_kernel_param_count(KernelIdentity<KernelNameType>());
193-
#else
194-
return KernelInfo<KernelNameType>::getNumParams();
195-
#endif
196-
}
197-
198-
template <typename KernelNameType>
199-
constexpr kernel_param_desc_t getKernelParamDesc(int Idx) {
200-
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
201-
kernel_param_desc_t ParamDesc;
202-
ParamDesc.kind =
203-
__builtin_sycl_kernel_param_kind(KernelIdentity<KernelNameType>(), Idx);
204-
ParamDesc.info = ParamDesc.kind == kernel_param_kind_t::kind_accessor
205-
? __builtin_sycl_kernel_param_access_target(
206-
KernelIdentity<KernelNameType>(), Idx)
207-
: __builtin_sycl_kernel_param_size(
208-
KernelIdentity<KernelNameType>(), Idx);
209-
ParamDesc.offset =
210-
__builtin_sycl_kernel_param_offset(KernelIdentity<KernelNameType>(), Idx);
211-
return ParamDesc;
212-
#else
213-
return KernelInfo<KernelNameType>::getParamDesc(Idx);
214-
#endif
215-
}
216-
217-
template <typename KernelNameType> constexpr const char *getKernelName() {
218-
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
219-
return __builtin_sycl_kernel_name(KernelIdentity<KernelNameType>());
220-
#else
221-
return KernelInfo<KernelNameType>::getName();
222-
#endif
223-
}
224-
225-
template <typename KernelNameType> constexpr bool isKernelESIMD() {
226-
// TODO Needs a builtin counterpart
227-
return KernelInfo<KernelNameType>::isESIMD();
228-
}
229-
230-
template <typename KernelNameType> constexpr const char *getKernelFileName() {
231-
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
232-
return __builtin_sycl_kernel_file_name(KernelIdentity<KernelNameType>());
233-
#else
234-
return KernelInfo<KernelNameType>::getFileName();
235-
#endif
236-
}
237-
238-
template <typename KernelNameType>
239-
constexpr const char *getKernelFunctionName() {
240-
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
241-
return __builtin_sycl_kernel_function_name(KernelIdentity<KernelNameType>());
242-
#else
243-
return KernelInfo<KernelNameType>::getFunctionName();
244-
#endif
245-
}
246-
247-
template <typename KernelNameType> constexpr unsigned getKernelLineNumber() {
248-
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
249-
return __builtin_sycl_kernel_line_number(KernelIdentity<KernelNameType>());
250-
#else
251-
return KernelInfo<KernelNameType>::getLineNumber();
252-
#endif
253-
}
254-
255-
template <typename KernelNameType> constexpr unsigned getKernelColumnNumber() {
256-
#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS
257-
return __builtin_sycl_kernel_column_number(KernelIdentity<KernelNameType>());
258-
#else
259-
return KernelInfo<KernelNameType>::getColumnNumber();
260-
#endif
261-
}
262-
263-
template <typename KernelNameType> constexpr int64_t getKernelSize() {
264-
// TODO needs a builtin counterpart, but is currently only used for checking
265-
// cases with external host compiler, which use integration headers.
266-
return KernelInfo<KernelNameType>::getKernelSize();
267-
}
268-
269-
template <typename KernelNameType> constexpr bool hasSpecialCaptures() {
270-
bool FoundSpecialCapture = false;
271-
for (unsigned I = 0; I < getKernelNumParams<KernelNameType>(); ++I) {
272-
auto ParamDesc = getKernelParamDesc<KernelNameType>(I);
273-
bool IsSpecialCapture =
274-
(ParamDesc.kind != kernel_param_kind_t::kind_std_layout &&
275-
ParamDesc.kind != kernel_param_kind_t::kind_pointer);
276-
FoundSpecialCapture |= IsSpecialCapture;
277-
}
278-
return FoundSpecialCapture;
279-
}
280190
} // namespace detail
281191
} // namespace _V1
282192
} // namespace sycl

sycl/include/sycl/detail/kernel_launch_helper.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#pragma once
1010

1111
#include <sycl/detail/cg_types.hpp>
12+
#include <sycl/detail/compile_time_kernel_info.hpp>
1213
#include <sycl/detail/helpers.hpp>
1314
#include <sycl/ext/intel/experimental/fp_control_kernel_properties.hpp>
1415
#include <sycl/ext/intel/experimental/kernel_execution_properties.hpp>
@@ -261,7 +262,8 @@ struct KernelLaunchPropertyWrapper {
261262
if constexpr (ext::oneapi::experimental::detail::
262263
HasKernelPropertiesGetMethod<const KernelType &>::value) {
263264

264-
h->template processProperties<detail::isKernelESIMD<KernelName>()>(
265+
h->template processProperties<
266+
detail::CompileTimeKernelInfo<KernelName>.IsESIMD>(
265267
KernelFunc.get(ext::oneapi::experimental::properties_tag{}));
266268
}
267269
#endif

0 commit comments

Comments
 (0)