Skip to content

Commit ddb00f5

Browse files
committed
[SYCL] Add SYCL2020 buffer and vec function byte_size()
1 parent ea4b8a9 commit ddb00f5

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

sycl/include/CL/sycl/buffer.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ class buffer {
263263
size_t get_count() const { return size(); }
264264
size_t size() const noexcept { return Range.size(); }
265265

266-
size_t get_size() const { return size() * sizeof(T); }
266+
__SYCL2020_DEPRECATED(
267+
"get_size() is deprecated, please use byte_size() instead")
268+
size_t get_size() const { return byte_size(); }
269+
size_t byte_size() const noexcept { return size() * sizeof(T); }
267270

268271
AllocatorT get_allocator() const {
269272
return impl->template get_allocator<AllocatorT>();
@@ -343,7 +346,7 @@ class buffer {
343346
template <typename ReinterpretT, int ReinterpretDim>
344347
buffer<ReinterpretT, ReinterpretDim, AllocatorT>
345348
reinterpret(range<ReinterpretDim> reinterpretRange) const {
346-
if (sizeof(ReinterpretT) * reinterpretRange.size() != get_size())
349+
if (sizeof(ReinterpretT) * reinterpretRange.size() != byte_size())
347350
throw cl::sycl::invalid_object_error(
348351
"Total size in bytes represented by the type and range of the "
349352
"reinterpreted SYCL buffer does not equal the total size in bytes "
@@ -369,7 +372,7 @@ class buffer {
369372
(sizeof(ReinterpretT) != sizeof(T))),
370373
buffer<ReinterpretT, ReinterpretDim, AllocatorT>>::type
371374
reinterpret() const {
372-
long sz = get_size(); // TODO: switch to byte_size() once implemented
375+
long sz = byte_size();
373376
if (sz % sizeof(ReinterpretT) != 0)
374377
throw cl::sycl::invalid_object_error(
375378
"Total byte size of buffer is not evenly divisible by the size of "

sycl/include/CL/sycl/types.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,10 @@ template <typename Type, int NumElements> class vec {
805805
__SYCL2020_DEPRECATED("get_count() is deprecated, please use size() instead")
806806
static constexpr size_t get_count() { return size(); }
807807
static constexpr size_t size() noexcept { return NumElements; }
808-
static constexpr size_t get_size() { return sizeof(m_Data); }
808+
__SYCL2020_DEPRECATED(
809+
"get_size() is deprecated, please use byte_size() instead")
810+
static constexpr size_t get_size() { return byte_size(); }
811+
static constexpr size_t byte_size() { return sizeof(m_Data); }
809812

810813
template <typename convertT,
811814
rounding_mode roundingMode = rounding_mode::automatic>
@@ -1400,7 +1403,10 @@ class SwizzleOp {
14001403
__SYCL2020_DEPRECATED("get_count() is deprecated, please use size() instead")
14011404
size_t get_count() const { return size(); }
14021405
size_t size() const noexcept { return getNumElements(); }
1403-
template <int Num = getNumElements()> size_t get_size() const {
1406+
__SYCL2020_DEPRECATED(
1407+
"get_size() is deprecated, please use byte_size() instead")
1408+
size_t get_size() const { return byte_size(); }
1409+
template <int Num = getNumElements()> size_t byte_size() const noexcept {
14041410
return sizeof(DataT) * (Num == 3 ? 4 : Num);
14051411
}
14061412

0 commit comments

Comments
 (0)