Skip to content

Commit 282d1de

Browse files
authored
[SYCL] Add SYCL 2020 buffer and vec function byte_size() (intel#4141)
1 parent a6447ca commit 282d1de

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-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: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,10 @@ template <typename Type, int NumElements> class vec {
810810
__SYCL2020_DEPRECATED("get_count() is deprecated, please use size() instead")
811811
static constexpr size_t get_count() { return size(); }
812812
static constexpr size_t size() noexcept { return NumElements; }
813-
static constexpr size_t get_size() { return sizeof(m_Data); }
813+
__SYCL2020_DEPRECATED(
814+
"get_size() is deprecated, please use byte_size() instead")
815+
static constexpr size_t get_size() { return byte_size(); }
816+
static constexpr size_t byte_size() { return sizeof(m_Data); }
814817

815818
template <typename convertT,
816819
rounding_mode roundingMode = rounding_mode::automatic>
@@ -1408,7 +1411,15 @@ class SwizzleOp {
14081411
__SYCL2020_DEPRECATED("get_count() is deprecated, please use size() instead")
14091412
size_t get_count() const { return size(); }
14101413
size_t size() const noexcept { return getNumElements(); }
1411-
template <int Num = getNumElements()> size_t get_size() const {
1414+
1415+
template <int Num = getNumElements()>
1416+
__SYCL2020_DEPRECATED(
1417+
"get_size() is deprecated, please use byte_size() instead")
1418+
size_t get_size() const {
1419+
return byte_size<Num>();
1420+
}
1421+
1422+
template <int Num = getNumElements()> size_t byte_size() const noexcept {
14121423
return sizeof(DataT) * (Num == 3 ? 4 : Num);
14131424
}
14141425

sycl/test/warnings/sycl_2020_deprecations.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ int main() {
6969
// expected-warning@+1{{'get_count' is deprecated: get_count() is deprecated, please use size() instead}}
7070
size_t BufferGetCount = Buffer.get_count();
7171
size_t BufferSize = Buffer.size();
72+
// expected-warning@+1 {{'get_size' is deprecated: get_size() is deprecated, please use byte_size() instead}}
73+
size_t BufferGetSize = Buffer.get_size();
74+
75+
sycl::vec<int, 2> Vec(1, 2);
76+
// expected-warning@+1{{'get_count' is deprecated: get_count() is deprecated, please use size() instead}}
77+
size_t VecGetCount = Vec.get_count();
78+
// expected-warning@+1 {{'get_size' is deprecated: get_size() is deprecated, please use byte_size() instead}}
79+
size_t VecGetSize = Vec.get_size();
7280

7381
// expected-warning@+1 {{'runtime_error' is deprecated: use sycl::exception with sycl::errc::runtime instead.}}
7482
sycl::runtime_error re;

0 commit comments

Comments
 (0)