Low-Level Abstraction of Memory Access
AoS.hpp
Go to the documentation of this file.
1 // Copyright 2022 Alexander Matthes, Bernhard Manfred Gruber
2 // SPDX-License-Identifier: MPL-2.0
3 
4 #pragma once
5 
6 #include "Common.hpp"
7 
8 namespace llama::mapping
9 {
19  template<
20  typename TArrayExtents,
21  typename TRecordDim,
22  FieldAlignment TFieldAlignment = FieldAlignment::Align,
23  typename TLinearizeArrayIndexFunctor = LinearizeArrayIndexRight,
24  template<typename> typename PermuteFields = PermuteFieldsInOrder>
25  struct AoS : MappingBase<TArrayExtents, TRecordDim>
26  {
27  private:
29  using size_type = typename Base::size_type;
30 
31  public:
32  inline static constexpr FieldAlignment fieldAlignment = TFieldAlignment;
33  using LinearizeArrayIndexFunctor = TLinearizeArrayIndexFunctor;
34  using Permuter = PermuteFields<FlatRecordDim<TRecordDim>>;
35  inline static constexpr std::size_t blobCount = 1;
36 
37  using Base::Base;
38 
39  LLAMA_FN_HOST_ACC_INLINE constexpr auto blobSize(size_type) const -> size_type
40  {
42  * flatSizeOf<typename Permuter::FlatRecordDim, fieldAlignment == FieldAlignment::Align>;
43  }
44 
45  template<std::size_t... RecordCoords>
47  typename Base::ArrayIndex ai,
49  {
50  constexpr std::size_t flatFieldIndex =
51 #if defined(__NVCC__) && __CUDACC_VER_MAJOR__ == 11 && __CUDACC_VER_MINOR__ <= 6
52  *& // mess with nvcc compiler state to workaround bug
53 #endif
54  Permuter::template permute<flatRecordCoord<TRecordDim, RecordCoord<RecordCoords...>>>;
55  const auto offset
57  * static_cast<size_type>(
58  flatSizeOf<typename Permuter::FlatRecordDim, fieldAlignment == FieldAlignment::Align>)
59  + static_cast<size_type>(flatOffsetOf<
60  typename Permuter::FlatRecordDim,
61  flatFieldIndex,
63  return {size_type{0}, offset};
64  }
65  };
66 
67  // we can drop this when inherited ctors also inherit deduction guides
69  template<typename TArrayExtents, typename TRecordDim>
70  AoS(TArrayExtents, TRecordDim) -> AoS<TArrayExtents, TRecordDim>;
71 
75  template<typename ArrayExtents, typename RecordDim, typename LinearizeArrayIndexFunctor = LinearizeArrayIndexRight>
77 
81  template<typename ArrayExtents, typename RecordDim, typename LinearizeArrayIndexFunctor = LinearizeArrayIndexRight>
82  using MinAlignedAoS = AoS<
84  RecordDim,
86  LinearizeArrayIndexFunctor,
88 
92  template<typename ArrayExtents, typename RecordDim, typename LinearizeArrayIndexFunctor = LinearizeArrayIndexRight>
94 
98  template<
100  typename LinearizeArrayIndexFunctor = LinearizeArrayIndexRight>
101  struct BindAoS
102  {
103  template<typename ArrayExtents, typename RecordDim>
105  };
106 
108  template<typename Mapping>
109  inline constexpr bool isAoS = false;
110 
112  template<
113  typename ArrayExtents,
114  typename RecordDim,
116  typename LinearizeArrayIndexFunctor,
117  template<typename>
118  typename PermuteFields>
119  inline constexpr bool
120  isAoS<AoS<ArrayExtents, RecordDim, FieldAlignment, LinearizeArrayIndexFunctor, PermuteFields>>
121  = true;
122 } // namespace llama::mapping
#define LLAMA_EXPORT
Definition: macros.hpp:192
#define LLAMA_FN_HOST_ACC_INLINE
Definition: macros.hpp:96
constexpr bool isAoS
Definition: AoS.hpp:109
AoS(TArrayExtents, TRecordDim) -> AoS< TArrayExtents, TRecordDim >
typename internal::FlattenRecordDimImpl< RecordDim >::type FlatRecordDim
Returns a flat type list containing all leaf field types of the given record dimension.
Definition: Core.hpp:481
ArrayExtents(Args...) -> ArrayExtents< typename internal::IndexTypeFromArgs< std::size_t, Args... >::type,(Args{}, dyn)... >
constexpr std::size_t flatRecordCoord
Definition: Core.hpp:517
constexpr std::size_t flatOffsetOf
The byte offset of an element in a type list ifs elements would be in a normal struct.
Definition: Core.hpp:634
TLinearizeArrayIndexFunctor LinearizeArrayIndexFunctor
Definition: AoS.hpp:33
static constexpr FieldAlignment fieldAlignment
Definition: AoS.hpp:32
PermuteFields< FlatRecordDim< TRecordDim > > Permuter
Definition: AoS.hpp:34
constexpr auto blobSize(size_type) const -> size_type
Definition: AoS.hpp:39
static constexpr std::size_t blobCount
Definition: AoS.hpp:35
constexpr auto blobNrAndOffset(typename Base::ArrayIndex ai, RecordCoord< RecordCoords... >={}) const -> NrAndOffset< size_type >
Definition: AoS.hpp:46
typename ArrayExtents::value_type size_type
Definition: Common.hpp:25
typename ArrayExtents::Index ArrayIndex
Definition: Common.hpp:24
constexpr auto extents() const -> ArrayExtents
Definition: Common.hpp:35
Retains the order of the record dimension's fields.
Definition: Common.hpp:182