Skip to content

Commit 7ed4f58

Browse files
authored
[SYCL] Support accessors to array types (#3096)
The patch does not break functionality guaranteed by SYCL 1.2.1. The fix also is in accordance with SYCL 2020, which replaces 'operator DataT()' with 'operator reference() const' and allows using accessors to trivially_copyable arrays such as int[N]. Signed-off-by: Vyacheslav N Klochkov <[email protected]>
1 parent f6ac45f commit 7ed4f58

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

sycl/include/CL/sycl/accessor.hpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,27 +1512,28 @@ class accessor :
15121512
return detail::convertToArrayOfN<Dimensions, 0>(getOffset());
15131513
}
15141514

1515-
template <int Dims = Dimensions,
1516-
typename = detail::enable_if_t<Dims == 0 && IsAccessAnyWrite>>
1515+
template <int Dims = Dimensions, typename RefT = RefType,
1516+
typename = detail::enable_if_t<Dims == 0 && IsAccessAnyWrite &&
1517+
!std::is_const<RefT>::value>>
15171518
operator RefType() const {
15181519
const size_t LinearIndex = getLinearIndex(id<AdjustedDim>());
15191520
return *(getQualifiedPtr() + LinearIndex);
15201521
}
15211522

1523+
template <int Dims = Dimensions,
1524+
typename = detail::enable_if_t<Dims == 0 && IsAccessReadOnly>>
1525+
operator ConstRefType() const {
1526+
const size_t LinearIndex = getLinearIndex(id<AdjustedDim>());
1527+
return *(getQualifiedPtr() + LinearIndex);
1528+
}
1529+
15221530
template <int Dims = Dimensions,
15231531
typename = detail::enable_if_t<(Dims > 0) && IsAccessAnyWrite>>
15241532
RefType operator[](id<Dimensions> Index) const {
15251533
const size_t LinearIndex = getLinearIndex(Index);
15261534
return getQualifiedPtr()[LinearIndex];
15271535
}
15281536

1529-
template <int Dims = Dimensions,
1530-
typename = detail::enable_if_t<Dims == 0 && IsAccessReadOnly>>
1531-
operator DataT() const {
1532-
const size_t LinearIndex = getLinearIndex(id<AdjustedDim>());
1533-
return *(getQualifiedPtr() + LinearIndex);
1534-
}
1535-
15361537
template <int Dims = Dimensions>
15371538
typename detail::enable_if_t<(Dims > 0) && IsAccessReadOnly, ConstRefType>
15381539
operator[](id<Dimensions> Index) const {

0 commit comments

Comments
 (0)