Skip to content

Commit fdd609a

Browse files
[SYCL][ABI-break] Add code_location parameter to the rest of sycl::queue methods (#9603)
code_location helps to improve error reporting and allow to detect exact code lines for failed command submission. --------- Signed-off-by: Tikhomirova, Kseniya <[email protected]>
1 parent 7618dff commit fdd609a

File tree

5 files changed

+162
-85
lines changed

5 files changed

+162
-85
lines changed

sycl/include/sycl/queue.hpp

Lines changed: 89 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,15 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
480480
/// trivially copyable.
481481
/// \param Count is the number of times to fill Pattern into Ptr.
482482
/// \return an event representing fill operation.
483-
template <typename T> event fill(void *Ptr, const T &Pattern, size_t Count) {
484-
// TODO: to add code location as parameter when ABI break is permitted
485-
const detail::code_location CodeLoc("sycl/queue.hpp", "fill", 0, 0);
486-
return submit([&](handler &CGH) { CGH.fill<T>(Ptr, Pattern, Count); },
487-
CodeLoc);
483+
template <typename T>
484+
event fill(void *Ptr, const T &Pattern,
485+
size_t Count _CODELOCPARAM(&CodeLoc)) {
486+
_CODELOCARG(&CodeLoc);
487+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
488+
489+
return submit([&](handler &CGH) {
490+
CGH.fill<T>(Ptr, Pattern, Count);
491+
} _CODELOCFW(CodeLoc));
488492
}
489493

490494
/// Fills the specified memory with the specified pattern.
@@ -496,11 +500,14 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
496500
/// \param DepEvent is an event that specifies the kernel dependencies.
497501
/// \return an event representing fill operation.
498502
template <typename T>
499-
event fill(void *Ptr, const T &Pattern, size_t Count, event DepEvent) {
503+
event fill(void *Ptr, const T &Pattern, size_t Count,
504+
event DepEvent _CODELOCPARAM(&CodeLoc)) {
505+
_CODELOCARG(&CodeLoc);
506+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
500507
return submit([&](handler &CGH) {
501508
CGH.depends_on(DepEvent);
502509
CGH.fill<T>(Ptr, Pattern, Count);
503-
});
510+
} _CODELOCFW(CodeLoc));
504511
}
505512

506513
/// Fills the specified memory with the specified pattern.
@@ -514,11 +521,13 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
514521
/// \return an event representing fill operation.
515522
template <typename T>
516523
event fill(void *Ptr, const T &Pattern, size_t Count,
517-
const std::vector<event> &DepEvents) {
524+
const std::vector<event> &DepEvents _CODELOCPARAM(&CodeLoc)) {
525+
_CODELOCARG(&CodeLoc);
526+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
518527
return submit([&](handler &CGH) {
519528
CGH.depends_on(DepEvents);
520529
CGH.fill<T>(Ptr, Pattern, Count);
521-
});
530+
} _CODELOCFW(CodeLoc));
522531
}
523532

524533
/// Fills the memory pointed by a USM pointer with the value specified.
@@ -530,7 +539,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
530539
/// \param Value is a value to be set. Value is cast as an unsigned char.
531540
/// \param Count is a number of bytes to fill.
532541
/// \return an event representing fill operation.
533-
event memset(void *Ptr, int Value, size_t Count);
542+
event memset(void *Ptr, int Value, size_t Count _CODELOCPARAM(&CodeLoc));
534543

535544
/// Fills the memory pointed by a USM pointer with the value specified.
536545
/// No operations is done if \param Count is zero. An exception is thrown
@@ -542,7 +551,8 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
542551
/// \param Count is a number of bytes to fill.
543552
/// \param DepEvent is an event that specifies the kernel dependencies.
544553
/// \return an event representing fill operation.
545-
event memset(void *Ptr, int Value, size_t Count, event DepEvent);
554+
event memset(void *Ptr, int Value, size_t Count,
555+
event DepEvent _CODELOCPARAM(&CodeLoc));
546556

547557
/// Fills the memory pointed by a USM pointer with the value specified.
548558
/// No operations is done if \param Count is zero. An exception is thrown
@@ -556,7 +566,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
556566
/// dependencies.
557567
/// \return an event representing fill operation.
558568
event memset(void *Ptr, int Value, size_t Count,
559-
const std::vector<event> &DepEvents);
569+
const std::vector<event> &DepEvents _CODELOCPARAM(&CodeLoc));
560570

561571
/// Copies data from one memory region to another, each is either a host
562572
/// pointer or a pointer within USM allocation accessible on the device
@@ -569,7 +579,8 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
569579
/// \param Src is a USM pointer to the source memory.
570580
/// \param Count is a number of bytes to copy.
571581
/// \return an event representing copy operation.
572-
event memcpy(void *Dest, const void *Src, size_t Count);
582+
event memcpy(void *Dest, const void *Src,
583+
size_t Count _CODELOCPARAM(&CodeLoc));
573584

