Skip to content

Commit e3c2570

Browse files
AlexeySachkovChenyang-L
authored andcommitted
[SYCL] Use sycl::exception instead of sycl::runtime_error (#10217)
`sycl::runtime_error` is deprecated in SYCL 2020. Therefore, removing its uses (at least some) from our RT headers. This PR **does not** cover: - some of our extensions, like `fixed_size_group` or `matrix` - `detail/common.hpp`, because it depends on RT library update - RT library (i.e. `source/` dir)
1 parent ed9e4aa commit e3c2570

File tree

12 files changed

+152
-152
lines changed

12 files changed

+152
-152
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,8 +843,9 @@ class image_accessor
843843

844844
sycl::vec<int, Dimensions> getRangeInternal() const {
845845
// TODO: Implement for host.
846-
throw runtime_error("image::getRangeInternal() is not implemented for host",
847-
PI_ERROR_INVALID_OPERATION);
846+
throw sycl::exception(
847+
make_error_code(errc::feature_not_supported),
848+
"image::getRangeInternal() is not implemented for host");
848849
return sycl::vec<int, Dimensions>{1};
849850
}
850851

sycl/include/sycl/backend.hpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,8 @@ auto get_native_buffer(const buffer<DataT, Dimensions, AllocatorT, void> &Obj)
114114
// No check for backend mismatch because buffer can be allocated on different
115115
// backends
116116
if (BackendName == backend::ext_oneapi_level_zero)
117-
throw sycl::runtime_error(
118-
errc::feature_not_supported,
119-
"Buffer interop is not supported by level zero yet",
120-
PI_ERROR_INVALID_OPERATION);
117+
throw sycl::exception(make_error_code(errc::feature_not_supported),
118+
"Buffer interop is not supported by level zero yet");
121119
return Obj.template getNative<BackendName>();
122120
}
123121
#endif
@@ -126,21 +124,19 @@ auto get_native_buffer(const buffer<DataT, Dimensions, AllocatorT, void> &Obj)
126124
template <backend BackendName, class SyclObjectT>
127125
auto get_native(const SyclObjectT &Obj)
128126
-> backend_return_t<BackendName, SyclObjectT> {
129-
// TODO use SYCL 2020 exception when implemented
130127
if (Obj.get_backend() != BackendName) {
131-
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
132-
PI_ERROR_INVALID_OPERATION);
128+
throw sycl::exception(make_error_code(errc::backend_mismatch),
129+
"Backends mismatch");
133130
}
134131
return reinterpret_cast<backend_return_t<BackendName, SyclObjectT>>(
135132
Obj.getNative());
136133
}
137134

138135
template <backend BackendName>
139136
auto get_native(const queue &Obj) -> backend_return_t<BackendName, queue> {
140-
// TODO use SYCL 2020 exception when implemented
141137
if (Obj.get_backend() != BackendName) {
142-
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
143-
PI_ERROR_INVALID_OPERATION);
138+
throw sycl::exception(make_error_code(errc::backend_mismatch),
139+
"Backends mismatch");
144140
}
145141
int32_t IsImmCmdList;
146142
pi_native_handle Handle = Obj.getNative(IsImmCmdList);
@@ -160,10 +156,9 @@ auto get_native(const queue &Obj) -> backend_return_t<BackendName, queue> {
160156
template <backend BackendName, bundle_state State>
161157
auto get_native(const kernel_bundle<State> &Obj)
162158
-> backend_return_t<BackendName, kernel_bundle<State>> {
163-
// TODO use SYCL 2020 exception when implemented
164159
if (Obj.get_backend() != BackendName) {
165-
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
166-
PI_ERROR_INVALID_OPERATION);
160+
throw sycl::exception(make_error_code(errc::backend_mismatch),
161+
"Backends mismatch");
167162
}
168163
return Obj.template getNative<BackendName>();
169164
}
@@ -179,10 +174,9 @@ auto get_native(const buffer<DataT, Dimensions, AllocatorT> &Obj)
179174
template <>
180175
inline backend_return_t<backend::opencl, event>
181176
get_native<backend::opencl, event>(const event &Obj) {
182-
// TODO use SYCL 2020 exception when implemented
183177
if (Obj.get_backend() != backend::opencl) {
184-
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
185-
PI_ERROR_INVALID_OPERATION);
178+
throw sycl::exception(make_error_code(errc::backend_mismatch),
179+
"Backends mismatch");
186180
}
187181
backend_return_t<backend::opencl, event> ReturnValue;
188182
for (auto const &element : Obj.getNativeVector()) {
@@ -199,10 +193,9 @@ get_native<backend::opencl, event>(const event &Obj) {
199193
template <>
200194
inline backend_return_t<backend::ext_oneapi_cuda, device>
201195
get_native<backend::ext_oneapi_cuda, device>(const device &Obj) {
202-
// TODO use SYCL 2020 exception when implemented
203196
if (Obj.get_backend() != backend::ext_oneapi_cuda) {
204-
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
205-
PI_ERROR_INVALID_OPERATION);
197+
throw sycl::exception(make_error_code(errc::backend_mismatch),
198+
"Backends mismatch");
206199
}
207200
// CUDA uses a 32-bit int instead of an opaque pointer like other backends,
208201
// so we need a specialization with static_cast instead of reinterpret_cast.

sycl/include/sycl/group.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@
1111
#include <CL/__spirv/spirv_ops.hpp>
1212
#include <CL/__spirv/spirv_types.hpp>
1313
#include <CL/__spirv/spirv_vars.hpp>
14-
#include <stdexcept>
1514
#include <sycl/detail/common.hpp>
1615
#include <sycl/detail/generic_type_traits.hpp>
1716
#include <sycl/detail/helpers.hpp>
1817
#include <sycl/detail/spirv.hpp>
1918
#include <sycl/device_event.hpp>
19+
#include <sycl/exception.hpp>
2020
#include <sycl/h_item.hpp>
2121
#include <sycl/id.hpp>
2222
#include <sycl/memory_enums.hpp>
2323
#include <sycl/pointers.hpp>
2424
#include <sycl/range.hpp>
2525
#include <type_traits>
2626

27+
#include <stdexcept>
28+
2729
namespace sycl {
2830
__SYCL_INLINE_VER_NAMESPACE(_V1) {
2931
namespace detail {
@@ -127,8 +129,8 @@ template <int Dimensions = 1> class __SYCL_TYPE(group) group {
127129
#ifdef __SYCL_DEVICE_ONLY__
128130
return __spirv::initLocalInvocationId<Dimensions, id<Dimensions>>();
129131
#else
130-
throw runtime_error("get_local_id() is not implemented on host",
131-
PI_ERROR_INVALID_DEVICE);
132+
throw sycl::exception(make_error_code(errc::feature_not_supported),
133+
"get_local_id() is not implemented on host");
132134
#endif
133135
}
134136

0 commit comments

Comments
 (0)