Skip to content

Commit d785db4

Browse files
committed
Remove uses of accessor::get_offset() from methods other than iterator constructor
1 parent 7ff5db5 commit d785db4

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

sycl/include/sycl/detail/accessor_iterator.hpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,17 @@ class __accessor_iterator {
216216
// . X X X .
217217
// . . . . .
218218
//
219-
// _MStaticOffset stores a number of elements in _full_ rows (and in _full_
220-
// slices in case of 3-dimensional buffers) before the first accessible
221-
// element. For the example above, _MStaticOffset would be equal to 5, because
222-
// there is only one full row before the first accessible element. "Static" in
223-
// the name highlights that this is a constant element in an equation which
224-
// calculates an absoulte offset to an accessor's buffer, it doesn't depend
225-
// on the current state of the iterator.
219+
// _MStaticOffset stores a number of elements which precede the first
220+
// accessible element, calculated as if the buffer was linearized.
221+
// For the example above, _MStaticOffset would be equal to 6, because
222+
// there is one full row before the first accessible element and a one more on
223+
// the second line. "Static" in the name highlights that this is a constant
224+
// element in an equation which calculates an absoulte offset to an accessor's
225+
// buffer, it doesn't depend on the current state of the iterator.
226+
//
227+
// NOTE: _MStaticOffset is set to 0 in 1D case even if the accessor was
228+
// created with offset: it is done to further optimize 1D case by
229+
// incorporating that offset into _MLinearId right away.
226230
//
227231
// _MPerRowOffset stores a number of _inaccessible_ elements in each
228232
// _accessible_ row. For the example above it would be equal to 2 (leftmost
@@ -278,9 +282,6 @@ class __accessor_iterator {
278282
_AbsoluteId += _MPerRowOffset * (_Remaining / _MRowSize);
279283
_Remaining %= _MRowSize;
280284

281-
// And finally, there could be inaccessible elements on the current row
282-
_AbsoluteId += _MAccessorPtr->get_offset()[_Dimensions - 1];
283-
284285
return _AbsoluteId;
285286
}
286287

@@ -314,8 +315,11 @@ class __accessor_iterator {
314315
_AccessRange[_XIndex] * _AccessRange[_YIndex] - _MSliceSize;
315316
}
316317
if constexpr (_Dimensions > 1) {
318+
// Elements in fully inaccessible rows
317319
_MStaticOffset +=
318320
_AccessRange[_XIndex] * _MAccessorPtr->get_offset()[_YIndex];
321+
// Elements from the first accessible row
322+
_MStaticOffset += _MAccessorPtr->get_offset()[_XIndex];
319323
_MPerRowOffset = _AccessRange[_XIndex] - _MRowSize;
320324
}
321325
}

0 commit comments

Comments
 (0)