Skip to content

Commit fa4ef51

Browse files
[SYCL] Use SYCL 2020 exception in ext/oneapi/experimental/*.hpp (intel#14483)
1 parent e891924 commit fa4ef51

File tree

7 files changed

+99
-103
lines changed

7 files changed

+99
-103
lines changed

sycl/include/sycl/ext/oneapi/experimental/ballot_group.hpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
#pragma once
1010

1111
#include <sycl/aspects.hpp>
12-
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_DEVICE
1312
#include <sycl/detail/spirv.hpp>
1413
#include <sycl/detail/type_traits.hpp> // for is_group, is_user_cons...
15-
#include <sycl/exception.hpp> // for runtime_error
14+
#include <sycl/exception.hpp>
1615
#include <sycl/ext/oneapi/experimental/non_uniform_groups.hpp> // for GetMask
1716
#include <sycl/ext/oneapi/sub_group_mask.hpp> // for sub_group_mask
1817
#include <sycl/id.hpp> // for id
@@ -49,71 +48,71 @@ template <typename ParentGroup> class ballot_group {
4948
#ifdef __SYCL_DEVICE_ONLY__
5049
return (Predicate) ? 1 : 0;
5150
#else
52-
throw runtime_error("Non-uniform groups are not supported on host device.",
53-
PI_ERROR_INVALID_DEVICE);
51+
throw exception(make_error_code(errc::runtime),
52+
"Non-uniform groups are not supported on host.");
5453
#endif
5554
}
5655

5756
id_type get_local_id() const {
5857
#ifdef __SYCL_DEVICE_ONLY__
5958
return sycl::detail::CallerPositionInMask(Mask);
6059
#else
61-
throw runtime_error("Non-uniform groups are not supported on host device.",
62-
PI_ERROR_INVALID_DEVICE);
60+
throw exception(make_error_code(errc::runtime),
61+
"Non-uniform groups are not supported on host.");
6362
#endif
6463
}
6564

6665
range_type get_group_range() const {
6766
#ifdef __SYCL_DEVICE_ONLY__
6867
return 2;
6968
#else
70-
throw runtime_error("Non-uniform groups are not supported on host device.",
71-
PI_ERROR_INVALID_DEVICE);
69+
throw exception(make_error_code(errc::runtime),
70+
"Non-uniform groups are not supported on host.");
7271
#endif
7372
}
7473

7574
range_type get_local_range() const {
7675
#ifdef __SYCL_DEVICE_ONLY__
7776
return Mask.count();
7877
#else
79-
throw runtime_error("Non-uniform groups are not supported on host device.",
80-
PI_ERROR_INVALID_DEVICE);
78+
throw exception(make_error_code(errc::runtime),
79+
"Non-uniform groups are not supported on host.");
8180
#endif
8281
}
8382

8483
linear_id_type get_group_linear_id() const {
8584
#ifdef __SYCL_DEVICE_ONLY__
8685
return static_cast<linear_id_type>(get_group_id()[0]);
8786
#else
88-
throw runtime_error("Non-uniform groups are not supported on host device.",
89-
PI_ERROR_INVALID_DEVICE);
87+
throw exception(make_error_code(errc::runtime),
88+
"Non-uniform groups are not supported on host.");
9089
#endif
9190
}
9291

9392
linear_id_type get_local_linear_id() const {
9493
#ifdef __SYCL_DEVICE_ONLY__
9594
return static_cast<linear_id_type>(get_local_id()[0]);
9695
#else
97-
throw runtime_error("Non-uniform groups are not supported on host device.",
98-
PI_ERROR_INVALID_DEVICE);
96+
throw exception(make_error_code(errc::runtime),
97+
"Non-uniform groups are not supported on host.");
9998
#endif
10099
}
101100

102101
linear_id_type get_group_linear_range() const {
103102
#ifdef __SYCL_DEVICE_ONLY__
104103
return static_cast<linear_id_type>(get_group_range()[0]);
105104
#else
106-
throw runtime_error("Non-uniform groups are not supported on host device.",
107-
PI_ERROR_INVALID_DEVICE);
105+
throw exception(make_error_code(errc::runtime),
106+
"Non-uniform groups are not supported on host.");
108107
#endif
109108
}
110109

111110
linear_id_type get_local_linear_range() const {
112111
#ifdef __SYCL_DEVICE_ONLY__
113112
return static_cast<linear_id_type>(get_local_range()[0]);
114113
#else
115-
throw runtime_error("Non-uniform groups are not supported on host device.",
116-
PI_ERROR_INVALID_DEVICE);
114+
throw exception(make_error_code(errc::runtime),
115+
"Non-uniform groups are not supported on host.");
117116
#endif
118117
}
119118

@@ -122,8 +121,8 @@ template <typename ParentGroup> class ballot_group {
122121
uint32_t Lowest = static_cast<uint32_t>(Mask.find_low()[0]);
123122
return __spirv_SubgroupLocalInvocationId() == Lowest;
124123
#else
125-
throw runtime_error("Non-uniform groups are not supported on host device.",
126-
PI_ERROR_INVALID_DEVICE);
124+
throw exception(make_error_code(errc::runtime),
125+
"Non-uniform groups are not supported on host.");
127126
#endif
128127
}
129128

@@ -165,8 +164,8 @@ get_ballot_group(Group group, bool predicate) {
165164
#endif
166165
#else
167166
(void)predicate;
168-
throw runtime_error("Non-uniform groups are not supported on host device.",
169-
PI_ERROR_INVALID_DEVICE);
167+
throw exception(make_error_code(errc::runtime),
168+
"Non-uniform groups are not supported on host.");
170169
#endif
171170
}
172171

sycl/include/sycl/ext/oneapi/experimental/builtins.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ namespace ext::oneapi::experimental {
7171
//
7272
// - OpenCL spec defines several additional features, like, for example, 'v'
7373
// modifier which allows to print OpenCL vectors: note that these features are
74-
// not available on host device and therefore their usage should be either
75-
// guarded using __SYCL_DEVICE_ONLY__ preprocessor macro or avoided in favor
76-
// of more portable solutions if needed
74+
// not available on host and therefore their usage should be either guarded
75+
// using __SYCL_DEVICE_ONLY__ preprocessor macro or avoided in favor of more
76+
// portable solutions if needed
7777
//
7878
template <typename FormatT, typename... Args>
7979
int printf(const FormatT *__format, Args... args) {

sycl/include/sycl/ext/oneapi/experimental/fixed_size_group.hpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
#pragma once
1010

1111
#include <sycl/aspects.hpp>
12-
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_DEVICE
1312
#include <sycl/detail/spirv.hpp>
1413
#include <sycl/detail/type_traits.hpp> // for is_fixed_size_group, is_group
15-
#include <sycl/exception.hpp> // for runtime_error
14+
#include <sycl/exception.hpp>
1615
#include <sycl/ext/oneapi/experimental/non_uniform_groups.hpp>
1716
#include <sycl/ext/oneapi/sub_group_mask.hpp> // for sub_group_mask
1817
#include <sycl/id.hpp> // for id
@@ -50,80 +49,80 @@ template <size_t PartitionSize, typename ParentGroup> class fixed_size_group {
5049
#ifdef __SYCL_DEVICE_ONLY__
5150
return __spirv_SubgroupLocalInvocationId() / PartitionSize;
5251
#else
53-
throw runtime_error("Non-uniform groups are not supported on host device.",
54-
PI_ERROR_INVALID_DEVICE);
52+
throw exception(make_error_code(errc::runtime),
53+
"Non-uniform groups are not supported on host.");
5554
#endif
5655
}
5756

5857
id_type get_local_id() const {
5958
#ifdef __SYCL_DEVICE_ONLY__
6059
return __spirv_SubgroupLocalInvocationId() % PartitionSize;
6160
#else
62-
throw runtime_error("Non-uniform groups are not supported on host device.",
63-
PI_ERROR_INVALID_DEVICE);
61+
throw exception(make_error_code(errc::runtime),
62+
"Non-uniform groups are not supported on host.");
6463
#endif
6564
}
6665

6766
range_type get_group_range() const {
6867
#ifdef __SYCL_DEVICE_ONLY__
6968
return __spirv_SubgroupSize() / PartitionSize;
7069
#else
71-
throw runtime_error("Non-uniform groups are not supported on host device.",
72-
PI_ERROR_INVALID_DEVICE);
70+
throw exception(make_error_code(errc::runtime),
71+
"Non-uniform groups are not supported on host.");
7372
#endif
7473
}
7574

7675
range_type get_local_range() const {
7776
#ifdef __SYCL_DEVICE_ONLY__
7877
return PartitionSize;
7978
#else
80-
throw runtime_error("Non-uniform groups are not supported on host device.",
81-
PI_ERROR_INVALID_DEVICE);
79+
throw exception(make_error_code(errc::runtime),
80+
"Non-uniform groups are not supported on host.");
8281
#endif
8382
}
8483

8584
linear_id_type get_group_linear_id() const {
8685
#ifdef __SYCL_DEVICE_ONLY__
8786
return static_cast<linear_id_type>(get_group_id()[0]);
8887
#else
89-
throw runtime_error("Non-uniform groups are not supported on host device.",
90-
PI_ERROR_INVALID_DEVICE);
88+
throw exception(make_error_code(errc::runtime),
89+
"Non-uniform groups are not supported on host.");
9190
#endif
9291
}
9392

9493
linear_id_type get_local_linear_id() const {
9594
#ifdef __SYCL_DEVICE_ONLY__
9695
return static_cast<linear_id_type>(get_local_id()[0]);
9796
#else
98-
throw runtime_error("Non-uniform groups are not supported on host device.",
99-
PI_ERROR_INVALID_DEVICE);
97+
throw exception(make_error_code(errc::runtime),
98+
"Non-uniform groups are not supported on host.");
10099
#endif
101100
}
102101

103102
linear_id_type get_group_linear_range() const {
104103
#ifdef __SYCL_DEVICE_ONLY__
105104
return static_cast<linear_id_type>(get_group_range()[0]);
106105
#else
107-
throw runtime_error("Non-uniform groups are not supported on host device.",
108-
PI_ERROR_INVALID_DEVICE);
106+
throw exception(make_error_code(errc::runtime),
107+
"Non-uniform groups are not supported on host.");
109108
#endif
110109
}
111110

112111
linear_id_type get_local_linear_range() const {
113112
#ifdef __SYCL_DEVICE_ONLY__
114113
return static_cast<linear_id_type>(get_local_range()[0]);
115114
#else
116-
throw runtime_error("Non-uniform groups are not supported on host device.",
117-
PI_ERROR_INVALID_DEVICE);
115+
throw exception(make_error_code(errc::runtime),
116+
"Non-uniform groups are not supported on host.");
118117
#endif
119118
}
120119

121120
bool leader() const {
122121
#ifdef __SYCL_DEVICE_ONLY__
123122
return get_local_linear_id() == 0;
124123
#else
125-
throw runtime_error("Non-uniform groups are not supported on host device.",
126-
PI_ERROR_INVALID_DEVICE);
124+
throw exception(make_error_code(errc::runtime),
125+
"Non-uniform groups are not supported on host.");
127126
#endif
128127
}
129128

@@ -168,8 +167,8 @@ get_fixed_size_group(Group group) {
168167
return fixed_size_group<PartitionSize, sycl::sub_group>();
169168
#endif
170169
#else
171-
throw runtime_error("Non-uniform groups are not supported on host device.",
172-
PI_ERROR_INVALID_DEVICE);
170+
throw exception(make_error_code(errc::runtime),
171+
"Non-uniform groups are not supported on host.");
173172
#endif
174173
}
175174

sycl/include/sycl/ext/oneapi/experimental/opportunistic_group.hpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
#pragma once
1010

1111
#include <sycl/aspects.hpp>
12-
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_DEVICE
1312
#include <sycl/detail/spirv.hpp>
1413
#include <sycl/detail/type_traits.hpp> // for is_group, is_user_cons...
15-
#include <sycl/exception.hpp> // for runtime_error
14+
#include <sycl/exception.hpp>
1615
#include <sycl/ext/oneapi/experimental/non_uniform_groups.hpp>
1716
#include <sycl/ext/oneapi/free_function_queries.hpp> // for this_sub_group
1817
#include <sycl/ext/oneapi/sub_group_mask.hpp> // for sub_group_mask
@@ -55,71 +54,71 @@ class opportunistic_group {
5554
#ifdef __SYCL_DEVICE_ONLY__
5655
return static_cast<id_type>(0);
5756
#else
58-
throw runtime_error("Non-uniform groups are not supported on host device.",
59-
PI_ERROR_INVALID_DEVICE);
57+
throw exception(make_error_code(errc::runtime),
58+
"Non-uniform groups are not supported on host.");
6059
#endif
6160
}
6261

6362
id_type get_local_id() const {
6463
#ifdef __SYCL_DEVICE_ONLY__
6564
return sycl::detail::CallerPositionInMask(Mask);
6665
#else
67-
throw runtime_error("Non-uniform groups are not supported on host device.",
68-
PI_ERROR_INVALID_DEVICE);
66+
throw exception(make_error_code(errc::runtime),
67+
"Non-uniform groups are not supported on host.");
6968
#endif
7069
}
7170

7271
range_type get_group_range() const {
7372
#ifdef __SYCL_DEVICE_ONLY__
7473
return 1;
7574
#else
76-
throw runtime_error("Non-uniform groups are not supported on host device.",
77-
PI_ERROR_INVALID_DEVICE);
75+
throw exception(make_error_code(errc::runtime),
76+
"Non-uniform groups are not supported on host.");
7877
#endif
7978
}
8079

8180
range_type get_local_range() const {
8281
#ifdef __SYCL_DEVICE_ONLY__
8382
return Mask.count();
8483
#else
85-
throw runtime_error("Non-uniform groups are not supported on host device.",
86-
PI_ERROR_INVALID_DEVICE);
84+
throw exception(make_error_code(errc::runtime),
85+
"Non-uniform groups are not supported on host.");
8786
#endif
8887
}
8988

9089
linear_id_type get_group_linear_id() const {
9190
#ifdef __SYCL_DEVICE_ONLY__
9291
return static_cast<linear_id_type>(get_group_id()[0]);
9392
#else
94-
throw runtime_error("Non-uniform groups are not supported on host device.",
95-
PI_ERROR_INVALID_DEVICE);
93+
throw exception(make_error_code(errc::runtime),
94+
"Non-uniform groups are not supported on host.");
9695
#endif
9796
}
9897

9998
linear_id_type get_local_linear_id() const {
10099
#ifdef __SYCL_DEVICE_ONLY__
101100
return static_cast<linear_id_type>(get_local_id()[0]);
102101
#else
103-
throw runtime_error("Non-uniform groups are not supported on host device.",
104-
PI_ERROR_INVALID_DEVICE);
102+
throw exception(make_error_code(errc::runtime),
103+
"Non-uniform groups are not supported on host.");
105104
#endif
106105
}
107106

108107
linear_id_type get_group_linear_range() const {
109108
#ifdef __SYCL_DEVICE_ONLY__
110109
return static_cast<linear_id_type>(get_group_range()[0]);
111110
#else
112-
throw runtime_error("Non-uniform groups are not supported on host device.",
113-
PI_ERROR_INVALID_DEVICE);
111+
throw exception(make_error_code(errc::runtime),
112+
"Non-uniform groups are not supported on host.");
114113
#endif
115114
}
116115

117116
linear_id_type get_local_linear_range() const {
118117
#ifdef __SYCL_DEVICE_ONLY__
119118
return static_cast<linear_id_type>(get_local_range()[0]);
120119
#else
121-
throw runtime_error("Non-uniform groups are not supported on host device.",
122-
PI_ERROR_INVALID_DEVICE);
120+
throw exception(make_error_code(errc::runtime),
121+
"Non-uniform groups are not supported on host.");
123122
#endif
124123
}
125124

@@ -128,8 +127,8 @@ class opportunistic_group {
128127
uint32_t Lowest = static_cast<uint32_t>(Mask.find_low()[0]);
129128
return __spirv_SubgroupLocalInvocationId() == Lowest;
130129
#else
131-
throw runtime_error("Non-uniform groups are not supported on host device.",
132-
PI_ERROR_INVALID_DEVICE);
130+
throw exception(make_error_code(errc::runtime),
131+
"Non-uniform groups are not supported on host.");
133132
#endif
134133
}
135134

@@ -162,8 +161,8 @@ inline opportunistic_group get_opportunistic_group() {
162161
return opportunistic_group(mask);
163162
#endif
164163
#else
165-
throw runtime_error("Non-uniform groups are not supported on host device.",
166-
PI_ERROR_INVALID_DEVICE);
164+
throw exception(make_error_code(errc::runtime),
165+
"Non-uniform groups are not supported on host.");
167166
#endif
168167
}
169168

sycl/include/sycl/ext/oneapi/experimental/root_group.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ void group_barrier(ext::oneapi::experimental::root_group<dimensions> G,
115115
#else
116116
(void)G;
117117
(void)FenceScope;
118-
throw sycl::runtime_error("Barriers are not supported on host device",
119-
PI_ERROR_INVALID_DEVICE);
118+
throw sycl::exception(make_error_code(errc::runtime),
119+
"Barriers are not supported on host");
120120
#endif
121121
}
122122

0 commit comments

Comments
 (0)