|
10 | 10 | #include <sycl/detail/kernel_desc.hpp> |
11 | 11 | #include <sycl/detail/string_view.hpp> |
12 | 12 |
|
| 13 | +#include <cassert> |
| 14 | + |
13 | 15 | namespace sycl { |
14 | 16 | inline namespace _V1 { |
15 | 17 | namespace detail { |
16 | | -inline namespace compile_time_kernel_info_v1 { |
17 | 18 |
|
| 19 | +template <typename KernelNameType> |
| 20 | +constexpr kernel_param_desc_t getKernelParamDesc(int Idx) { |
| 21 | +#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS |
| 22 | + kernel_param_desc_t ParamDesc; |
| 23 | + ParamDesc.kind = |
| 24 | + __builtin_sycl_kernel_param_kind(KernelIdentity<KernelNameType>(), Idx); |
| 25 | + ParamDesc.info = ParamDesc.kind == kernel_param_kind_t::kind_accessor |
| 26 | + ? __builtin_sycl_kernel_param_access_target( |
| 27 | + KernelIdentity<KernelNameType>(), Idx) |
| 28 | + : __builtin_sycl_kernel_param_size( |
| 29 | + KernelIdentity<KernelNameType>(), Idx); |
| 30 | + ParamDesc.offset = |
| 31 | + __builtin_sycl_kernel_param_offset(KernelIdentity<KernelNameType>(), Idx); |
| 32 | + return ParamDesc; |
| 33 | +#else |
| 34 | + return KernelInfo<KernelNameType>::getParamDesc(Idx); |
| 35 | +#endif |
| 36 | +} |
| 37 | + |
| 38 | +inline namespace compile_time_kernel_info_v1 { |
18 | 39 | // This is being passed across ABI boundary, so we don't use std::string_view, |
19 | 40 | // at least for as long as we support user apps built with GNU libstdc++'s |
20 | 41 | // pre-C++11 ABI. |
21 | 42 | struct CompileTimeKernelInfoTy { |
22 | | - detail::string_view Name; |
| 43 | + detail::string_view Name{}; |
23 | 44 | unsigned NumParams = 0; |
24 | 45 | bool IsESIMD = false; |
| 46 | + // TODO: Can we just have code_location here? |
25 | 47 | detail::string_view FileName{}; |
26 | 48 | detail::string_view FunctionName{}; |
27 | 49 | unsigned LineNumber = 0; |
28 | 50 | unsigned ColumnNumber = 0; |
29 | 51 | int64_t KernelSize = 0; |
30 | 52 | using ParamDescGetterT = kernel_param_desc_t (*)(int); |
31 | 53 | ParamDescGetterT ParamDescGetter = nullptr; |
32 | | - bool HasSpecialCaptures = true; |
| 54 | + |
| 55 | + bool HasSpecialCaptures = [this]() constexpr { |
| 56 | + // No-compile time info for the kernel (i.e., kernel_bundle/interop/etc.), |
| 57 | + // be conservative: |
| 58 | + if (NumParams == 0) |
| 59 | + return true; |
| 60 | + |
| 61 | + bool FoundSpecialCapture = false; |
| 62 | + for (unsigned I = 0; I < NumParams; ++I) { |
| 63 | + auto ParamDesc = ParamDescGetter(I); |
| 64 | + bool IsSpecialCapture = |
| 65 | + (ParamDesc.kind != kernel_param_kind_t::kind_std_layout && |
| 66 | + ParamDesc.kind != kernel_param_kind_t::kind_pointer); |
| 67 | + FoundSpecialCapture |= IsSpecialCapture; |
| 68 | + } |
| 69 | + return FoundSpecialCapture; |
| 70 | + }(); |
| 71 | + |
| 72 | + void refine(const CompileTimeKernelInfoTy &Other) { |
| 73 | + auto RefineField = [](auto &Self, const auto &Other, const auto &Default) { |
| 74 | + if (Self == Default) { |
| 75 | + Self = Other; |
| 76 | + } else if (Other != Default) { |
| 77 | + assert(Self == Other); |
| 78 | + } |
| 79 | + }; |
| 80 | + |
| 81 | + constexpr CompileTimeKernelInfoTy Empty; |
| 82 | + RefineField(Name, static_cast<std::string_view>(Other.Name), |
| 83 | + static_cast<std::string_view>(Empty.Name)); |
| 84 | + RefineField(NumParams, Other.NumParams, Empty.NumParams); |
| 85 | + RefineField(IsESIMD, Other.IsESIMD, Empty.IsESIMD); |
| 86 | + RefineField(FileName, static_cast<std::string_view>(Other.FileName), |
| 87 | + static_cast<std::string_view>(Empty.FileName)); |
| 88 | + RefineField(FunctionName, static_cast<std::string_view>(Other.FunctionName), |
| 89 | + static_cast<std::string_view>(Empty.FunctionName)); |
| 90 | + RefineField(LineNumber, Other.LineNumber, Empty.LineNumber); |
| 91 | + RefineField(ColumnNumber, Other.ColumnNumber, Empty.ColumnNumber); |
| 92 | + RefineField(KernelSize, Other.KernelSize, Empty.KernelSize); |
| 93 | + RefineField(ParamDescGetter, Other.ParamDescGetter, Empty.ParamDescGetter); |
| 94 | + RefineField(HasSpecialCaptures, Other.HasSpecialCaptures, |
| 95 | + Empty.HasSpecialCaptures); |
| 96 | + } |
33 | 97 | }; |
34 | 98 |
|
35 | 99 | template <class Kernel> |
36 | 100 | 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 | | - |
| 101 | +#ifndef __INTEL_SYCL_USE_INTEGRATION_HEADERS |
| 102 | + __builtin_sycl_kernel_name(KernelIdentity<Kernel>()), |
| 103 | + __builtin_sycl_kernel_param_count(KernelIdentity<Kernel>()), |
| 104 | + false /*IsESIMD*/, // TODO needs a builtin counterpart |
| 105 | + __builtin_sycl_kernel_file_name(KernelIdentity<Kernel>()), |
| 106 | + __builtin_sycl_kernel_function_name(KernelIdentity<Kernel>()), |
| 107 | + __builtin_sycl_kernel_line_number(KernelIdentity<Kernel>()), |
| 108 | + __builtin_sycl_kernel_column_number(KernelIdentity<Kernel>()), |
| 109 | + // TODO needs a builtin counterpart, but is currently only used for checking |
| 110 | + // cases with external host compiler, which use integration headers. |
| 111 | + 0 /* KernelSize */, &getKernelParamDesc<Kernel> |
| 112 | +#else |
| 113 | + detail::string_view{KernelInfo<Kernel>::getName()}, |
| 114 | + KernelInfo<Kernel>::getNumParams(), KernelInfo<Kernel>::isESIMD(), |
| 115 | + detail::string_view{KernelInfo<Kernel>::getFileName()}, |
| 116 | + detail::string_view{KernelInfo<Kernel>::getFunctionName()}, |
| 117 | + KernelInfo<Kernel>::getLineNumber(), KernelInfo<Kernel>::getColumnNumber(), |
| 118 | + KernelInfo<Kernel>::getKernelSize(), |
| 119 | + // Can't use KernelInfo::getParamDesc due to different return type (const |
| 120 | + // ref vs. by val): |
| 121 | + &getKernelParamDesc<Kernel> |
| 122 | +#endif |
| 123 | +}; |
48 | 124 | } // namespace compile_time_kernel_info_v1 |
49 | 125 | } // namespace detail |
50 | 126 | } // namespace _V1 |
|
0 commit comments