Low-Level Abstraction of Memory Access
One.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 "../Core.hpp"
7 #include "Common.hpp"
8 
9 namespace llama::mapping
10 {
19  template<
20  typename TArrayExtents,
21  typename TRecordDim,
22  FieldAlignment TFieldAlignment = FieldAlignment::Align,
23  template<typename> typename PermuteFields = PermuteFieldsMinimizePadding>
24  struct One : MappingBase<TArrayExtents, TRecordDim>
25  {
26  private:
28  using size_type = typename Base::size_type;
29 
30  public:
31  inline static constexpr FieldAlignment fieldAlignment = TFieldAlignment;
32  using Permuter = PermuteFields<FlatRecordDim<TRecordDim>>;
33  static constexpr std::size_t blobCount = 1;
34 
35 #if defined(__NVCC__) && __CUDACC_VER_MAJOR__ >= 12
36  using Base::Base;
37 #else
38  constexpr One() = default;
39 
40  LLAMA_FN_HOST_ACC_INLINE constexpr explicit One(TArrayExtents extents, TRecordDim = {}) : Base(extents)
41  {
42  }
43 #endif
44 
46  {
47  return flatSizeOf<
48  typename Permuter::FlatRecordDim,
50  false>; // no tail padding
51  }
52 
53  template<std::size_t... RecordCoords>
55  typename Base::ArrayIndex,
57  {
58  constexpr std::size_t flatFieldIndex =
59 #if defined(__NVCC__) && __CUDACC_VER_MAJOR__ == 11 && __CUDACC_VER_MINOR__ <= 6
60  *& // mess with nvcc compiler state to workaround bug
61 #endif
62  Permuter::template permute<flatRecordCoord<TRecordDim, RecordCoord<RecordCoords...>>>;
63  constexpr auto offset = static_cast<size_type>(flatOffsetOf<
64  typename Permuter::FlatRecordDim,
65  flatFieldIndex,
67  return {size_type{0}, offset};
68  }
69  };
70 
74  template<typename ArrayExtents, typename RecordDim>
76 
81  template<typename ArrayExtents, typename RecordDim>
83 
87  template<typename ArrayExtents, typename RecordDim>
89 
93  template<
95  template<typename> typename PermuteFields = PermuteFieldsMinimizePadding>
96  struct BindOne
97  {
98  template<typename ArrayExtents, typename RecordDim>
100  };
101 
103  template<typename Mapping>
104  inline constexpr bool isOne = false;
105 
107  template<
108  typename ArrayExtents,
109  typename RecordDim,
111  template<typename>
112  typename PermuteFields>
113  inline constexpr bool isOne<One<ArrayExtents, RecordDim, FieldAlignment, PermuteFields>> = true;
114 } // namespace llama::mapping
#define LLAMA_EXPORT
Definition: macros.hpp:192
#define LLAMA_FN_HOST_ACC_INLINE
Definition: macros.hpp:96
PermuteFieldsIncreasingAlignment< FlatRecordDim > PermuteFieldsMinimizePadding
Sorts the record dimension fields by the alignment of its fields to minimize padding.
Definition: Common.hpp:241
constexpr bool isOne
Definition: One.hpp:104
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
constexpr std::size_t flatSizeOf
The size of a type list if its elements would be in a normal struct.
Definition: Core.hpp:618
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
constexpr auto blobNrAndOffset(typename Base::ArrayIndex, RecordCoord< RecordCoords... >={}) const -> NrAndOffset< size_type >
Definition: One.hpp:54
constexpr One()=default
static constexpr FieldAlignment fieldAlignment
Definition: One.hpp:31
constexpr One(TArrayExtents extents, TRecordDim={})
Definition: One.hpp:40
constexpr auto blobSize(size_type) const -> size_type
Definition: One.hpp:45
PermuteFields< FlatRecordDim< TRecordDim > > Permuter
Definition: One.hpp:32
static constexpr std::size_t blobCount
Definition: One.hpp:33