From ddb00f5f63c76d8298fe87231db6b8e40e879a17 Mon Sep 17 00:00:00 2001 From: Nawrin Sultana Date: Wed, 14 Jul 2021 14:50:31 -0700 Subject: [PATCH 1/5] [SYCL] Add SYCL2020 buffer and vec function byte_size() --- sycl/include/CL/sycl/buffer.hpp | 9 ++++++--- sycl/include/CL/sycl/types.hpp | 10 ++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/sycl/include/CL/sycl/buffer.hpp b/sycl/include/CL/sycl/buffer.hpp index 7cf5a0e2be62e..240c332c910b4 100755 --- a/sycl/include/CL/sycl/buffer.hpp +++ b/sycl/include/CL/sycl/buffer.hpp @@ -263,7 +263,10 @@ class buffer { size_t get_count() const { return size(); } size_t size() const noexcept { return Range.size(); } - size_t get_size() const { return size() * sizeof(T); } + __SYCL2020_DEPRECATED( + "get_size() is deprecated, please use byte_size() instead") + size_t get_size() const { return byte_size(); } + size_t byte_size() const noexcept { return size() * sizeof(T); } AllocatorT get_allocator() const { return impl->template get_allocator(); @@ -343,7 +346,7 @@ class buffer { template buffer reinterpret(range reinterpretRange) const { - if (sizeof(ReinterpretT) * reinterpretRange.size() != get_size()) + if (sizeof(ReinterpretT) * reinterpretRange.size() != byte_size()) throw cl::sycl::invalid_object_error( "Total size in bytes represented by the type and range of the " "reinterpreted SYCL buffer does not equal the total size in bytes " @@ -369,7 +372,7 @@ class buffer { (sizeof(ReinterpretT) != sizeof(T))), buffer>::type reinterpret() const { - long sz = get_size(); // TODO: switch to byte_size() once implemented + long sz = byte_size(); if (sz % sizeof(ReinterpretT) != 0) throw cl::sycl::invalid_object_error( "Total byte size of buffer is not evenly divisible by the size of " diff --git a/sycl/include/CL/sycl/types.hpp b/sycl/include/CL/sycl/types.hpp index 602b54a1bcca0..d8af99233d375 100644 --- a/sycl/include/CL/sycl/types.hpp +++ b/sycl/include/CL/sycl/types.hpp @@ -805,7 +805,10 @@ template class vec { __SYCL2020_DEPRECATED("get_count() is deprecated, please use size() instead") static constexpr size_t get_count() { return size(); } static constexpr size_t size() noexcept { return NumElements; } - static constexpr size_t get_size() { return sizeof(m_Data); } + __SYCL2020_DEPRECATED( + "get_size() is deprecated, please use byte_size() instead") + static constexpr size_t get_size() { return byte_size(); } + static constexpr size_t byte_size() { return sizeof(m_Data); } template @@ -1400,7 +1403,10 @@ class SwizzleOp { __SYCL2020_DEPRECATED("get_count() is deprecated, please use size() instead") size_t get_count() const { return size(); } size_t size() const noexcept { return getNumElements(); } - template size_t get_size() const { + __SYCL2020_DEPRECATED( + "get_size() is deprecated, please use byte_size() instead") + size_t get_size() const { return byte_size(); } + template size_t byte_size() const noexcept { return sizeof(DataT) * (Num == 3 ? 4 : Num); } From 94c95e76e56692ec82c866dd67afb922303d6b52 Mon Sep 17 00:00:00 2001 From: Nawrin Sultana Date: Wed, 4 Aug 2021 07:45:16 -0700 Subject: [PATCH 2/5] Add template to get_size --- sycl/include/CL/sycl/types.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sycl/include/CL/sycl/types.hpp b/sycl/include/CL/sycl/types.hpp index d8af99233d375..74de581de4ac5 100644 --- a/sycl/include/CL/sycl/types.hpp +++ b/sycl/include/CL/sycl/types.hpp @@ -1405,7 +1405,9 @@ class SwizzleOp { size_t size() const noexcept { return getNumElements(); } __SYCL2020_DEPRECATED( "get_size() is deprecated, please use byte_size() instead") - size_t get_size() const { return byte_size(); } + template size_t get_size() const { + return byte_size(); + } template size_t byte_size() const noexcept { return sizeof(DataT) * (Num == 3 ? 4 : Num); } From d19dc0e231e6d8c6955c5f000b3c3a965b02218c Mon Sep 17 00:00:00 2001 From: Nawrin Sultana Date: Wed, 4 Aug 2021 10:09:16 -0700 Subject: [PATCH 3/5] Fix test failures --- sycl/include/CL/sycl/types.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sycl/include/CL/sycl/types.hpp b/sycl/include/CL/sycl/types.hpp index 74de581de4ac5..8c7a679110881 100644 --- a/sycl/include/CL/sycl/types.hpp +++ b/sycl/include/CL/sycl/types.hpp @@ -1403,11 +1403,12 @@ class SwizzleOp { __SYCL2020_DEPRECATED("get_count() is deprecated, please use size() instead") size_t get_count() const { return size(); } size_t size() const noexcept { return getNumElements(); } + + template __SYCL2020_DEPRECATED( "get_size() is deprecated, please use byte_size() instead") - template size_t get_size() const { - return byte_size(); - } + size_t get_size() const { return byte_size(); } + template size_t byte_size() const noexcept { return sizeof(DataT) * (Num == 3 ? 4 : Num); } From 3790eefcd5c4cd4067f73326a7cc7c4d2da9e184 Mon Sep 17 00:00:00 2001 From: Nawrin Sultana Date: Wed, 4 Aug 2021 10:16:29 -0700 Subject: [PATCH 4/5] Fix clang format --- sycl/include/CL/sycl/types.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sycl/include/CL/sycl/types.hpp b/sycl/include/CL/sycl/types.hpp index 8c7a679110881..3387c3cc0407b 100644 --- a/sycl/include/CL/sycl/types.hpp +++ b/sycl/include/CL/sycl/types.hpp @@ -1407,7 +1407,9 @@ class SwizzleOp { template __SYCL2020_DEPRECATED( "get_size() is deprecated, please use byte_size() instead") - size_t get_size() const { return byte_size(); } + size_t get_size() const { + return byte_size(); + } template size_t byte_size() const noexcept { return sizeof(DataT) * (Num == 3 ? 4 : Num); From 679fe52c10f936660eccc9bba8054f6ae3cb48d1 Mon Sep 17 00:00:00 2001 From: Nawrin Sultana Date: Thu, 12 Aug 2021 16:23:22 -0700 Subject: [PATCH 5/5] Add check for deprecation messages --- sycl/test/warnings/sycl_2020_deprecations.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sycl/test/warnings/sycl_2020_deprecations.cpp b/sycl/test/warnings/sycl_2020_deprecations.cpp index 218f2ac5e0591..d99b34eff1880 100644 --- a/sycl/test/warnings/sycl_2020_deprecations.cpp +++ b/sycl/test/warnings/sycl_2020_deprecations.cpp @@ -69,6 +69,14 @@ int main() { // expected-warning@+1{{'get_count' is deprecated: get_count() is deprecated, please use size() instead}} size_t BufferGetCount = Buffer.get_count(); size_t BufferSize = Buffer.size(); + // expected-warning@+1 {{'get_size' is deprecated: get_size() is deprecated, please use byte_size() instead}} + size_t BufferGetSize = Buffer.get_size(); + + sycl::vec Vec(1, 2); + // expected-warning@+1{{'get_count' is deprecated: get_count() is deprecated, please use size() instead}} + size_t VecGetCount = Vec.get_count(); + // expected-warning@+1 {{'get_size' is deprecated: get_size() is deprecated, please use byte_size() instead}} + size_t VecGetSize = Vec.get_size(); // expected-warning@+1 {{'runtime_error' is deprecated: use sycl::exception with sycl::errc::runtime instead.}} sycl::runtime_error re;