Skip to content

[SYCL] Add SYCL 2020 buffer and vec function byte_size() #4141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions sycl/include/CL/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<AllocatorT>();
Expand Down Expand Up @@ -343,7 +346,7 @@ class buffer {
template <typename ReinterpretT, int ReinterpretDim>
buffer<ReinterpretT, ReinterpretDim, AllocatorT>
reinterpret(range<ReinterpretDim> 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 "
Expand All @@ -369,7 +372,7 @@ class buffer {
(sizeof(ReinterpretT) != sizeof(T))),
buffer<ReinterpretT, ReinterpretDim, AllocatorT>>::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 "
Expand Down
15 changes: 13 additions & 2 deletions sycl/include/CL/sycl/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,10 @@ template <typename Type, int NumElements> 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 <typename convertT,
rounding_mode roundingMode = rounding_mode::automatic>
Expand Down Expand Up @@ -1400,7 +1403,15 @@ 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 <int Num = getNumElements()> size_t get_size() const {

template <int Num = getNumElements()>
__SYCL2020_DEPRECATED(
"get_size() is deprecated, please use byte_size() instead")
size_t get_size() const {
return byte_size<Num>();
}

template <int Num = getNumElements()> size_t byte_size() const noexcept {
return sizeof(DataT) * (Num == 3 ? 4 : Num);
}

Expand Down
8 changes: 8 additions & 0 deletions sycl/test/warnings/sycl_2020_deprecations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, 2> 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;
Expand Down