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

// reinterpret() with no arguments. Can be specialized with one or two
// template arguments. four possible combinations two template specializers:
// R is same size as T. RD is same as dimensions.
// RD is one. To avoid ambiguity, R size is different or previous dimension is
// not same.

// single template specializers
// R is same size as T. RD is assumed to be same as previous.
// R is not same as T previous dimensions were 1.

template <typename ReinterpretT, int ReinterpretDim>
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>
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
return buffer<ReinterpretT, ReinterpretDim, AllocatorT>(
impl, range<1>{sz / sizeof(ReinterpretT)}, OffsetInBytes, IsSubBuffer);
}

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

template <typename ReinterpretT>
typename std::enable_if<(sizeof(ReinterpretT) != sizeof(T)) &&
(dimensions == 1),
buffer<ReinterpretT, 1, AllocatorT>>::type
reinterpret() const {
long sz = get_size(); // TODO: switch to byte_size() once implemented
return buffer<ReinterpretT, dimensions, AllocatorT>(
impl, range<1>{sz / sizeof(ReinterpretT)}, OffsetInBytes, IsSubBuffer);
}

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