Skip to content

Commit 436f4c9

Browse files
committed
Improve DX around buffer::get_access
- Throw static assertion if trying to use legacy master-access overload. - Improve exception messages for when trying to access wrong buffer type from within host/device tasks.
1 parent 7a0b572 commit 436f4c9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

include/buffer.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class buffer {
6060

6161
template <cl::sycl::access::mode Mode, cl::sycl::access::target Target, typename Functor>
6262
accessor<DataT, Dims, Mode, Target> get_access(handler& cgh, Functor rmfn) const {
63+
static_assert(!std::is_same_v<Functor, cl::sycl::range<Dims>>, "The buffer::get_access overload for master-access tasks (now called 'host tasks') has "
64+
"been removed with Celerity 0.2.0. Please provide a range mapper instead.");
65+
6366
using rmfn_traits = allscale::utils::lambda_traits<Functor>;
6467
static_assert(rmfn_traits::result_type::dims == Dims, "The returned subrange doesn't match buffer dimensions.");
6568

@@ -79,7 +82,7 @@ class buffer {
7982
// This also means that we have to clamp the subrange ourselves here, which is not ideal from an encapsulation standpoint.
8083
if constexpr(Target == cl::sycl::access::target::host_buffer) {
8184
if(detail::get_handler_execution_target(cgh) != detail::execution_target::HOST) {
82-
throw std::runtime_error("range-mapped get_access to host buffers is only allowed in host tasks");
85+
throw std::runtime_error("Calling buffer::get_access with sycl::access::target::host_buffer is only allowed in host tasks.");
8386
}
8487
auto& live_cgh = dynamic_cast<detail::live_pass_host_handler&>(cgh);
8588
const auto sr = detail::clamp_subrange_to_buffer_size(live_cgh.apply_range_mapper<Dims>(rmfn, get_range()), get_range());
@@ -88,7 +91,9 @@ class buffer {
8891
return detail::make_host_accessor<DataT, Dims, Mode>(sr, access_info.buffer, access_info.offset, range);
8992
} else {
9093
if(detail::get_handler_execution_target(cgh) != detail::execution_target::DEVICE) {
91-
throw std::runtime_error("range-mapped get_access to device buffers is only allowed in compute tasks");
94+
throw std::runtime_error(
95+
"Calling buffer::get_access on device buffers is only allowed in compute tasks. "
96+
"If you want to access this buffer from within a host task, please specialize the call using sycl::access::target::host_buffer.");
9297
}
9398
auto& live_cgh = dynamic_cast<detail::live_pass_device_handler&>(cgh);
9499
const auto sr = detail::clamp_subrange_to_buffer_size(live_cgh.apply_range_mapper<Dims>(rmfn, get_range()), get_range());

0 commit comments

Comments
 (0)