Skip to content

[SYCL] Use sycl::exception instead of sycl::runtime_error #10217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sycl/include/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,9 @@ class image_accessor

sycl::vec<int, Dimensions> getRangeInternal() const {
// TODO: Implement for host.
throw runtime_error("image::getRangeInternal() is not implemented for host",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(
make_error_code(errc::feature_not_supported),
"image::getRangeInternal() is not implemented for host");
return sycl::vec<int, Dimensions>{1};
}

Expand Down
31 changes: 12 additions & 19 deletions sycl/include/sycl/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ auto get_native_buffer(const buffer<DataT, Dimensions, AllocatorT, void> &Obj)
// No check for backend mismatch because buffer can be allocated on different
// backends
if (BackendName == backend::ext_oneapi_level_zero)
throw sycl::runtime_error(
errc::feature_not_supported,
"Buffer interop is not supported by level zero yet",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(make_error_code(errc::feature_not_supported),
"Buffer interop is not supported by level zero yet");
return Obj.template getNative<BackendName>();
}
#endif
Expand All @@ -126,21 +124,19 @@ auto get_native_buffer(const buffer<DataT, Dimensions, AllocatorT, void> &Obj)
template <backend BackendName, class SyclObjectT>
auto get_native(const SyclObjectT &Obj)
-> backend_return_t<BackendName, SyclObjectT> {
// TODO use SYCL 2020 exception when implemented
if (Obj.get_backend() != BackendName) {
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(make_error_code(errc::backend_mismatch),
"Backends mismatch");
}
return reinterpret_cast<backend_return_t<BackendName, SyclObjectT>>(
Obj.getNative());
}

template <backend BackendName>
auto get_native(const queue &Obj) -> backend_return_t<BackendName, queue> {
// TODO use SYCL 2020 exception when implemented
if (Obj.get_backend() != BackendName) {
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(make_error_code(errc::backend_mismatch),
"Backends mismatch");
}
int32_t IsImmCmdList;
pi_native_handle Handle = Obj.getNative(IsImmCmdList);
Expand All @@ -160,10 +156,9 @@ auto get_native(const queue &Obj) -> backend_return_t<BackendName, queue> {
template <backend BackendName, bundle_state State>
auto get_native(const kernel_bundle<State> &Obj)
-> backend_return_t<BackendName, kernel_bundle<State>> {
// TODO use SYCL 2020 exception when implemented
if (Obj.get_backend() != BackendName) {
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(make_error_code(errc::backend_mismatch),
"Backends mismatch");
}
return Obj.template getNative<BackendName>();
}
Expand All @@ -179,10 +174,9 @@ auto get_native(const buffer<DataT, Dimensions, AllocatorT> &Obj)
template <>
inline backend_return_t<backend::opencl, event>
get_native<backend::opencl, event>(const event &Obj) {
// TODO use SYCL 2020 exception when implemented
if (Obj.get_backend() != backend::opencl) {
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(make_error_code(errc::backend_mismatch),
"Backends mismatch");
}
backend_return_t<backend::opencl, event> ReturnValue;
for (auto const &element : Obj.getNativeVector()) {
Expand All @@ -199,10 +193,9 @@ get_native<backend::opencl, event>(const event &Obj) {
template <>
inline backend_return_t<backend::ext_oneapi_cuda, device>
get_native<backend::ext_oneapi_cuda, device>(const device &Obj) {
// TODO use SYCL 2020 exception when implemented
if (Obj.get_backend() != backend::ext_oneapi_cuda) {
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(make_error_code(errc::backend_mismatch),
"Backends mismatch");
}
// CUDA uses a 32-bit int instead of an opaque pointer like other backends,
// so we need a specialization with static_cast instead of reinterpret_cast.
Expand Down
8 changes: 5 additions & 3 deletions sycl/include/sycl/group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@
#include <CL/__spirv/spirv_ops.hpp>
#include <CL/__spirv/spirv_types.hpp>
#include <CL/__spirv/spirv_vars.hpp>
#include <stdexcept>
#include <sycl/detail/common.hpp>
#include <sycl/detail/generic_type_traits.hpp>
#include <sycl/detail/helpers.hpp>
#include <sycl/detail/spirv.hpp>
#include <sycl/device_event.hpp>
#include <sycl/exception.hpp>
#include <sycl/h_item.hpp>
#include <sycl/id.hpp>
#include <sycl/memory_enums.hpp>
#include <sycl/pointers.hpp>
#include <sycl/range.hpp>
#include <type_traits>

#include <stdexcept>

namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {
namespace detail {
Expand Down Expand Up @@ -127,8 +129,8 @@ template <int Dimensions = 1> class __SYCL_TYPE(group) group {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv::initLocalInvocationId<Dimensions, id<Dimensions>>();
#else
throw runtime_error("get_local_id() is not implemented on host",
PI_ERROR_INVALID_DEVICE);
throw sycl::exception(make_error_code(errc::feature_not_supported),
"get_local_id() is not implemented on host");
#endif
}

Expand Down
Loading