From 227614ca013b26a34d8fc2e9b96eac9f9b2502ae Mon Sep 17 00:00:00 2001 From: Alexey Sachkov Date: Thu, 20 Oct 2022 19:21:47 +0200 Subject: [PATCH] [SYCL] Adjust accessor::value_type in accordance with the spec (#7096) `value_type` should be defined as `const DataT` for read-only accessors. This also makes `accessor::iterator` of a read-only accessor non-writeable as it should be in accordance with the spec. --- sycl/include/sycl/accessor.hpp | 10 +++- .../accessor/iterator-member-types.cpp | 57 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 sycl/test/basic_tests/accessor/iterator-member-types.cpp diff --git a/sycl/include/sycl/accessor.hpp b/sycl/include/sycl/accessor.hpp index 396c3000fd613..d06c54981c502 100644 --- a/sycl/include/sycl/accessor.hpp +++ b/sycl/include/sycl/accessor.hpp @@ -1205,13 +1205,17 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor : friend class sycl::ext::intel::esimd::detail::AccessorPrivateProxy; public: - using value_type = DataT; + // 4.7.6.9.1. Interface for buffer command accessors + // value_type is defined as const DataT for read_only accessors, DataT + // otherwise + using value_type = typename std::conditional::type; using reference = DataT &; using const_reference = const DataT &; - using iterator = typename detail::accessor_iterator; + using iterator = typename detail::accessor_iterator; using const_iterator = - typename detail::accessor_iterator; + typename detail::accessor_iterator; using difference_type = typename std::iterator_traits::difference_type; diff --git a/sycl/test/basic_tests/accessor/iterator-member-types.cpp b/sycl/test/basic_tests/accessor/iterator-member-types.cpp new file mode 100644 index 0000000000000..d607479c4a074 --- /dev/null +++ b/sycl/test/basic_tests/accessor/iterator-member-types.cpp @@ -0,0 +1,57 @@ +// RUN: %clangxx -fsycl -c %s +// +// Purpose of this test is to check that [accessor|host_accessor]::iterator and +// ::const_iterator are aliased to the correct type. +// FIXME: extend this test to also check ::reverse_iterator and +// ::const_reverse_iterator +#include + +#include + +template +void check_accessor() { + using AccessorT = + typename sycl::accessor; + static_assert(std::is_same_v, + typename AccessorT::iterator>); + + static_assert( + std::is_same_v, + typename AccessorT::const_iterator>); +} + +template +void check_host_accessor() { + using AccessorT = typename sycl::host_accessor; + static_assert(std::is_same_v, + typename AccessorT::iterator>); + + static_assert( + std::is_same_v, + typename AccessorT::const_iterator>); +} + +struct user_defined_t { + char c; + float f; + double d; + sycl::vec v3; +}; + +int main() { + + check_accessor(); + check_accessor(); + check_accessor(); + + check_host_accessor(); + check_host_accessor(); + check_host_accessor(); + + return 0; +}