Skip to content

Commit a5de188

Browse files
[SYCL][local_accessor] std::abort instead of throwing from noexcept (#17146)
1 parent 1c2587d commit a5de188

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ class accessor;
229229

230230
namespace detail {
231231

232+
template <typename... Ts>
233+
#ifndef __SYCL_DEVICE_ONLY__
234+
[[noreturn]]
235+
#endif
236+
void cannot_be_called_on_host([[maybe_unused]] const char *API,
237+
Ts &&.../* ignore */) {
238+
#ifndef __SYCL_DEVICE_ONLY__
239+
std::fprintf(stderr, "%s cannot be called on host!\n", API);
240+
std::abort();
241+
#endif
242+
}
243+
232244
// A helper structure which is shared between buffer accessor and accessor_impl
233245
// TODO: Unify with AccessorImplDevice?
234246
struct AccHostDataT {
@@ -2564,22 +2576,20 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor
25642576
__SYCL2020_DEPRECATED(
25652577
"local_accessor::get_pointer() is deprecated, please use get_multi_ptr()")
25662578
local_ptr<DataT> get_pointer() const noexcept {
2567-
#ifndef __SYCL_DEVICE_ONLY__
2568-
throw sycl::exception(
2569-
make_error_code(errc::invalid),
2570-
"get_pointer must not be called on the host for a local accessor");
2571-
#endif
2579+
#if __SYCL_DEVICE_ONLY__
25722580
return local_ptr<DataT>(local_acc::getQualifiedPtr());
2581+
#else
2582+
detail::cannot_be_called_on_host("local_accessor::get_pointer");
2583+
#endif
25732584
}
25742585

25752586
template <access::decorated IsDecorated>
25762587
accessor_ptr<IsDecorated> get_multi_ptr() const noexcept {
2577-
#ifndef __SYCL_DEVICE_ONLY__
2578-
throw sycl::exception(
2579-
make_error_code(errc::invalid),
2580-
"get_multi_ptr must not be called on the host for a local accessor");
2581-
#endif
2588+
#if __SYCL_DEVICE_ONLY__
25822589
return accessor_ptr<IsDecorated>(local_acc::getQualifiedPtr());
2590+
#else
2591+
detail::cannot_be_called_on_host("local_accessor::get_multi_ptr");
2592+
#endif
25832593
}
25842594

25852595
template <typename Property> bool has_property() const noexcept {

0 commit comments

Comments
 (0)