19 #include <type_traits>
25 inline namespace _V1 {
32 template <
typename DataT>
34 std::is_pointer_v<DataT>>;
36 template <
typename DataT>
38 !std::is_pointer_v<DataT>>;
40 #if !defined(NDEBUG) && (_MSC_VER > 1929 || __has_builtin(__builtin_FILE))
41 #define __CODELOC_FILE_NAME __builtin_FILE()
43 #define __CODELOC_FILE_NAME nullptr
46 #if _MSC_VER > 1929 || __has_builtin(__builtin_FUNCTION)
47 #define __CODELOC_FUNCTION __builtin_FUNCTION()
49 #define __CODELOC_FUNCTION nullptr
52 #if _MSC_VER > 1929 || __has_builtin(__builtin_LINE)
53 #define __CODELOC_LINE __builtin_LINE()
55 #define __CODELOC_LINE 0
58 #if _MSC_VER > 1929 || __has_builtin(__builtin_COLUMN)
59 #define __CODELOC_COLUMN __builtin_COLUMN()
61 #define __CODELOC_COLUMN 0
75 #undef __CODELOC_FILE_NAME
76 #undef __CODELOC_FUNCTION
78 #undef __CODELOC_COLUMN
82 : MFileName(file), MFunctionName(
func), MLineNo(line), MColumnNo(col) {}
85 : MFileName(
nullptr), MFunctionName(
nullptr), MLineNo(0), MColumnNo(0) {}
93 const char *MFileName;
94 const char *MFunctionName;
95 unsigned long MLineNo;
96 unsigned long MColumnNo;
150 bool MLocalScope =
true;
157 #ifdef __SYCL_DEVICE_ONLY__
159 #define __SYCL_ASSERT(x)
161 #define __SYCL_ASSERT(x) assert(x)
164 #define __SYCL_UR_ERROR_REPORT \
165 "Native API failed. " \
168 "Native API returns: "
173 inline namespace _V1 {
178 template <
int Val>
static T<N>
get();
183 template <
int Val>
static T<1>
get() {
return T<1>{Val}; }
188 template <
int Val>
static T<2>
get() {
return T<2>{Val, Val}; }
193 template <
int Val>
static T<3>
get() {
return T<3>{Val, Val, Val}; }
197 template <
int NDims,
int Dim,
template <
int>
class LoopBoundTy,
typename FuncTy,
198 template <
int>
class LoopIndexTy>
201 const LoopBoundTy<NDims> &Stride,
202 const LoopBoundTy<NDims> &UpperBound, FuncTy f,
203 LoopIndexTy<NDims> &Index) {
204 constexpr
size_t AdjIdx = NDims - 1 - Dim;
205 for (Index[AdjIdx] = LowerBound[AdjIdx]; Index[AdjIdx] < UpperBound[AdjIdx];
206 Index[AdjIdx] += Stride[AdjIdx]) {
209 LowerBound, Stride, UpperBound, f, Index};
215 template <
int NDims,
template <
int>
class LoopBoundTy,
typename FuncTy,
216 template <
int>
class LoopIndexTy>
219 const LoopBoundTy<NDims> &Stride,
220 const LoopBoundTy<NDims> &UpperBound, FuncTy f,
221 LoopIndexTy<NDims> &Index) {
223 constexpr
size_t AdjIdx = NDims - 1;
224 for (Index[AdjIdx] = LowerBound[AdjIdx]; Index[AdjIdx] < UpperBound[AdjIdx];
225 Index[AdjIdx] += Stride[AdjIdx]) {
242 template <
template <
int>
class LoopBoundTy,
typename FuncTy,
243 template <
int>
class LoopIndexTy = LoopBoundTy>
246 const LoopIndexTy<NDims> LowerBound =
248 const LoopBoundTy<NDims> Stride =
250 LoopIndexTy<NDims> Index =
254 LowerBound, Stride, UpperBound, f, Index};
260 template <
template <
int>
class LoopBoundTy,
typename FuncTy,
261 template <
int>
class LoopIndexTy = LoopBoundTy>
263 const LoopBoundTy<NDims> &Stride,
264 const LoopBoundTy<NDims> &UpperBound,
266 LoopIndexTy<NDims> Index =
269 LowerBound, Stride, UpperBound, f, Index};
285 template <
int Dims,
template <
int>
class T,
template <
int>
class U>
287 size_t LinearIndex = 0;
288 for (
int I = 0; I < Dims; ++I)
289 LinearIndex = LinearIndex * Range[I] + Index[I];
302 template <
int NewDim,
int DefaultValue,
template <
int>
class T,
int OldDim>
305 const int CopyDims = NewDim > OldDim ? OldDim : NewDim;
306 for (
int I = 0; I < CopyDims; ++I)
307 NewObj[I] = OldObj[I];
308 for (
int I = CopyDims; I < NewDim; ++I)
309 NewObj[I] = DefaultValue;
314 template <
typename T, std::size_t... Is1, std::size_t... Is2>
315 constexpr std::array<T,
sizeof...(Is1) +
sizeof...(Is2)>
317 const std::array<T,
sizeof...(Is2)> &A2,
318 std::index_sequence<Is1...>, std::index_sequence<Is2...>) {
319 return {A1[Is1]..., A2[Is2]...};
321 template <
typename T, std::
size_t N1, std::
size_t N2>
322 constexpr std::array<T, N1 + N2>
ConcatArrays(
const std::array<T, N1> &A1,
323 const std::array<T, N2> &A2) {
324 return ConcatArrays(A1, A2, std::make_index_sequence<N1>(),
325 std::make_index_sequence<N2>());
330 template <
typename DataT,
template <
typename,
typename>
typename FlattenF,
333 template <
typename DataT,
template <
typename,
typename>
typename FlattenF,
334 typename ArgT,
typename... ArgTN>
336 static constexpr
auto Create(
const ArgT &Arg,
const ArgTN &...Args) {
337 auto ImmArray = FlattenF<DataT, ArgT>()(Arg);
340 if constexpr (
sizeof...(Args) > 0)
347 template <
typename DataT,
template <
typename,
typename>
typename FlattenF>
349 static constexpr
auto Create() {
return std::array<DataT, 0>{}; }
354 template <
typename T,
size_t... Is>
355 static constexpr std::array<T,
sizeof...(Is)>
357 auto ReturnArg = [&](size_t) {
return Arg; };
358 return {ReturnArg(Is)...};
360 template <
size_t N,
typename T>
367 #define __SYCL_REPORT_EXCEPTION_TO_STREAM(str, e) \
369 std::cerr << str << " " << e.what() << std::endl; \
373 #define __SYCL_REPORT_EXCEPTION_TO_STREAM(str, e)
Data type that manages the code_location information in TLS.
std::function< void(interop_handle)> func
#define __CODELOC_FILE_NAME
#define __CODELOC_FUNCTION
#define __SYCL_ALWAYS_INLINE
std::enable_if_t< std::is_pointer_v< DataT > > EnableIfOutputPointerT
static T< NewDim > convertToArrayOfN(T< OldDim > OldObj)
size_t getLinearIndex(const T< Dims > &Index, const U< Dims > &Range)
constexpr size_t getNextPowerOfTwo(size_t Var)
std::enable_if_t< !std::is_pointer_v< DataT > > EnableIfOutputIteratorT
constexpr std::array< T, sizeof...(Is1)+sizeof...(Is2)> ConcatArrays(const std::array< T, sizeof...(Is1)> &A1, const std::array< T, sizeof...(Is2)> &A2, std::index_sequence< Is1... >, std::index_sequence< Is2... >)
constexpr size_t getNextPowerOfTwoHelper(size_t Var, size_t Offset)
ur_code_location_t codeLocationCallback(void *)
static constexpr std::array< T, sizeof...(Is)> RepeatValueHelper(const T &Arg, std::index_sequence< Is... >)
static constexpr std::array< T, N > RepeatValue(const T &Arg)
_Abi const simd< _Tp, _Abi > & noexcept
static constexpr auto Create(const ArgT &Arg, const ArgTN &...Args)
static constexpr auto Create()
NDLoopIterateImpl(const LoopIndexTy< NDims > &LowerBound, const LoopBoundTy< NDims > &Stride, const LoopBoundTy< NDims > &UpperBound, FuncTy f, LoopIndexTy< NDims > &Index)
Helper class for the NDLoop.
NDLoopIterateImpl(const LoopIndexTy< NDims > &LowerBound, const LoopBoundTy< NDims > &Stride, const LoopBoundTy< NDims > &UpperBound, FuncTy f, LoopIndexTy< NDims > &Index)
Generates an NDims-dimensional perfect loop nest.
static __SYCL_ALWAYS_INLINE void iterate(const LoopBoundTy< NDims > &UpperBound, FuncTy f)
Generates ND loop nest with {0,..0} .
static __SYCL_ALWAYS_INLINE void iterate(const LoopIndexTy< NDims > &LowerBound, const LoopBoundTy< NDims > &Stride, const LoopBoundTy< NDims > &UpperBound, FuncTy f)
Generates ND loop nest with LowerBound .
static constexpr code_location current(const char *fileName=__CODELOC_FILE_NAME, const char *funcName=__CODELOC_FUNCTION, unsigned long lineNo=__CODELOC_LINE, unsigned long columnNo=__CODELOC_COLUMN) noexcept
constexpr code_location(const char *file, const char *func, int line, int col) noexcept
constexpr code_location() noexcept
constexpr unsigned long columnNumber() const noexcept
constexpr const char * fileName() const noexcept
constexpr const char * functionName() const noexcept
constexpr unsigned long lineNumber() const noexcept