574585
/// Copies data from one memory region to another, each is either a host
575586
/// pointer or a pointer within USM allocation accessible on the device
@@ -583,7 +594,8 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
583594
/// \param Count is a number of bytes to copy.
584595
/// \param DepEvent is an event that specifies the kernel dependencies.
585596
/// \return an event representing copy operation.
586-
event memcpy(void *Dest, const void *Src, size_t Count, event DepEvent);
597+
event memcpy(void *Dest, const void *Src, size_t Count,
598+
event DepEvent _CODELOCPARAM(&CodeLoc));
587599

588600
/// Copies data from one memory region to another, each is either a host
589601
/// pointer or a pointer within USM allocation accessible on the device
@@ -599,7 +611,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
599611
/// dependencies.
600612
/// \return an event representing copy operation.
601613
event memcpy(void *Dest, const void *Src, size_t Count,
602-
const std::vector<event> &DepEvents);
614+
const std::vector<event> &DepEvents _CODELOCPARAM(&CodeLoc));
603615

604616
/// Copies data from one memory region to another, each is either a host
605617
/// pointer or a pointer within USM allocation accessible on the device
@@ -670,7 +682,8 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
670682
/// \param Advice is a device-defined advice for the specified allocation.
671683
/// \return an event representing advice operation.
672684
__SYCL2020_DEPRECATED("use the overload with int Advice instead")
673-
event mem_advise(const void *Ptr, size_t Length, pi_mem_advice Advice);
685+
event mem_advise(const void *Ptr, size_t Length,
686+
pi_mem_advice Advice _CODELOCPARAM(&CodeLoc));
674687

675688
/// Provides additional information to the underlying runtime about how
676689
/// different allocations are used.
@@ -679,7 +692,8 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
679692
/// \param Length is a number of bytes in the allocation.
680693
/// \param Advice is a device-defined advice for the specified allocation.
681694
/// \return an event representing advice operation.
682-
event mem_advise(const void *Ptr, size_t Length, int Advice);
695+
event mem_advise(const void *Ptr, size_t Length,
696+
int Advice _CODELOCPARAM(&CodeLoc));
683697

684698
/// Provides additional information to the underlying runtime about how
685699
/// different allocations are used.
@@ -689,7 +703,8 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
689703
/// \param Advice is a device-defined advice for the specified allocation.
690704
/// \param DepEvent is an event that specifies the kernel dependencies.
691705
/// \return an event representing advice operation.
692-
event mem_advise(const void *Ptr, size_t Length, int Advice, event DepEvent);
706+
event mem_advise(const void *Ptr, size_t Length, int Advice,
707+
event DepEvent _CODELOCPARAM(&CodeLoc));
693708

694709
/// Provides additional information to the underlying runtime about how
695710
/// different allocations are used.
@@ -701,7 +716,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
701716
/// dependencies.
702717
/// \return an event representing advice operation.
703718
event mem_advise(const void *Ptr, size_t Length, int Advice,
704-
const std::vector<event> &DepEvents);
719+
const std::vector<event> &DepEvents _CODELOCPARAM(&CodeLoc));
705720

706721
/// Provides hints to the runtime library that data should be made available
707722
/// on a device earlier than Unified Shared Memory would normally require it
@@ -710,10 +725,11 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
710725
/// \param Ptr is a USM pointer to the memory to be prefetched to the device.
711726
/// \param Count is a number of bytes to be prefetched.
712727
/// \return an event representing prefetch operation.
713-
event prefetch(const void *Ptr, size_t Count) {
714-
// TODO: to add code location as parameter when ABI break is permitted
715-
const detail::code_location CodeLoc("sycl/queue.hpp", "prefetch", 0, 0);
716-
return submit([=](handler &CGH) { CGH.prefetch(Ptr, Count); }, CodeLoc);
728+
event prefetch(const void *Ptr, size_t Count _CODELOCPARAM(&CodeLoc)) {
729+
_CODELOCARG(&CodeLoc);
730+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
731+
return submit(
732+
[=](handler &CGH) { CGH.prefetch(Ptr, Count); } _CODELOCFW(CodeLoc));
717733
}
718734

719735
/// Provides hints to the runtime library that data should be made available
@@ -724,11 +740,14 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
724740
/// \param Count is a number of bytes to be prefetched.
725741
/// \param DepEvent is an event that specifies the kernel dependencies.
726742
/// \return an event representing prefetch operation.
727-
event prefetch(const void *Ptr, size_t Count, event DepEvent) {
743+
event prefetch(const void *Ptr, size_t Count,
744+
event DepEvent _CODELOCPARAM(&CodeLoc)) {
745+
_CODELOCARG(&CodeLoc);
746+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
728747
return submit([=](handler &CGH) {
729748
CGH.depends_on(DepEvent);
730749
CGH.prefetch(Ptr, Count);
731-
});
750+
} _CODELOCFW(CodeLoc));
732751
}
733752

