From 7bd48a599fb0f8619f15ad8fbc56a0e5effbc7a6 Mon Sep 17 00:00:00 2001 From: Chris Perkins Date: Tue, 9 Mar 2021 13:29:16 -0800 Subject: [PATCH 1/2] SYCL 2020 adds a new override of buffer::reinterpret() that takes zero arguments. Four specializations to fulfill spec. Signed-off-by: Chris Perkins --- sycl/include/CL/sycl/buffer.hpp | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/sycl/include/CL/sycl/buffer.hpp b/sycl/include/CL/sycl/buffer.hpp index c011e1f16130a..65cd8b915e546 100755 --- a/sycl/include/CL/sycl/buffer.hpp +++ b/sycl/include/CL/sycl/buffer.hpp @@ -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 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 + return buffer( + impl, range<1>{sz / sizeof(ReinterpretT)}, OffsetInBytes, IsSubBuffer); + } + + template + typename std::enable_if>::type + reinterpret() const { + return buffer( + impl, get_range(), OffsetInBytes, IsSubBuffer); + } + + template + typename std::enable_if<(sizeof(ReinterpretT) != sizeof(T)) && + (dimensions == 1), + buffer>::type + reinterpret() const { + long sz = get_size(); // TODO: switch to byte_size() once implemented + return buffer( + impl, range<1>{sz / sizeof(ReinterpretT)}, OffsetInBytes, IsSubBuffer); + } + template bool has_property() const { return impl->template has_property(); } From 831f9a0bbf051555ea735c430d91891bea486586 Mon Sep 17 00:00:00 2001 From: Chris Perkins Date: Fri, 12 Mar 2021 10:35:10 -0800 Subject: [PATCH 2/2] reviewer feedback Signed-off-by: Chris Perkins --- sycl/include/CL/sycl/buffer.hpp | 38 +++++++-------------------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/sycl/include/CL/sycl/buffer.hpp b/sycl/include/CL/sycl/buffer.hpp index 65cd8b915e546..43ce038c34aa3 100755 --- a/sycl/include/CL/sycl/buffer.hpp +++ b/sycl/include/CL/sycl/buffer.hpp @@ -351,17 +351,7 @@ 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 + template typename std::enable_if< (sizeof(ReinterpretT) == sizeof(T)) && (dimensions == ReinterpretDim), buffer>::type @@ -370,32 +360,20 @@ class buffer { impl, get_range(), OffsetInBytes, IsSubBuffer); } - template + 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 - return buffer( - impl, range<1>{sz / sizeof(ReinterpretT)}, OffsetInBytes, IsSubBuffer); - } - - template - typename std::enable_if>::type - reinterpret() const { - return buffer( - impl, get_range(), OffsetInBytes, IsSubBuffer); - } + 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); - template - typename std::enable_if<(sizeof(ReinterpretT) != sizeof(T)) && - (dimensions == 1), - buffer>::type - reinterpret() const { - long sz = get_size(); // TODO: switch to byte_size() once implemented - return buffer( + return buffer( impl, range<1>{sz / sizeof(ReinterpretT)}, OffsetInBytes, IsSubBuffer); }