Skip to content

[SYCL] zero argument version of buffer::reinterpret() for SYCL 2020. #3333

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
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
26 changes: 26 additions & 0 deletions sycl/include/CL/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,32 @@ class buffer {
impl, reinterpretRange, OffsetInBytes, IsSubBuffer);
}

template <typename ReinterpretT, int ReinterpretDim = dimensions>
typename std::enable_if<
(sizeof(ReinterpretT) == sizeof(T)) && (dimensions == ReinterpretDim),
buffer<ReinterpretT, ReinterpretDim, AllocatorT>>::type
reinterpret() const {
return buffer<ReinterpretT, ReinterpretDim, AllocatorT>(
impl, get_range(), OffsetInBytes, IsSubBuffer);
}

template <typename ReinterpretT, int ReinterpretDim = dimensions>
typename std::enable_if<
(ReinterpretDim == 1) && ((dimensions != ReinterpretDim) ||
(sizeof(ReinterpretT) != sizeof(T))),
buffer<ReinterpretT, ReinterpretDim, AllocatorT>>::type
reinterpret() const {
long sz = get_size(); // TODO: switch to byte_size() once implemented
if (sz % sizeof(ReinterpretT) != 0)
throw cl::sycl::invalid_object_error(
"Total byte size of buffer is not evenly divisible by the size of "
"the reinterpreted type",
PI_INVALID_VALUE);

return buffer<ReinterpretT, ReinterpretDim, AllocatorT>(
impl, range<1>{sz / sizeof(ReinterpretT)}, OffsetInBytes, IsSubBuffer);
}

template <typename propertyT> bool has_property() const {
return impl->template has_property<propertyT>();
}
Expand Down