diff --git a/sycl/include/CL/sycl/buffer.hpp b/sycl/include/CL/sycl/buffer.hpp index c011e1f16130a..43ce038c34aa3 100755 --- a/sycl/include/CL/sycl/buffer.hpp +++ b/sycl/include/CL/sycl/buffer.hpp @@ -351,6 +351,32 @@ class buffer { impl, reinterpretRange, OffsetInBytes, IsSubBuffer); } + template + typename std::enable_if< + (sizeof(ReinterpretT) == sizeof(T)) && (dimensions == ReinterpretDim), + buffer>::type + reinterpret() const { + return buffer( + impl, get_range(), OffsetInBytes, IsSubBuffer); + } + + template + typename std::enable_if< + (ReinterpretDim == 1) && ((dimensions != ReinterpretDim) || + (sizeof(ReinterpretT) != sizeof(T))), + buffer>::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( + impl, range<1>{sz / sizeof(ReinterpretT)}, OffsetInBytes, IsSubBuffer); + } + template bool has_property() const { return impl->template has_property(); }