Skip to content

Commit 5b9fd3c

Browse files
authored
[SYCL] Implement local_accessor begin/end (#6692)
SYCL2020 introduces various accessor begin/end member functions that allow user to iterate through the underlying buffer. E2E tests: intel/llvm-test-suite#1225
1 parent 80498d1 commit 5b9fd3c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,6 +2529,12 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor
25292529
// Use base classes constructors
25302530
using local_acc::local_acc;
25312531

2532+
using value_type = DataT;
2533+
using iterator = value_type *;
2534+
using const_iterator = const value_type *;
2535+
using reverse_iterator = std::reverse_iterator<iterator>;
2536+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
2537+
25322538
#ifdef __SYCL_DEVICE_ONLY__
25332539

25342540
// __init needs to be defined within the class not through inheritance.
@@ -2550,6 +2556,24 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(local_accessor) local_accessor
25502556
#endif
25512557

25522558
public:
2559+
iterator begin() const noexcept {
2560+
return &this->operator[](id<Dimensions>());
2561+
}
2562+
iterator end() const noexcept { return begin() + this->size(); }
2563+
2564+
const_iterator cbegin() const noexcept { return const_iterator(begin()); }
2565+
const_iterator cend() const noexcept { return const_iterator(end()); }
2566+
2567+
reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); }
2568+
reverse_iterator rend() const noexcept { return reverse_iterator(begin()); }
2569+
2570+
const_reverse_iterator crbegin() const noexcept {
2571+
return const_reverse_iterator(end());
2572+
}
2573+
const_reverse_iterator crend() const noexcept {
2574+
return const_reverse_iterator(begin());
2575+
}
2576+
25532577
template <typename Property> bool has_property() const noexcept {
25542578
#ifndef __SYCL_DEVICE_ONLY__
25552579
return this->getPropList().template has_property<Property>();

0 commit comments

Comments
 (0)