Skip to content

Commit 20a088e

Browse files
[SYCL] Use SYCL 2020 exception in ext/oneapi/matrix/* (#14485)
1 parent b87f456 commit 20a088e

File tree

2 files changed

+104
-107
lines changed

2 files changed

+104
-107
lines changed

sycl/include/sycl/ext/oneapi/matrix/matrix-intel.hpp

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
#include <sycl/access/access.hpp> // for address_space, decorated
1616
#include <sycl/builtins.hpp> // for fabs
1717
#include <sycl/detail/defines_elementary.hpp> // for __SYCL_ALWAYS_INLINE
18-
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_DEVICE
19-
#include <sycl/exception.hpp> // for runtime_error
18+
#include <sycl/exception.hpp>
2019
#include <sycl/ext/oneapi/bfloat16.hpp> // for bfloat16
2120
#include <sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr.hpp> // for annotated_ptr
2221
#include <sycl/group.hpp> // for group
@@ -122,8 +121,8 @@ class wi_element {
122121
const size_t col = coord[1];
123122
return std::make_tuple(row, col);
124123
#else
125-
throw runtime_error("joint matrix is not supported on host device.",
126-
PI_ERROR_INVALID_DEVICE);
124+
throw exception(make_error_code(errc::runtime),
125+
"joint matrix is not supported on host.");
127126
#endif // __SYCL_DEVICE_ONLY__
128127
}
129128

@@ -137,8 +136,8 @@ class wi_element {
137136
idx);
138137
return elem;
139138
#else
140-
throw runtime_error("joint matrix is not supported on host device.",
141-
PI_ERROR_INVALID_DEVICE);
139+
throw exception(make_error_code(errc::runtime),
140+
"joint matrix is not supported on host.");
142141
#endif // __SYCL_DEVICE_ONLY__
143142
}
144143

@@ -151,8 +150,8 @@ class wi_element {
151150
spv_scope_traits<Group>::value>(
152151
M.spvm, idx) != static_cast<storage_element_type>(0);
153152
#else
154-
throw runtime_error("joint matrix is not supported on host device.",
155-
PI_ERROR_INVALID_DEVICE);
153+
throw exception(make_error_code(errc::runtime),
154+
"joint matrix is not supported on host.");
156155
#endif // __SYCL_DEVICE_ONLY__
157156
}
158157

@@ -163,8 +162,8 @@ class wi_element {
163162
return *this;
164163
#else
165164
(void)rhs;
166-
throw runtime_error("joint matrix is not supported on host device.",
167-
PI_ERROR_INVALID_DEVICE);
165+
throw exception(make_error_code(errc::runtime),
166+
"joint matrix is not supported on host.");
168167
#endif // __SYCL_DEVICE_ONLY__
169168
}
170169

@@ -182,8 +181,8 @@ class wi_element {
182181
return *this;
183182
#else
184183
(void)rhs;
185-
throw runtime_error("joint matrix is not supported on host device.",
186-
PI_ERROR_INVALID_DEVICE);
184+
throw exception(make_error_code(errc::runtime),
185+
"joint matrix is not supported on host.");
187186
#endif // __SYCL_DEVICE_ONLY__
188187
}
189188

@@ -206,8 +205,8 @@ class wi_element {
206205
#define OP(op) \
207206
template <typename T2> wi_element &operator op##=(const T2 & rhs) { \
208207
(void)rhs; \
209-
throw runtime_error("joint matrix is not supported on host device.", \
210-
PI_ERROR_INVALID_DEVICE); \
208+
throw exception(make_error_code(errc::runtime), \
209+
"joint matrix is not supported on host."); \
211210
}
212211
#endif // __SYCL_DEVICE_ONLY__
213212
OP(+)
@@ -242,8 +241,8 @@ class wi_element<sycl::ext::oneapi::bfloat16, NumRows, NumCols, Use, Layout,
242241
const uint32_t col = coord[1];
243242
return std::make_tuple(row, col);
244243
#else
245-
throw runtime_error("joint matrix is not supported on host device.",
246-
PI_ERROR_INVALID_DEVICE);
244+
throw exception(make_error_code(errc::runtime),
245+
"joint matrix is not supported on host.");
247246
#endif // __SYCL_DEVICE_ONLY__
248247
}
249248

@@ -255,8 +254,8 @@ class wi_element<sycl::ext::oneapi::bfloat16, NumRows, NumCols, Use, Layout,
255254
spv_matrix_layout_traits<Layout>::value,
256255
spv_scope_traits<Group>::value>(M.spvm, idx);
257256
#else
258-
throw runtime_error("joint matrix is not supported on host device.",
259-
PI_ERROR_INVALID_DEVICE);
257+
throw exception(make_error_code(errc::runtime),
258+
"joint matrix is not supported on host.");
260259
#endif // __SYCL_DEVICE_ONLY__
261260
}
262261

@@ -270,8 +269,8 @@ class wi_element<sycl::ext::oneapi::bfloat16, NumRows, NumCols, Use, Layout,
270269
spv_scope_traits<Group>::value>(M.spvm, idx))) >=
271270
std::numeric_limits<float>::epsilon();
272271
#else
273-
throw runtime_error("joint matrix is not supported on host device.",
274-
PI_ERROR_INVALID_DEVICE);
272+
throw exception(make_error_code(errc::runtime),
273+
"joint matrix is not supported on host.");
275274
#endif // __SYCL_DEVICE_ONLY__
276275
}
277276

@@ -281,8 +280,8 @@ class wi_element<sycl::ext::oneapi::bfloat16, NumRows, NumCols, Use, Layout,
281280
return *this;
282281
#else
283282
(void)rhs;
284-
throw runtime_error("joint matrix is not supported on host device.",
285-
PI_ERROR_INVALID_DEVICE);
283+
throw exception(make_error_code(errc::runtime),
284+
"joint matrix is not supported on host.");
286285
#endif // __SYCL_DEVICE_ONLY__
287286
}
288287

@@ -301,8 +300,8 @@ class wi_element<sycl::ext::oneapi::bfloat16, NumRows, NumCols, Use, Layout,
301300
return *this;
302301
#else
303302
(void)rhs;
304-
throw runtime_error("joint matrix is not supported on host device.",
305-
PI_ERROR_INVALID_DEVICE);
303+
throw exception(make_error_code(errc::runtime),
304+
"joint matrix is not supported on host.");
306305
#endif // __SYCL_DEVICE_ONLY__
307306
}
308307

@@ -323,8 +322,8 @@ class wi_element<sycl::ext::oneapi::bfloat16, NumRows, NumCols, Use, Layout,
323322
#define OP(opassign, op) \
324323
wi_element &operator opassign(const sycl::ext::oneapi::bfloat16 & rhs) { \
325324
(void)rhs; \
326-
throw runtime_error("joint matrix is not supported on host device.", \
327-
PI_ERROR_INVALID_DEVICE); \
325+
throw exception(make_error_code(errc::runtime), \
326+
"joint matrix is not supported on host."); \
328327
}
329328
#endif // __SYCL_DEVICE_ONLY__
330329
OP(+=, +)
@@ -398,15 +397,15 @@ class wi_element<sycl::ext::oneapi::bfloat16, NumRows, NumCols, Use, Layout,
398397
const wi_element<sycl::ext::oneapi::bfloat16, NumRows, NumCols, Use, \
399398
Layout, Group> &, \
400399
const sycl::ext::oneapi::bfloat16 &) { \
401-
throw runtime_error("joint matrix is not supported on host device.", \
402-
PI_ERROR_INVALID_DEVICE); \
400+
throw exception(make_error_code(errc::runtime), \
401+
"joint matrix is not supported on host."); \
403402
} \
404403
friend type operator op( \
405404
const sycl::ext::oneapi::bfloat16 &, \
406405
const wi_element<sycl::ext::oneapi::bfloat16, NumRows, NumCols, Use, \
407406
Layout, Group> &) { \
408-
throw runtime_error("joint matrix is not supported on host device.", \
409-
PI_ERROR_INVALID_DEVICE); \
407+
throw exception(make_error_code(errc::runtime), \
408+
"joint matrix is not supported on host."); \
410409
}
411410
OP(sycl::ext::oneapi::bfloat16, +)
412411
OP(sycl::ext::oneapi::bfloat16, -)
@@ -451,8 +450,8 @@ class wi_data {
451450
#if __SYCL_DEVICE_ONLY__
452451
return __spirv_JointMatrixWorkItemLengthINTEL(jm.spvm);
453452
#else
454-
throw runtime_error("joint matrix is not supported on host device.",
455-
PI_ERROR_INVALID_DEVICE);
453+
throw exception(make_error_code(errc::runtime),
454+
"joint matrix is not supported on host.");
456455
#endif
457456
};
458457

@@ -496,10 +495,10 @@ joint_matrix_store(Group,
496495
std::ignore = src;
497496
std::ignore = dst;
498497
std::ignore = stride;
499-
throw runtime_error(
498+
throw exception(
499+
make_error_code(errc::runtime),
500500
"This version of the matrix extension is only currently supported on "
501-
"intel devices",
502-
PI_ERROR_INVALID_DEVICE);
501+
"intel devices");
503502
#else
504503
// intel's impl
505504
using DecorT = typename sycl::detail::DecoratedType<T, Space>::type;
@@ -518,8 +517,8 @@ joint_matrix_store(Group,
518517
std::ignore = src;
519518
std::ignore = dst;
520519
std::ignore = stride;
521-
throw runtime_error("joint matrix is not supported on host device.",
522-
PI_ERROR_INVALID_DEVICE);
520+
throw exception(make_error_code(errc::runtime),
521+
"joint matrix is not supported on host.");
523522
#endif // defined(__SYCL_DEVICE_ONLY__)
524523
}
525524

@@ -542,10 +541,10 @@ inline __SYCL_ALWAYS_INLINE void joint_matrix_store(
542541
std::ignore = src;
543542
std::ignore = dst;
544543
std::ignore = stride;
545-
throw runtime_error(
544+
throw exception(
545+
make_error_code(errc::runtime),
546546
"This version of the matrix extension is only currently supported on "
547-
"intel devices",
548-
PI_ERROR_INVALID_DEVICE);
547+
"intel devices");
549548
#else
550549
// intel's impl
551550
T *Ptr = dst.get();
@@ -563,8 +562,8 @@ inline __SYCL_ALWAYS_INLINE void joint_matrix_store(
563562
std::ignore = src;
564563
std::ignore = dst;
565564
std::ignore = stride;
566-
throw runtime_error("joint matrix is not supported on host device.",
567-
PI_ERROR_INVALID_DEVICE);
565+
throw exception(make_error_code(errc::runtime),
566+
"joint matrix is not supported on host.");
568567
#endif // defined(__SYCL_DEVICE_ONLY__)
569568
}
570569

@@ -599,8 +598,8 @@ inline __SYCL_ALWAYS_INLINE void joint_matrix_apply(
599598
std::ignore = sg;
600599
std::ignore = jm;
601600
std::ignore = lambda;
602-
throw runtime_error("joint matrix is not supported on host device.",
603-
PI_ERROR_INVALID_DEVICE);
601+
throw exception(make_error_code(errc::runtime),
602+
"joint matrix is not supported on host.");
604603
#endif
605604
}
606605

@@ -630,8 +629,8 @@ inline __SYCL_ALWAYS_INLINE void joint_matrix_fill_checked(
630629
std::ignore = Width;
631630
std::ignore = CoordX;
632631
std::ignore = CoordY;
633-
throw runtime_error("joint matrix is not supported on host device.",
634-
PI_ERROR_INVALID_DEVICE);
632+
throw exception(make_error_code(errc::runtime),
633+
"joint matrix is not supported on host.");
635634
#endif // defined(__SYCL_DEVICE_ONLY__)
636635
}
637636

@@ -668,8 +667,8 @@ inline __SYCL_ALWAYS_INLINE void joint_matrix_load_checked(
668667
std::ignore = Layout;
669668
std::ignore = CoordX;
670669
std::ignore = CoordY;
671-
throw runtime_error("joint matrix is not supported on host device.",
672-
PI_ERROR_INVALID_DEVICE);
670+
throw exception(make_error_code(errc::runtime),
671+
"joint matrix is not supported on host.");
673672
#endif // defined(__SYCL_DEVICE_ONLY__)
674673
}
675674

@@ -705,8 +704,8 @@ inline __SYCL_ALWAYS_INLINE void joint_matrix_load_checked(
705704
std::ignore = Width;
706705
std::ignore = CoordX;
707706
std::ignore = CoordY;
708-
throw runtime_error("joint matrix is not supported on host device.",
709-
PI_ERROR_INVALID_DEVICE);
707+
throw exception(make_error_code(errc::runtime),
708+
"joint matrix is not supported on host.");
710709
#endif // defined(__SYCL_DEVICE_ONLY__)
711710
}
712711

@@ -740,8 +739,8 @@ inline __SYCL_ALWAYS_INLINE void joint_matrix_store_checked(
740739
std::ignore = Layout;
741740
std::ignore = CoordX;
742741
std::ignore = CoordY;
743-
throw runtime_error("joint matrix is not supported on host device.",
744-
PI_ERROR_INVALID_DEVICE);
742+
throw exception(make_error_code(errc::runtime),
743+
"joint matrix is not supported on host.");
745744
#endif // defined(__SYCL_DEVICE_ONLY__)
746745
}
747746

@@ -773,8 +772,8 @@ inline __SYCL_ALWAYS_INLINE void joint_matrix_store_checked(
773772
std::ignore = Width;
774773
std::ignore = CoordX;
775774
std::ignore = CoordY;
776-
throw runtime_error("joint matrix is not supported on host device.",
777-
PI_ERROR_INVALID_DEVICE);
775+
throw exception(make_error_code(errc::runtime),
776+
"joint matrix is not supported on host.");
778777
#endif // defined(__SYCL_DEVICE_ONLY__)
779778
}
780779

@@ -808,8 +807,8 @@ inline __SYCL_ALWAYS_INLINE void joint_matrix_load_checked(
808807
std::ignore = Layout;
809808
std::ignore = CoordX;
810809
std::ignore = CoordY;
811-
throw runtime_error("joint matrix is not supported on host device.",
812-
PI_ERROR_INVALID_DEVICE);
810+
throw exception(make_error_code(errc::runtime),
811+
"joint matrix is not supported on host.");
813812
#endif // defined(__SYCL_DEVICE_ONLY__)
814813
}
815814

@@ -841,8 +840,8 @@ inline __SYCL_ALWAYS_INLINE void joint_matrix_load_checked(
841840
std::ignore = Width;
842841
std::ignore = CoordX;
843842
std::ignore = CoordY;
844-
throw runtime_error("joint matrix is not supported on host device.",
845-
PI_ERROR_INVALID_DEVICE);
843+
throw exception(make_error_code(errc::runtime),
844+
"joint matrix is not supported on host.");
846845
#endif // defined(__SYCL_DEVICE_ONLY__)
847846
}
848847

@@ -873,8 +872,8 @@ inline __SYCL_ALWAYS_INLINE void joint_matrix_store_checked(
873872
std::ignore = Layout;
874873
std::ignore = CoordX;
875874
std::ignore = CoordY;
876-
throw runtime_error("joint matrix is not supported on host device.",
877-
PI_ERROR_INVALID_DEVICE);
875+
throw exception(make_error_code(errc::runtime),
876+
"joint matrix is not supported on host.");
878877
#endif // defined(__SYCL_DEVICE_ONLY__)
879878
}
880879

@@ -902,8 +901,8 @@ inline __SYCL_ALWAYS_INLINE void joint_matrix_store_checked(
902901
std::ignore = Width;
903902
std::ignore = CoordX;
904903
std::ignore = CoordY;
905-
throw runtime_error("joint matrix is not supported on host device.",
906-
PI_ERROR_INVALID_DEVICE);
904+
throw exception(make_error_code(errc::runtime),
905+
"joint matrix is not supported on host.");
907906
#endif // defined(__SYCL_DEVICE_ONLY__)
908907
}
909908
// End out-of-bounds API

0 commit comments

Comments
 (0)