734753
/// Provides hints to the runtime library that data should be made available
@@ -741,11 +760,13 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
741760
/// dependencies.
742761
/// \return an event representing prefetch operation.
743762
event prefetch(const void *Ptr, size_t Count,
744-
const std::vector<event> &DepEvents) {
763+
const std::vector<event> &DepEvents _CODELOCPARAM(&CodeLoc)) {
764+
_CODELOCARG(&CodeLoc);
765+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
745766
return submit([=](handler &CGH) {
746767
CGH.depends_on(DepEvents);
747768
CGH.prefetch(Ptr, Count);
748-
});
769+
} _CODELOCFW(CodeLoc));
749770
}
750771

751772
/// Copies data from one 2D memory region to another, both pointed by
@@ -1085,7 +1106,9 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
10851106
template <typename T, typename PropertyListT>
10861107
event memcpy(ext::oneapi::experimental::device_global<T, PropertyListT> &Dest,
10871108
const void *Src, size_t NumBytes, size_t Offset,
1088-
const std::vector<event> &DepEvents) {
1109+
const std::vector<event> &DepEvents _CODELOCPARAM(&CodeLoc)) {
1110+
_CODELOCARG(&CodeLoc);
1111+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
10891112
if (sizeof(T) < Offset + NumBytes)
10901113
throw sycl::exception(make_error_code(errc::invalid),
10911114
"Copy to device_global is out of bounds.");
@@ -1096,7 +1119,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
10961119
return submit([&](handler &CGH) {
10971120
CGH.depends_on(DepEvents);
10981121
return CGH.memcpy(Dest, Src, NumBytes, Offset);
1099-
});
1122+
} _CODELOCFW(CodeLoc));
11001123
}
11011124

11021125
constexpr bool IsDeviceImageScoped = PropertyListT::template has_property<
@@ -1120,7 +1143,9 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
11201143
template <typename T, typename PropertyListT>
11211144
event memcpy(ext::oneapi::experimental::device_global<T, PropertyListT> &Dest,
11221145
const void *Src, size_t NumBytes, size_t Offset,
1123-
event DepEvent) {
1146+
event DepEvent _CODELOCPARAM(&CodeLoc)) {
1147+
_CODELOCARG(&CodeLoc);
1148+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
11241149
return this->memcpy(Dest, Src, NumBytes, Offset,
11251150
std::vector<event>{DepEvent});
11261151
}
@@ -1138,7 +1163,9 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
11381163
template <typename T, typename PropertyListT>
11391164
event memcpy(ext::oneapi::experimental::device_global<T, PropertyListT> &Dest,
11401165
const void *Src, size_t NumBytes = sizeof(T),
1141-
size_t Offset = 0) {
1166+
size_t Offset = 0 _CODELOCPARAM(&CodeLoc)) {
1167+
_CODELOCARG(&CodeLoc);
1168+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
11421169
return this->memcpy(Dest, Src, NumBytes, Offset, std::vector<event>{});
11431170
}
11441171

