Skip to content

Commit c0c3c80

Browse files
[SYCL] Add zero argument version of buffer::reinterpret() for SYCL 2020 (#3333)
SYCL 2020 adds a new override of buffer::reinterpret() that takes zero arguments Signed-off-by: Chris Perkins <[email protected]>
1 parent 8a32b7d commit c0c3c80

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

sycl/include/CL/sycl/buffer.hpp

+26
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,32 @@ class buffer {
351351
impl, reinterpretRange, OffsetInBytes, IsSubBuffer);
352352
}
353353

354+
template <typename ReinterpretT, int ReinterpretDim = dimensions>
355+
typename std::enable_if<
356+
(sizeof(ReinterpretT) == sizeof(T)) && (dimensions == ReinterpretDim),
357+
buffer<ReinterpretT, ReinterpretDim, AllocatorT>>::type
358+
reinterpret() const {
359+
return buffer<ReinterpretT, ReinterpretDim, AllocatorT>(
360+
impl, get_range(), OffsetInBytes, IsSubBuffer);
361+
}
362+
363+
template <typename ReinterpretT, int ReinterpretDim = dimensions>
364+
typename std::enable_if<
365+
(ReinterpretDim == 1) && ((dimensions != ReinterpretDim) ||
366+
(sizeof(ReinterpretT) != sizeof(T))),
367+
buffer<ReinterpretT, ReinterpretDim, AllocatorT>>::type
368+
reinterpret() const {
369+
long sz = get_size(); // TODO: switch to byte_size() once implemented
370+
if (sz % sizeof(ReinterpretT) != 0)
371+
throw cl::sycl::invalid_object_error(
372+
"Total byte size of buffer is not evenly divisible by the size of "
373+
"the reinterpreted type",
374+
PI_INVALID_VALUE);
375+
376+
return buffer<ReinterpretT, ReinterpretDim, AllocatorT>(
377+
impl, range<1>{sz / sizeof(ReinterpretT)}, OffsetInBytes, IsSubBuffer);
378+
}
379+
354380
template <typename propertyT> bool has_property() const {
355381
return impl->template has_property<propertyT>();
356382
}

0 commit comments

Comments
 (0)