32 template <
typename DataT>
34 std::is_pointer<DataT>::value>;
36 template <
typename DataT>
38 !std::is_pointer<DataT>::value>;
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) {}
87 constexpr
unsigned long lineNumber() const noexcept {
return MLineNo; }
88 constexpr
unsigned long columnNumber() const noexcept {
return MColumnNo; }
89 constexpr
const char *
fileName() const noexcept {
return MFileName; }
90 constexpr
const char *
functionName() const noexcept {
return MFunctionName; }
93 const char *MFileName;
94 const char *MFunctionName;
95 unsigned long MLineNo;
96 unsigned long MColumnNo;
105 #ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
106 #define _CODELOCONLYPARAM(a) \
107 const detail::code_location a = detail::code_location::current()
108 #define _CODELOCPARAM(a) \
109 , const detail::code_location a = detail::code_location::current()
110 #define _CODELOCPARAMDEF(a) , const detail::code_location a
112 #define _CODELOCARG(a)
113 #define _CODELOCFW(a) , a
115 #define _CODELOCONLYPARAM(a)
116 #define _CODELOCPARAM(a)
118 #define _CODELOCARG(a) const detail::code_location a = {}
119 #define _CODELOCFW(a)
171 bool MLocalScope =
true;
193 #ifdef __SYCL_DEVICE_ONLY__
195 #define __SYCL_ASSERT(x)
197 #define __SYCL_ASSERT(x) assert(x)
198 #endif // #ifdef __SYCL_DEVICE_ONLY__
200 #define __SYCL_PI_ERROR_REPORT \
201 "Native API failed. " \
204 "Native API returns: "
206 #ifndef __SYCL_SUPPRESS_PI_ERROR_REPORT
209 #define __SYCL_REPORT_PI_ERR_TO_STREAM(expr) \
212 if (code != PI_SUCCESS) { \
213 std::cerr << __SYCL_PI_ERROR_REPORT << sycl::detail::codeToString(code) \
219 #ifndef SYCL_SUPPRESS_EXCEPTIONS
222 #define __SYCL_REPORT_PI_ERR_TO_EXC(expr, exc, str) \
225 if (code != PI_SUCCESS) { \
226 std::string err_str = \
227 str ? "\n" + std::string(str) + "\n" : std::string{}; \
228 throw exc(__SYCL_PI_ERROR_REPORT + sycl::detail::codeToString(code) + \
233 #define __SYCL_REPORT_PI_ERR_TO_EXC_THROW(code, exc, str) \
234 __SYCL_REPORT_PI_ERR_TO_EXC(code, exc, str)
235 #define __SYCL_REPORT_PI_ERR_TO_EXC_BASE(code) \
236 __SYCL_REPORT_PI_ERR_TO_EXC(code, sycl::runtime_error, nullptr)
238 #define __SYCL_REPORT_PI_ERR_TO_EXC_BASE(code) \
239 __SYCL_REPORT_PI_ERR_TO_STREAM(code)
242 #define __SYCL_REPORT_ERR_TO_EXC_VIA_ERRC(expr, errc) \
245 if (code != PI_SUCCESS) { \
246 throw sycl::exception(sycl::make_error_code(errc), \
247 __SYCL_PI_ERROR_REPORT + \
248 sycl::detail::codeToString(code)); \
251 #define __SYCL_REPORT_ERR_TO_EXC_THROW_VIA_ERRC(code, errc) \
252 __SYCL_REPORT_ERR_TO_EXC_VIA_ERRC(code, errc)
254 #ifdef __SYCL_SUPPRESS_PI_ERROR_REPORT
256 #define __SYCL_CHECK_OCL_CODE(X) (void)(X)
257 #define __SYCL_CHECK_OCL_CODE_THROW(X, EXC, STR) \
262 #define __SYCL_CHECK_OCL_CODE_NO_EXC(X) (void)(X)
264 #define __SYCL_CHECK_CODE_THROW_VIA_ERRC(X, ERRC) (void)(X)
267 #define __SYCL_CHECK_OCL_CODE(X) __SYCL_REPORT_PI_ERR_TO_EXC_BASE(X)
268 #define __SYCL_CHECK_OCL_CODE_THROW(X, EXC, STR) \
269 __SYCL_REPORT_PI_ERR_TO_EXC_THROW(X, EXC, STR)
270 #define __SYCL_CHECK_OCL_CODE_NO_EXC(X) __SYCL_REPORT_PI_ERR_TO_STREAM(X)
272 #define __SYCL_CHECK_CODE_THROW_VIA_ERRC(X, ERRC) \
273 __SYCL_REPORT_ERR_TO_EXC_THROW_VIA_ERRC(X, ERRC)
279 #define __SYCL_EBO __declspec(empty_bases)
301 assert(SyclObject.impl &&
"every constructor should create an impl");
302 return SyclObject.impl;
311 return SyclObject.impl.get();
325 template <
int Val>
static T<N>
get();
330 template <
int Val>
static T<1>
get() {
return T<1>{Val}; }
335 template <
int Val>
static T<2>
get() {
return T<2>{Val, Val}; }
340 template <
int Val>
static T<3>
get() {
return T<3>{Val, Val, Val}; }
344 template <
int NDims,
int Dim,
template <
int>
class LoopBoundTy,
typename FuncTy,
345 template <
int>
class LoopIndexTy>
348 const LoopBoundTy<NDims> &Stride,
349 const LoopBoundTy<NDims> &UpperBound, FuncTy f,
350 LoopIndexTy<NDims> &Index) {
351 constexpr
size_t AdjIdx = NDims - 1 - Dim;
352 for (Index[AdjIdx] = LowerBound[AdjIdx]; Index[AdjIdx] < UpperBound[AdjIdx];
353 Index[AdjIdx] += Stride[AdjIdx]) {
356 LowerBound, Stride, UpperBound, f, Index};
362 template <
int NDims,
template <
int>
class LoopBoundTy,
typename FuncTy,
363 template <
int>
class LoopIndexTy>
366 const LoopBoundTy<NDims> &Stride,
367 const LoopBoundTy<NDims> &UpperBound, FuncTy f,
368 LoopIndexTy<NDims> &Index) {
370 constexpr
size_t AdjIdx = NDims - 1;
371 for (Index[AdjIdx] = LowerBound[AdjIdx]; Index[AdjIdx] < UpperBound[AdjIdx];
372 Index[AdjIdx] += Stride[AdjIdx]) {
389 template <
template <
int>
class LoopBoundTy,
typename FuncTy,
390 template <
int>
class LoopIndexTy = LoopBoundTy>
393 const LoopIndexTy<NDims> LowerBound =
395 const LoopBoundTy<NDims> Stride =
397 LoopIndexTy<NDims> Index =
401 LowerBound, Stride, UpperBound, f, Index};
407 template <
template <
int>
class LoopBoundTy,
typename FuncTy,
408 template <
int>
class LoopIndexTy = LoopBoundTy>
410 const LoopBoundTy<NDims> &Stride,
411 const LoopBoundTy<NDims> &UpperBound,
413 LoopIndexTy<NDims> Index =
416 LowerBound, Stride, UpperBound, f, Index};
432 template <
int Dims,
template <
int>
class T,
template <
int>
class U>
434 size_t LinearIndex = 0;
435 for (
int I = 0; I < Dims; ++I)
436 LinearIndex = LinearIndex * Range[I] + Index[I];
450 static constexpr T value{};
453 template <
typename T> constexpr
T InlineVariableHelper<T>::value;
458 template <
int NewDim,
int DefaultValue,
template <
int>
class T,
int OldDim>
461 const int CopyDims = NewDim > OldDim ? OldDim : NewDim;
462 for (
int I = 0; I < CopyDims; ++I)
463 NewObj[I] = OldObj[I];
464 for (
int I = CopyDims; I < NewDim; ++I)
465 NewObj[I] = DefaultValue;
470 template <
typename T, std::size_t... Is1, std::size_t... Is2>
471 constexpr std::array<
T,
sizeof...(Is1) +
sizeof...(Is2)>
473 const std::array<T,
sizeof...(Is2)> &A2,
474 std::index_sequence<Is1...>, std::index_sequence<Is2...>) {
475 return {A1[Is1]..., A2[Is2]...};
477 template <
typename T, std::
size_t N1, std::
size_t N2>
478 constexpr std::array<T, N1 + N2>
ConcatArrays(
const std::array<T, N1> &A1,
479 const std::array<T, N2> &A2) {
480 return ConcatArrays(A1, A2, std::make_index_sequence<N1>(),
481 std::make_index_sequence<N2>());
486 template <
typename DataT,
template <
typename,
typename>
typename FlattenF,
489 template <
typename DataT,
template <
typename,
typename>
typename FlattenF,
490 typename ArgT,
typename... ArgTN>
492 static constexpr
auto Create(
const ArgT &Arg,
const ArgTN &...Args) {
493 auto ImmArray = FlattenF<DataT, ArgT>()(Arg);
496 if constexpr (
sizeof...(Args) > 0)
503 template <
typename DataT,
template <
typename,
typename>
typename FlattenF>
505 static constexpr
auto Create() {
return std::array<DataT, 0>{}; }
510 template <
typename T,
size_t... Is>
511 static constexpr std::array<
T,
sizeof...(Is)>
513 auto ReturnArg = [&](size_t) {
return Arg; };
514 return {ReturnArg(Is)...};
516 template <
size_t N,
typename T>