@@ -1158,7 +1185,10 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
11581185
event
11591186
memcpy(void *Dest,
11601187
const ext::oneapi::experimental::device_global<T, PropertyListT> &Src,
1161-
size_t NumBytes, size_t Offset, const std::vector<event> &DepEvents) {
1188+
size_t NumBytes, size_t Offset,
1189+
const std::vector<event> &DepEvents _CODELOCPARAM(&CodeLoc)) {
1190+
_CODELOCARG(&CodeLoc);
1191+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
11621192
if (sizeof(T) < Offset + NumBytes)
11631193
throw sycl::exception(make_error_code(errc::invalid),
11641194
"Copy from device_global is out of bounds.");
@@ -1194,7 +1224,10 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
11941224
event
11951225
memcpy(void *Dest,
11961226
const ext::oneapi::experimental::device_global<T, PropertyListT> &Src,
1197-
size_t NumBytes, size_t Offset, event DepEvent) {
1227+
size_t NumBytes, size_t Offset,
1228+
event DepEvent _CODELOCPARAM(&CodeLoc)) {
1229+
_CODELOCARG(&CodeLoc);
1230+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
11981231
return this->memcpy(Dest, Src, NumBytes, Offset,
11991232
std::vector<event>{DepEvent});
12001233
}
@@ -1213,7 +1246,10 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
12131246
event
12141247
memcpy(void *Dest,
12151248
const ext::oneapi::experimental::device_global<T, PropertyListT> &Src,
1216-
size_t NumBytes = sizeof(T), size_t Offset = 0) {
1249+
size_t NumBytes = sizeof(T),
1250+
size_t Offset = 0 _CODELOCPARAM(&CodeLoc)) {
1251+
_CODELOCARG(&CodeLoc);
1252+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
12171253
return this->memcpy(Dest, Src, NumBytes, Offset, std::vector<event>{});
12181254
}
12191255

@@ -1234,7 +1270,9 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
12341270
event copy(const std::remove_all_extents_t<T> *Src,
12351271
ext::oneapi::experimental::device_global<T, PropertyListT> &Dest,
12361272
size_t Count, size_t StartIndex,
1237-
const std::vector<event> &DepEvents) {
1273+
const std::vector<event> &DepEvents _CODELOCPARAM(&CodeLoc)) {
1274+
_CODELOCARG(&CodeLoc);
1275+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
12381276
return this->memcpy(Dest, Src, Count * sizeof(std::remove_all_extents_t<T>),
12391277
StartIndex * sizeof(std::remove_all_extents_t<T>),
12401278
DepEvents);
@@ -1256,7 +1294,10 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
12561294
template <typename T, typename PropertyListT>
12571295
event copy(const std::remove_all_extents_t<T> *Src,
12581296
ext::oneapi::experimental::device_global<T, PropertyListT> &Dest,
1259-
size_t Count, size_t StartIndex, event DepEvent) {
1297+
size_t Count, size_t StartIndex,
1298+
event DepEvent _CODELOCPARAM(&CodeLoc)) {
1299+
_CODELOCARG(&CodeLoc);
1300+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
12601301
return this->memcpy(Dest, Src, Count * sizeof(std::remove_all_extents_t<T>),
12611302
StartIndex * sizeof(std::remove_all_extents_t<T>),
12621303
DepEvent);
@@ -1277,7 +1318,9 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
12771318
event copy(const std::remove_all_extents_t<T> *Src,
12781319
ext::oneapi::experimental::device_global<T, PropertyListT> &Dest,
12791320
size_t Count = sizeof(T) / sizeof(std::remove_all_extents_t<T>),
1280-
size_t StartIndex = 0) {
1321+
size_t StartIndex = 0 _CODELOCPARAM(&CodeLoc)) {
1322+
_CODELOCARG(&CodeLoc);
1323+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
12811324
return this->memcpy(Dest, Src, Count * sizeof(std::remove_all_extents_t<T>),
12821325
StartIndex * sizeof(std::remove_all_extents_t<T>));
12831326
}
@@ -1299,7 +1342,9 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
12991342
event
13001343
copy(const ext::oneapi::experimental::device_global<T, PropertyListT> &Src,
13011344
std::remove_all_extents_t<T> *Dest, size_t Count, size_t StartIndex,
1302-
const std::vector<event> &DepEvents) {
1345+
const std::vector<event> &DepEvents _CODELOCPARAM(&CodeLoc)) {
1346+
_CODELOCARG(&CodeLoc);
1347+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
13031348
return this->memcpy(Dest, Src, Count * sizeof(std::remove_all_extents_t<T>),
13041349
StartIndex * sizeof(std::remove_all_extents_t<T>),
13051350
DepEvents);
@@ -1322,7 +1367,9 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
13221367
event
13231368
copy(const ext::oneapi::experimental::device_global<T, PropertyListT> &Src,
13241369
std::remove_all_extents_t<T> *Dest, size_t Count, size_t StartIndex,
1325-
event DepEvent) {
1370+
event DepEvent _CODELOCPARAM(&CodeLoc)) {
1371+
_CODELOCARG(&CodeLoc);
1372+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
13261373
return this->memcpy(Dest, Src, Count * sizeof(std::remove_all_extents_t<T>),
13271374
StartIndex * sizeof(std::remove_all_extents_t<T>),
13281375
DepEvent);
@@ -1344,7 +1391,9 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
13441391
copy(const ext::oneapi::experimental::device_global<T, PropertyListT> &Src,
13451392
std::remove_all_extents_t<T> *Dest,
13461393
size_t Count = sizeof(T) / sizeof(std::remove_all_extents_t<T>),
1347-
size_t StartIndex = 0) {
1394+
size_t StartIndex = 0 _CODELOCPARAM(&CodeLoc)) {
1395+
_CODELOCARG(&CodeLoc);
1396+
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
13481397
return this->memcpy(Dest, Src, Count * sizeof(std::remove_all_extents_t<T>),
13491398
StartIndex * sizeof(std::remove_all_extents_t<T>));
13501399
}

0 commit comments

Comments
 (0)