Skip to content

[SYCL] Specialize errc for backends. #4298

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
6 changes: 5 additions & 1 deletion sycl/include/CL/sycl/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ template <backend Backend, typename T> struct BackendReturn {
// TODO replace usage of interop with specializations.
using type = typename interop<Backend, T>::type;
};

// TODO each backend can have its own custom errc enumeration
// but the details for this are not fully specified yet
enum class backend_errc : unsigned int {};
} // namespace detail

template <backend Backend> class backend_traits {
Expand All @@ -49,7 +53,7 @@ template <backend Backend> class backend_traits {
template <class T>
using return_type = typename detail::BackendReturn<Backend, T>::type;

// TODO define errc once SYCL2020-style exceptions are supported.
using errc = detail::backend_errc;
};

template <backend Backend, typename SyclType>
Expand Down
3 changes: 3 additions & 0 deletions sycl/include/CL/sycl/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// 4.9.2 Exception Class Interface

#include <CL/sycl/backend_types.hpp>
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/export.hpp>
#include <CL/sycl/detail/pi.h>
Expand Down Expand Up @@ -185,6 +186,8 @@ enum class errc : unsigned int {
backend_mismatch = 13,
};

template <backend B> using errc_for = typename backend_traits<B>::errc;

/// Constructs an error code using e and sycl_category()
__SYCL_EXPORT std::error_code make_error_code(sycl::errc E) noexcept;

Expand Down
21 changes: 21 additions & 0 deletions sycl/test/basic_tests/exceptions-SYCL-2020.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ int main() {
static_assert(std::is_error_code_enum<sycl::errc>::value, "errc enum should identify as error code");
static_assert(!std::is_error_condition_enum<sycl::errc>::value, "errc enum should not identify as error condition");

// Test errc_for and backends. Should compile without complaint.
constexpr int EC = 1;
sycl::backend_traits<sycl::backend::opencl>::errc someOpenCLErrCode{EC};
sycl::errc_for<sycl::backend::opencl> anotherOpenCLErrCode{EC};
assert(someOpenCLErrCode == anotherOpenCLErrCode);
sycl::backend_traits<sycl::backend::level_zero>::errc someL0ErrCode{EC};
sycl::errc_for<sycl::backend::level_zero> anotherL0ErrCode{EC};
assert(someL0ErrCode == anotherL0ErrCode);
sycl::backend_traits<sycl::backend::host>::errc someHOSTErrCode{EC};
sycl::errc_for<sycl::backend::host> anotherHOSTErrCode{EC};
assert(someHOSTErrCode == anotherHOSTErrCode);
sycl::backend_traits<sycl::backend::cuda>::errc someCUDAErrCode{EC};
sycl::errc_for<sycl::backend::cuda> anotherCUDAErrCode{EC};
assert(someCUDAErrCode == anotherCUDAErrCode);
sycl::backend_traits<sycl::backend::esimd_cpu>::errc someESIMDErrCode{EC};
sycl::errc_for<sycl::backend::esimd_cpu> anotherESIMDErrCode{EC};
assert(someESIMDErrCode == anotherESIMDErrCode);
sycl::backend_traits<sycl::backend::rocm>::errc someROCMErrCode{EC};
sycl::errc_for<sycl::backend::rocm> anotherROCMErrCode{EC};
assert(someROCMErrCode == anotherROCMErrCode);

std::cout << "OK" << std::endl;
return 0;
}