Skip to content

[SYCL] Use SYCL 2020 exception in ext/oneapi/experimental/*.hpp #14483

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
43 changes: 21 additions & 22 deletions sycl/include/sycl/ext/oneapi/experimental/ballot_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
#pragma once

#include <sycl/aspects.hpp>
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_DEVICE
#include <sycl/detail/spirv.hpp>
#include <sycl/detail/type_traits.hpp> // for is_group, is_user_cons...
#include <sycl/exception.hpp> // for runtime_error
#include <sycl/exception.hpp>
#include <sycl/ext/oneapi/experimental/non_uniform_groups.hpp> // for GetMask
#include <sycl/ext/oneapi/sub_group_mask.hpp> // for sub_group_mask
#include <sycl/id.hpp> // for id
Expand Down Expand Up @@ -49,71 +48,71 @@ template <typename ParentGroup> class ballot_group {
#ifdef __SYCL_DEVICE_ONLY__
return (Predicate) ? 1 : 0;
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

id_type get_local_id() const {
#ifdef __SYCL_DEVICE_ONLY__
return sycl::detail::CallerPositionInMask(Mask);
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

range_type get_group_range() const {
#ifdef __SYCL_DEVICE_ONLY__
return 2;
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

range_type get_local_range() const {
#ifdef __SYCL_DEVICE_ONLY__
return Mask.count();
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

linear_id_type get_group_linear_id() const {
#ifdef __SYCL_DEVICE_ONLY__
return static_cast<linear_id_type>(get_group_id()[0]);
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

linear_id_type get_local_linear_id() const {
#ifdef __SYCL_DEVICE_ONLY__
return static_cast<linear_id_type>(get_local_id()[0]);
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

linear_id_type get_group_linear_range() const {
#ifdef __SYCL_DEVICE_ONLY__
return static_cast<linear_id_type>(get_group_range()[0]);
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

linear_id_type get_local_linear_range() const {
#ifdef __SYCL_DEVICE_ONLY__
return static_cast<linear_id_type>(get_local_range()[0]);
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

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

Expand Down Expand Up @@ -165,8 +164,8 @@ get_ballot_group(Group group, bool predicate) {
#endif
#else
(void)predicate;
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

Expand Down
6 changes: 3 additions & 3 deletions sycl/include/sycl/ext/oneapi/experimental/builtins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ namespace ext::oneapi::experimental {
//
// - OpenCL spec defines several additional features, like, for example, 'v'
// modifier which allows to print OpenCL vectors: note that these features are
// not available on host device and therefore their usage should be either
// guarded using __SYCL_DEVICE_ONLY__ preprocessor macro or avoided in favor
// of more portable solutions if needed
// not available on host and therefore their usage should be either guarded
// using __SYCL_DEVICE_ONLY__ preprocessor macro or avoided in favor of more
// portable solutions if needed
//
template <typename FormatT, typename... Args>
int printf(const FormatT *__format, Args... args) {
Expand Down
43 changes: 21 additions & 22 deletions sycl/include/sycl/ext/oneapi/experimental/fixed_size_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
#pragma once

#include <sycl/aspects.hpp>
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_DEVICE
#include <sycl/detail/spirv.hpp>
#include <sycl/detail/type_traits.hpp> // for is_fixed_size_group, is_group
#include <sycl/exception.hpp> // for runtime_error
#include <sycl/exception.hpp>
#include <sycl/ext/oneapi/experimental/non_uniform_groups.hpp>
#include <sycl/ext/oneapi/sub_group_mask.hpp> // for sub_group_mask
#include <sycl/id.hpp> // for id
Expand Down Expand Up @@ -50,80 +49,80 @@ template <size_t PartitionSize, typename ParentGroup> class fixed_size_group {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv_SubgroupLocalInvocationId() / PartitionSize;
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

id_type get_local_id() const {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv_SubgroupLocalInvocationId() % PartitionSize;
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

range_type get_group_range() const {
#ifdef __SYCL_DEVICE_ONLY__
return __spirv_SubgroupSize() / PartitionSize;
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

range_type get_local_range() const {
#ifdef __SYCL_DEVICE_ONLY__
return PartitionSize;
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

linear_id_type get_group_linear_id() const {
#ifdef __SYCL_DEVICE_ONLY__
return static_cast<linear_id_type>(get_group_id()[0]);
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

linear_id_type get_local_linear_id() const {
#ifdef __SYCL_DEVICE_ONLY__
return static_cast<linear_id_type>(get_local_id()[0]);
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

linear_id_type get_group_linear_range() const {
#ifdef __SYCL_DEVICE_ONLY__
return static_cast<linear_id_type>(get_group_range()[0]);
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

linear_id_type get_local_linear_range() const {
#ifdef __SYCL_DEVICE_ONLY__
return static_cast<linear_id_type>(get_local_range()[0]);
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

bool leader() const {
#ifdef __SYCL_DEVICE_ONLY__
return get_local_linear_id() == 0;
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

Expand Down Expand Up @@ -168,8 +167,8 @@ get_fixed_size_group(Group group) {
return fixed_size_group<PartitionSize, sycl::sub_group>();
#endif
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

Expand Down
43 changes: 21 additions & 22 deletions sycl/include/sycl/ext/oneapi/experimental/opportunistic_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
#pragma once

#include <sycl/aspects.hpp>
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_DEVICE
#include <sycl/detail/spirv.hpp>
#include <sycl/detail/type_traits.hpp> // for is_group, is_user_cons...
#include <sycl/exception.hpp> // for runtime_error
#include <sycl/exception.hpp>
#include <sycl/ext/oneapi/experimental/non_uniform_groups.hpp>
#include <sycl/ext/oneapi/free_function_queries.hpp> // for this_sub_group
#include <sycl/ext/oneapi/sub_group_mask.hpp> // for sub_group_mask
Expand Down Expand Up @@ -55,71 +54,71 @@ class opportunistic_group {
#ifdef __SYCL_DEVICE_ONLY__
return static_cast<id_type>(0);
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

id_type get_local_id() const {
#ifdef __SYCL_DEVICE_ONLY__
return sycl::detail::CallerPositionInMask(Mask);
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

range_type get_group_range() const {
#ifdef __SYCL_DEVICE_ONLY__
return 1;
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

range_type get_local_range() const {
#ifdef __SYCL_DEVICE_ONLY__
return Mask.count();
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

linear_id_type get_group_linear_id() const {
#ifdef __SYCL_DEVICE_ONLY__
return static_cast<linear_id_type>(get_group_id()[0]);
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

linear_id_type get_local_linear_id() const {
#ifdef __SYCL_DEVICE_ONLY__
return static_cast<linear_id_type>(get_local_id()[0]);
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

linear_id_type get_group_linear_range() const {
#ifdef __SYCL_DEVICE_ONLY__
return static_cast<linear_id_type>(get_group_range()[0]);
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

linear_id_type get_local_linear_range() const {
#ifdef __SYCL_DEVICE_ONLY__
return static_cast<linear_id_type>(get_local_range()[0]);
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

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

Expand Down Expand Up @@ -162,8 +161,8 @@ inline opportunistic_group get_opportunistic_group() {
return opportunistic_group(mask);
#endif
#else
throw runtime_error("Non-uniform groups are not supported on host device.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::runtime),
"Non-uniform groups are not supported on host.");
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions sycl/include/sycl/ext/oneapi/experimental/root_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ void group_barrier(ext::oneapi::experimental::root_group<dimensions> G,
#else
(void)G;
(void)FenceScope;
throw sycl::runtime_error("Barriers are not supported on host device",
PI_ERROR_INVALID_DEVICE);
throw sycl::exception(make_error_code(errc::runtime),
"Barriers are not supported on host");
#endif
}

Expand Down
Loading
Loading