Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f20318c
[SYCL] Implement accessor iterator
AlexeySachkov Sep 13, 2022
2af129d
Add more tests and fix operator+
AlexeySachkov Sep 19, 2022
a3c98fb
Merge remote-tracking branch 'origin/sycl' into private/asachkov/acce…
AlexeySachkov Sep 20, 2022
d684185
Mark begin/end methods as const
AlexeySachkov Sep 21, 2022
2dff81d
Generalize test code a bit
AlexeySachkov Sep 21, 2022
87e771f
Fixes and tests for offset + range accessors
AlexeySachkov Sep 21, 2022
36364a0
Remove LIT which was used for local experiments
AlexeySachkov Sep 22, 2022
ba45577
Completely refactor accessor::iterator
AlexeySachkov Sep 26, 2022
53d5799
Some fixes and a couple more tests
AlexeySachkov Sep 28, 2022
90004cd
Refactor tests to prepare for their generalization
AlexeySachkov Sep 28, 2022
7ff5db5
Do not store accessor memory range in iterator
AlexeySachkov Sep 28, 2022
d785db4
Remove uses of accessor::get_offset() from methods other than iterato…
AlexeySachkov Sep 28, 2022
7e5789b
Do not use accessor APIs in the iterator constructor
AlexeySachkov Sep 28, 2022
a4a1817
Do not store a reference to an accessor within iterator
AlexeySachkov Sep 28, 2022
47e6c46
Add cbegin/cend and some tests for those methods
AlexeySachkov Sep 28, 2022
ef83061
Merge remote-tracking branch 'origin/sycl' into private/asachkov/acce…
AlexeySachkov Oct 4, 2022
9ef84c2
Fix build after merge
AlexeySachkov Oct 4, 2022
91f0d30
Fix Wreorder warning coming from AccessorSubscript constructor
AlexeySachkov Oct 4, 2022
8e2db4e
Allow iterators to be decremented past begin and incremented past end
AlexeySachkov Oct 7, 2022
769ab13
Add tests for writing through an iterator
AlexeySachkov Oct 7, 2022
a6effbb
Revert back from using reserved identifiers
AlexeySachkov Oct 7, 2022
600916b
Fix clang-format
AlexeySachkov Oct 7, 2022
78215dc
Return some undescores from comments back
AlexeySachkov Oct 7, 2022
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
39 changes: 37 additions & 2 deletions sycl/include/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <CL/__spirv/spirv_types.hpp>
#include <sycl/atomic.hpp>
#include <sycl/buffer.hpp>
#include <sycl/detail/accessor_iterator.hpp>
#include <sycl/detail/cl.h>
#include <sycl/detail/common.hpp>
#include <sycl/detail/export.hpp>
Expand All @@ -30,6 +31,7 @@
#include <sycl/property_list_conversion.hpp>
#include <sycl/sampler.hpp>

#include <iterator>
#include <type_traits>

#include <utility>
Expand Down Expand Up @@ -334,7 +336,7 @@ class accessor_common {

public:
AccessorSubscript(AccType Accessor, id<Dims> IDs)
: MAccessor(Accessor), MIDs(IDs) {}
: MIDs(IDs), MAccessor(Accessor) {}

// Only accessor class is supposed to use this c'tor for the first
// operator[].
Expand Down Expand Up @@ -1192,7 +1194,12 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
using value_type = DataT;
using reference = DataT &;
using const_reference = const DataT &;
using difference_type = size_t;

using iterator = typename detail::accessor_iterator<DataT, Dimensions>;
using const_iterator =
typename detail::accessor_iterator<const DataT, Dimensions>;
using difference_type =
typename std::iterator_traits<iterator>::difference_type;

// The list of accessor constructors with their arguments
// -------+---------+-------+----+-----+--------------
Expand Down Expand Up @@ -2091,6 +2098,34 @@ class __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
bool operator==(const accessor &Rhs) const { return impl == Rhs.impl; }
bool operator!=(const accessor &Rhs) const { return !(*this == Rhs); }

iterator begin() const noexcept {
return iterator::getBegin(
get_pointer(),
detail::convertToArrayOfN<Dimensions, 1>(getMemoryRange()), get_range(),
get_offset());
}

iterator end() const noexcept {
return iterator::getEnd(
get_pointer(),
detail::convertToArrayOfN<Dimensions, 1>(getMemoryRange()), get_range(),
get_offset());
}

const_iterator cbegin() const noexcept {
return const_iterator::getBegin(
get_pointer(),
detail::convertToArrayOfN<Dimensions, 1>(getMemoryRange()), get_range(),
get_offset());
}

const_iterator cend() const noexcept {
return const_iterator::getEnd(
get_pointer(),
detail::convertToArrayOfN<Dimensions, 1>(getMemoryRange()), get_range(),
get_offset());
}

private:
#ifdef __SYCL_DEVICE_ONLY__
size_t getTotalOffset() const {
Expand Down
Loading