14 #include <type_traits>
19 template<
typename T,
typename SFINAE =
void>
20 inline constexpr
bool isView =
false;
23 template<
typename TView>
24 inline constexpr
bool isView<
34 template<
typename TView>
37 static_assert(isView<TView>);
41 using pointer = value_type*;
42 using const_pointer = value_type
const*;
43 using reference = value_type&;
44 using const_reference = value_type
const&;
61 static_assert(Dim::value == 0,
"operator* is only valid for Buffers and Views of dimension 0");
67 static_assert(Dim::value == 0,
"operator* is only valid for Buffers and Views of dimension 0");
73 static_assert(Dim::value == 0,
"operator-> is only valid for Buffers and Views of dimension 0");
79 static_assert(Dim::value == 0,
"operator-> is only valid for Buffers and Views of dimension 0");
85 static_assert(Dim::value == 1,
"operator[i] is only valid for Buffers and Views of dimension 1");
91 static_assert(Dim::value == 1,
"operator[i] is only valid for Buffers and Views of dimension 1");
96 template<
typename TIdx>
100 std::is_convertible_v<TIdx, Idx>,
101 "the index type must be convertible to the index of the Buffer or View");
103 auto ptr =
reinterpret_cast<std::uintptr_t
>(
data());
104 if constexpr(Dim::value > 0)
106 ptr +=
static_cast<std::uintptr_t
>(
107 (
getPitchesInBytes(*
static_cast<TView const*
>(
this)) * castVec<Idx>(index)).sum());
109 return reinterpret_cast<const_pointer
>(ptr);
113 template<
typename TIdx>
116 return *
const_cast<pointer
>(ptr_at(index));
119 template<
typename TIdx>
122 return *ptr_at(index);
125 template<
typename TIdx>
128 auto extent =
getExtents(*
static_cast<TView*
>(
this));
129 if(!(index < extent).
all())
131 std::stringstream msg;
132 msg <<
"index " << index <<
" is outside of the Buffer or View extent " << extent;
133 throw std::out_of_range(msg.str());
135 return *
const_cast<pointer
>(ptr_at(index));
138 template<
typename TIdx>
141 auto extent =
getExtents(*
static_cast<TView const*
>(
this));
142 if(!(index < extent).
all())
144 std::stringstream msg;
145 msg <<
"index " << index <<
" is outside of the Buffer or View extent " << extent;
146 throw std::out_of_range(msg.str());
148 return *ptr_at(index);
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto all(TWarp const &warp, std::int32_t predicate) -> std::int32_t
Evaluates predicate for all active threads of the warp and returns non-zero if and only if predicate ...
typename trait::IdxType< T >::type Idx
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getExtents(T const &object) -> Vec< Dim< T >, Idx< T >>
ALPAKA_FN_HOST auto getPitchesInBytes(TView const &view) -> Vec< Dim< TView >, Idx< TView >>
ALPAKA_FN_HOST auto getPtrNative(TView const &view) -> Elem< TView > const *
Gets the native pointer of the memory view.
std::remove_volatile_t< typename trait::ElemType< TView >::type > Elem
The element type trait alias template to remove the ::type.
typename trait::DimType< T >::type Dim
The dimension type trait alias template to remove the ::type.
ALPAKA_FN_HOST auto operator[](Idx i) const -> const_reference
ALPAKA_FN_HOST auto data() const -> const_pointer
ALPAKA_FN_HOST auto at(Vec< Dim, TIdx > index) -> reference
ALPAKA_FN_HOST auto operator[](Vec< Dim, TIdx > index) const -> const_reference
ALPAKA_FN_HOST auto operator*() -> reference
ALPAKA_FN_HOST auto data() -> pointer
ALPAKA_FN_HOST auto operator->() -> pointer
ALPAKA_FN_HOST auto operator[](Vec< Dim, TIdx > index) -> reference
ALPAKA_FN_HOST auto operator[](Idx i) -> reference
ALPAKA_FN_HOST auto operator->() const -> const_pointer
ALPAKA_FN_HOST auto operator*() const -> const_reference
ALPAKA_FN_HOST auto at(Vec< Dim, TIdx > index) const -> const_reference