49 template <
typename T,
typename =
void>
76 return static_cast<uint32_t
>(
sizeof(T));
84 template <
typename T_Direction>
87 if constexpr (T_Direction::reads_existing_data && T_Direction::writes_result)
91 else if constexpr (T_Direction::reads_existing_data)
95 else if constexpr (T_Direction::writes_result)
101 static_assert(T_Direction::reads_existing_data || T_Direction::writes_result,
"A kernel buffer direction must read or write");
114 template <
typename T_Param>
120 using Pointer = std::remove_cv_t<Value>;
122 kernelElementSize<typename Pointer::element_type>());
126 using Element = std::remove_cv_t<typename remove_pointer<Value>::type>;
127 constexpr
bool writesBack = std::is_lvalue_reference_v<T_Param> && std::is_const_v<Value> ==
false;
129 kernelElementSize<Element>());
131 else if constexpr (is_ndarray_v<Value>)
147 template <
typename T_Function>
150 template <
typename T_Return,
typename... T_Params>
155 static constexpr uint32_t ParamCount =
sizeof...(T_Params);
156 static constexpr std::array<uint64_t, KernelSignatureMaxParams> Params = {describeKernelParam<T_Params>()...};
161 template <
typename T_Signature, u
int32_t index>
164 template <
typename T_Signature, u
int32_t index>
167 template <
typename T_Signature, u
int32_t nameLength>
174 #define MU_KERNEL_SIGNATURE_PARAM(N) \
175 ".if %c[paramCount] > " #N "\n.4byte %c[low" #N "]\n.4byte %c[high" #N "]\n.endif\n"
177 #define MU_KERNEL_SIGNATURE_OPERANDS(N) \
178 [low##N] "i"(mu::detail::kernelSignatureParamLow<MuKernelSignature, N>), \
179 [high##N] "i"(mu::detail::kernelSignatureParamHigh<MuKernelSignature, N>)
187 #ifndef MU_KERNEL_SIGNATURE
189 #define MU_KERNEL_SIGNATURE(TARGET, NAME) \
191 using MuKernelSignature = mu::detail::KernelSignature_t<std::decay_t<decltype(TARGET)>>; \
192 static_assert(mu::detail::kernelSignatureRecordSizeOf<MuKernelSignature, sizeof(NAME) - 1> <= \
193 mu::detail::KernelSignatureMaxRecordSize, \
194 "Kernel name too long for a signature record"); \
195 __asm__ volatile(".pushsection .mu_kernel_sig,\"\",@progbits\n" \
196 ".4byte %c[magic]\n" \
197 ".2byte %c[version]\n" \
198 ".2byte %c[recordSize]\n" \
199 ".byte %c[paramCount]\n" \
201 ".2byte %c[nameLength]\n" \
203 MU_KERNEL_SIGNATURE_PARAM(0) \
204 MU_KERNEL_SIGNATURE_PARAM(1) \
205 MU_KERNEL_SIGNATURE_PARAM(2) \
206 MU_KERNEL_SIGNATURE_PARAM(3) \
207 MU_KERNEL_SIGNATURE_PARAM(4) \
208 MU_KERNEL_SIGNATURE_PARAM(5) \
209 MU_KERNEL_SIGNATURE_PARAM(6) \
210 MU_KERNEL_SIGNATURE_PARAM(7) \
211 MU_KERNEL_SIGNATURE_PARAM(8) \
212 ".asciz \"" NAME "\"\n" \
215 : [magic] "i"(mu::detail::KernelSignatureMagic), \
216 [version] "i"(mu::detail::KernelSignatureVersion), \
217 [recordSize] "i"(mu::detail::kernelSignatureRecordSizeOf<MuKernelSignature, sizeof(NAME) - 1>), \
218 [paramCount] "i"(MuKernelSignature::ParamCount), \
219 [nameLength] "i"(sizeof(NAME) - 1), \
220 MU_KERNEL_SIGNATURE_OPERANDS(0), MU_KERNEL_SIGNATURE_OPERANDS(1), \
221 MU_KERNEL_SIGNATURE_OPERANDS(2), MU_KERNEL_SIGNATURE_OPERANDS(3), \
222 MU_KERNEL_SIGNATURE_OPERANDS(4), MU_KERNEL_SIGNATURE_OPERANDS(5), \
223 MU_KERNEL_SIGNATURE_OPERANDS(6), MU_KERNEL_SIGNATURE_OPERANDS(7), \
224 MU_KERNEL_SIGNATURE_OPERANDS(8)); \
NDArray is a class that can be used in both host and device code. NDArray is automatically divided in...
bool_type< false > false_type
bool_type< true > true_type
constexpr uint8_t KernelParamWriteBack
constexpr uint32_t KernelSignatureMaxParams
constexpr uint64_t packKernelParam(KernelParamKind kind, KernelParamDirection direction, uint8_t flags, uint32_t size)
constexpr uint32_t kernelSignatureRecordSize(uint32_t paramCount, uint32_t nameLength)
constexpr uint32_t KernelSignatureHeaderSize
constexpr uint32_t KernelSignatureMagic
constexpr KernelParamDirection kernelParamDirection()
constexpr uint32_t kernelSignatureParamLow
constexpr uint32_t KernelSignatureParamSize
constexpr uint32_t KernelParamFlagsShift
constexpr uint32_t KernelParamSizeShift
constexpr uint32_t KernelParamDirectionShift
constexpr uint16_t KernelSignatureVersion
constexpr uint32_t kernelElementSize()
constexpr uint32_t kernelSignatureRecordSizeOf
constexpr uint32_t KernelSignatureMaxRecordSize
constexpr uint32_t kernelSignatureParamHigh
constexpr uint64_t describeKernelParam()
Extensions to the C++ standard library.