Skip to content

Commit

Permalink
Remove ArrayIndex as mandatory mapping member
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jul 26, 2023
1 parent 8ff563b commit 2c2987d
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 61 deletions.
4 changes: 2 additions & 2 deletions docs/pages/mappings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ The view requires each mapping to fulfill at least the following concept:
template <typename M>
concept Mapping = requires(M m) {
typename M::ArrayExtents;
typename M::ArrayIndex;
typename M::RecordDim;
{ m.extents() } -> std::same_as<typename M::ArrayExtents>;
{ +M::blobCount } -> std::same_as<std::size_t>;
requires isConstexpr<M::blobCount>;
{ m.blobSize(std::size_t{}) } -> std::same_as<typename M::ArrayExtents::value_type>;
};

That is, each mapping type needs to expose the types :cpp:`ArrayExtents`, :cpp:`ArrayIndex` and :cpp:`RecordDim`.
That is, each mapping type needs to expose the types :cpp:`ArrayExtents` and :cpp:`RecordDim`.
Each mapping also needs to provide a getter `extents()` to retrieve the runtime value of the :cpp:`ArrayExtents` held by the mapping,
and provide a :cpp:`static constexpr` member variable :cpp:`blobCount`.
Finally, the member function :cpp:`blobSize(i)` gives the size in bytes of the :cpp:`i`\ th block of memory needed for this mapping
Expand Down
3 changes: 1 addition & 2 deletions examples/bufferguard/bufferguard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ template<template<typename, typename> typename InnerMapping, typename TRecordDim
struct GuardMapping2D : llama::ArrayExtentsDynamic<std::size_t, 2>
{
using ArrayExtents = llama::ArrayExtentsDynamic<std::size_t, 2>;
using ArrayIndex = llama::ArrayIndex<std::size_t, 2>;
using RecordDim = TRecordDim;

constexpr GuardMapping2D() = default;
Expand Down Expand Up @@ -71,7 +70,7 @@ struct GuardMapping2D : llama::ArrayExtentsDynamic<std::size_t, 2>
}

template<std::size_t... RecordCoords>
constexpr auto blobNrAndOffset(ArrayIndex ai, llama::RecordCoord<RecordCoords...> rc = {}) const
constexpr auto blobNrAndOffset(ArrayExtents::Index ai, llama::RecordCoord<RecordCoords...> rc = {}) const
-> llama::NrAndOffset<std::size_t>
{
// [0][0] is at left top
Expand Down
14 changes: 7 additions & 7 deletions include/llama/Concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace llama
template<typename M>
concept Mapping = requires(M m) {
typename M::ArrayExtents;
typename M::ArrayIndex;
typename M::RecordDim;
{
m.extents()
Expand All @@ -36,7 +35,7 @@ namespace llama
};

template<typename M, typename RC>
concept PhysicalField = requires(M m, typename M::ArrayIndex ai) {
concept PhysicalField = requires(M m, typename M::ArrayExtents::Index ai) {
{
m.blobNrAndOffset(ai, RC{})
} -> std::same_as<NrAndOffset<typename M::ArrayExtents::value_type>>;
Expand Down Expand Up @@ -81,11 +80,12 @@ namespace llama
|| (ProxyReference<R> && std::is_same_v<typename R::value_type, T>);

template<typename M, typename RC>
concept ComputedField = M::isComputed(RC{}) && requires(M m, typename M::ArrayIndex ai, std::byte** blobs) {
{
m.compute(ai, RC{}, blobs)
} -> AnyReferenceTo<GetType<typename M::RecordDim, RC>>;
};
concept ComputedField
= M::isComputed(RC{}) && requires(M m, typename M::ArrayExtents::Index ai, std::byte** blobs) {
{
m.compute(ai, RC{}, blobs)
} -> AnyReferenceTo<GetType<typename M::RecordDim, RC>>;
};

template<typename M>
struct MakeIsComputed
Expand Down
8 changes: 4 additions & 4 deletions include/llama/DumpMapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ namespace llama
template<typename View, typename RecordCoord>
void boxesFromComputedField(
View& view,
typename View::Mapping::ArrayIndex ai,
typename View::Mapping::ArrayExtents::Index ai,
RecordCoord rc,
std::vector<FieldBox<typename View::Mapping::ArrayIndex>>& infos)
std::vector<FieldBox<typename View::Mapping::ArrayExtents::Index>>& infos)
{
using Mapping = typename View::Mapping;
using RecordDim = typename Mapping::RecordDim;
Expand Down Expand Up @@ -182,9 +182,9 @@ namespace llama
}

template<typename Mapping>
auto boxesFromMapping(const Mapping& mapping) -> std::vector<FieldBox<typename Mapping::ArrayIndex>>
auto boxesFromMapping(const Mapping& mapping) -> std::vector<FieldBox<typename Mapping::ArrayExtents::Index>>
{
std::vector<FieldBox<typename Mapping::ArrayIndex>> infos;
std::vector<FieldBox<typename Mapping::ArrayExtents::Index>> infos;

std::optional<decltype(allocView(mapping))> view;
if constexpr(hasAnyComputedField<Mapping>())
Expand Down
4 changes: 2 additions & 2 deletions include/llama/RecordRef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,14 @@ namespace llama
/// should not be created by the user. They are returned from various access functions in \ref View and RecordRef
/// itself.
template<typename TView, typename TBoundRecordCoord, bool OwnView>
struct RecordRef : private TView::Mapping::ArrayIndex
struct RecordRef : private TView::Mapping::ArrayExtents::Index
{
using View = TView; ///< View this record reference points into.
using BoundRecordCoord
= TBoundRecordCoord; ///< Record coords into View::RecordDim which are already bound by this RecordRef.

private:
using ArrayIndex = typename View::Mapping::ArrayIndex;
using ArrayIndex = typename View::Mapping::ArrayExtents::Index;
using RecordDim = typename View::Mapping::RecordDim;

std::conditional_t<OwnView, View, View&> view;
Expand Down
10 changes: 5 additions & 5 deletions include/llama/View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace llama
template<typename Mapping, typename BlobType, typename Accessor, std::size_t... RCs>
LLAMA_FN_HOST_ACC_INLINE void constructField(
View<Mapping, BlobType, Accessor>& view,
typename Mapping::ArrayIndex ai,
typename Mapping::ArrayExtents::Index ai,
RecordCoord<RCs...> rc)
{
using FieldType = GetType<typename Mapping::RecordDim, decltype(rc)>;
Expand Down Expand Up @@ -348,7 +348,7 @@ namespace llama
template<typename Mapping, typename RecordCoord, typename Blobs>
LLAMA_FN_HOST_ACC_INLINE auto mapToMemory(
Mapping& mapping,
typename Mapping::ArrayIndex ai,
typename Mapping::ArrayExtents::Index ai,
RecordCoord rc,
Blobs& blobs) -> decltype(auto)
{
Expand Down Expand Up @@ -386,7 +386,7 @@ namespace llama
using Mapping = TMapping;
using BlobType = TBlobType;
using ArrayExtents = typename Mapping::ArrayExtents;
using ArrayIndex = typename Mapping::ArrayIndex;
using ArrayIndex = typename ArrayExtents::Index;
using RecordDim = typename Mapping::RecordDim;
using Accessor = TAccessor;
using iterator = Iterator<View>;
Expand Down Expand Up @@ -670,7 +670,7 @@ namespace llama
using ParentView = std::remove_const_t<std::remove_reference_t<StoredParentView>>; ///< type of the parent view
using Mapping = typename ParentView::Mapping; ///< mapping of the parent view
using ArrayExtents = typename Mapping::ArrayExtents; ///< array extents of the parent view
using ArrayIndex = typename Mapping::ArrayIndex; ///< array index of the parent view
using ArrayIndex = typename ArrayExtents::Index; ///< array index of the parent view

using size_type = typename ArrayExtents::value_type;

Expand Down Expand Up @@ -740,6 +740,6 @@ namespace llama
/// SubView vview(view); will store a reference to view.
/// SubView vview(std::move(view)); will store the view.
template<typename TStoredParentView>
SubView(TStoredParentView&&, typename std::remove_reference_t<TStoredParentView>::Mapping::ArrayIndex)
SubView(TStoredParentView&&, typename std::remove_reference_t<TStoredParentView>::Mapping::ArrayExtents::Index)
-> SubView<TStoredParentView>;
} // namespace llama
5 changes: 4 additions & 1 deletion include/llama/mapping/Bytesplit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ namespace llama::mapping
using Inner = InnerMapping<TArrayExtents, internal::SplitBytes<TRecordDim>>;

using ArrayExtents = typename Inner::ArrayExtents;
using ArrayIndex = typename Inner::ArrayIndex;
using RecordDim = TRecordDim; // hide Inner::RecordDim
using Inner::blobCount;

using Inner::blobSize;
using Inner::extents;

private:
using ArrayIndex = typename TArrayExtents::Index;

public:
LLAMA_FN_HOST_ACC_INLINE
constexpr explicit Bytesplit(TArrayExtents extents, TRecordDim = {}) : Inner(extents)
{
Expand Down
5 changes: 4 additions & 1 deletion include/llama/mapping/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ namespace llama::mapping
struct MappingBase : protected TArrayExtents
{
using ArrayExtents = TArrayExtents;
using ArrayIndex = typename ArrayExtents::Index;
using RecordDim = TRecordDim;

protected:
using ArrayIndex = typename ArrayExtents::Index;
using size_type = typename ArrayExtents::value_type;

public:
constexpr MappingBase() = default;

LLAMA_FN_HOST_ACC_INLINE
Expand Down
2 changes: 1 addition & 1 deletion include/llama/mapping/FieldAccessCount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ namespace llama::mapping

template<std::size_t... RecordCoords, typename Blobs>
LLAMA_FN_HOST_ACC_INLINE auto compute(
typename Mapping::ArrayIndex ai,
typename Mapping::ArrayExtents::Index ai,
RecordCoord<RecordCoords...> rc,
Blobs& blobs) const -> decltype(auto)
{
Expand Down
11 changes: 6 additions & 5 deletions include/llama/mapping/Heatmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ namespace llama::mapping

private:
using size_type = typename Mapping::ArrayExtents::value_type;
using ArrayIndex = typename Mapping::ArrayExtents::Index;

public:
using Inner = Mapping;
inline static constexpr std::size_t granularity = Granularity;
using CountType = TCountType;
using typename Mapping::ArrayExtents;
using typename Mapping::ArrayIndex;
#ifdef _MSC_VER
using typename Mapping::ArrayExtents::Index;
#endif
using typename Mapping::RecordDim;

// We duplicate every blob of the inner mapping with a shadow blob, where we count the accesses
Expand Down Expand Up @@ -81,10 +84,8 @@ namespace llama::mapping
}

template<std::size_t... RecordCoords, typename Blobs>
LLAMA_FN_HOST_ACC_INLINE auto compute(
typename Mapping::ArrayIndex ai,
RecordCoord<RecordCoords...> rc,
Blobs& blobs) const -> decltype(auto)
LLAMA_FN_HOST_ACC_INLINE auto compute(ArrayIndex ai, RecordCoord<RecordCoords...> rc, Blobs& blobs) const
-> decltype(auto)
{
static_assert(
!std::is_const_v<Blobs>,
Expand Down
2 changes: 1 addition & 1 deletion include/llama/mapping/PermuteArrayIndex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ namespace llama::mapping
{
private:
using size_type = typename Mapping::ArrayExtents::value_type;
using ArrayIndex = typename Mapping::ArrayExtents::Index;

public:
using Inner = Mapping;
using ArrayIndex = typename Inner::ArrayIndex;

constexpr PermuteArrayIndex() = default;

Expand Down
7 changes: 5 additions & 2 deletions include/llama/mapping/Projection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,16 @@ namespace llama::mapping
= InnerMapping<TArrayExtents, internal::ReplaceTypesByProjectionResults<TRecordDim, TProjectionMap>>;
using ProjectionMap = TProjectionMap;
using ArrayExtents = typename Inner::ArrayExtents;
using ArrayIndex = typename Inner::ArrayIndex;
using RecordDim = TRecordDim; // hide Inner::RecordDim
using Inner::blobCount;
using Inner::blobSize;
using Inner::extents;
using Inner::Inner;

protected:
using ArrayIndex = typename ArrayExtents::Index;

public:
template<typename RecordCoord>
LLAMA_FN_HOST_ACC_INLINE static constexpr auto isComputed(RecordCoord) -> bool
{
Expand All @@ -150,7 +153,7 @@ namespace llama::mapping

template<std::size_t... RecordCoords, typename BlobArray>
LLAMA_FN_HOST_ACC_INLINE constexpr auto compute(
typename Inner::ArrayIndex ai,
ArrayIndex ai,
RecordCoord<RecordCoords...> rc,
BlobArray& blobs) const
{
Expand Down
10 changes: 5 additions & 5 deletions tests/mapping.AoS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TEST_CASE("mapping.AoS.Packed.address")
{
using Mapping = llama::mapping::PackedAoS<decltype(arrayExtents), Particle>;
auto mapping = Mapping{arrayExtents};
using ArrayIndex = typename Mapping::ArrayIndex;
using ArrayIndex = typename Mapping::ArrayExtents::Index;

STATIC_REQUIRE(mapping.blobCount == 1);
CHECK(mapping.blobSize(0) == 14336);
Expand Down Expand Up @@ -72,7 +72,7 @@ TEST_CASE("mapping.AoS.Packed.fortran.address")
using Mapping
= llama::mapping::PackedAoS<decltype(arrayExtents), Particle, llama::mapping::LinearizeArrayDimsFortran>;
auto mapping = Mapping{arrayExtents};
using ArrayIndex = typename Mapping::ArrayIndex;
using ArrayIndex = typename Mapping::ArrayExtents::Index;

STATIC_REQUIRE(mapping.blobCount == 1);
CHECK(mapping.blobSize(0) == 14336);
Expand Down Expand Up @@ -135,7 +135,7 @@ TEST_CASE("mapping.AoS.Packed.morton.address")
using Mapping
= llama::mapping::PackedAoS<decltype(arrayExtents), Particle, llama::mapping::LinearizeArrayDimsMorton>;
auto mapping = Mapping{arrayExtents};
using ArrayIndex = typename Mapping::ArrayIndex;
using ArrayIndex = typename Mapping::ArrayExtents::Index;

STATIC_REQUIRE(mapping.blobCount == 1);
CHECK(mapping.blobSize(0) == 14336);
Expand Down Expand Up @@ -197,7 +197,7 @@ TEST_CASE("mapping.AoS.Aligned.address")
{
using Mapping = llama::mapping::AlignedAoS<decltype(arrayExtents), Particle>;
auto mapping = Mapping{arrayExtents};
using ArrayIndex = typename Mapping::ArrayIndex;
using ArrayIndex = typename Mapping::ArrayExtents::Index;

STATIC_REQUIRE(mapping.blobCount == 1);
CHECK(mapping.blobSize(0) == 16384);
Expand Down Expand Up @@ -259,7 +259,7 @@ TEST_CASE("mapping.AoS.aligned_min.address")
{
using Mapping = llama::mapping::MinAlignedAoS<decltype(arrayExtents), Particle>;
auto mapping = Mapping{arrayExtents};
using ArrayIndex = typename Mapping::ArrayIndex;
using ArrayIndex = typename Mapping::ArrayExtents::Index;

STATIC_REQUIRE(mapping.blobCount == 1);
CHECK(mapping.blobSize(0) == 14336);
Expand Down
2 changes: 1 addition & 1 deletion tests/mapping.AoSoA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TEST_CASE("mapping.AoSoA.4.address")
{
using Mapping = llama::mapping::AoSoA<decltype(arrayExtents), Particle, 4>;
auto mapping = Mapping{arrayExtents};
using ArrayIndex = typename Mapping::ArrayIndex;
using ArrayIndex = typename Mapping::ArrayExtents::Index;

{
const auto ai = ArrayIndex{0, 0};
Expand Down
6 changes: 3 additions & 3 deletions tests/mapping.One.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TEST_CASE("mapping.One.Packed.address")
{
using Mapping = llama::mapping::PackedOne<decltype(arrayExtents), Particle>;
auto mapping = Mapping{arrayExtents};
using ArrayIndex = typename Mapping::ArrayIndex;
using ArrayIndex = typename Mapping::ArrayExtents::Index;

STATIC_REQUIRE(mapping.blobCount == 1);
STATIC_REQUIRE(mapping.blobSize(0) == 56);
Expand Down Expand Up @@ -41,7 +41,7 @@ TEST_CASE("mapping.One.Aligned.address")
{
using Mapping = llama::mapping::AlignedOne<decltype(arrayExtents), Particle>;
auto mapping = Mapping{arrayExtents};
using ArrayIndex = typename Mapping::ArrayIndex;
using ArrayIndex = typename Mapping::ArrayExtents::Index;

STATIC_REQUIRE(mapping.blobCount == 1);
STATIC_REQUIRE(mapping.blobSize(0) == 60);
Expand Down Expand Up @@ -73,7 +73,7 @@ TEST_CASE("mapping.One.MinAligned.address")
{
using Mapping = llama::mapping::MinAlignedOne<decltype(arrayExtents), Particle>;
auto mapping = Mapping{arrayExtents};
using ArrayIndex = typename Mapping::ArrayIndex;
using ArrayIndex = typename Mapping::ArrayExtents::Index;

STATIC_REQUIRE(mapping.blobCount == 1);
STATIC_REQUIRE(mapping.blobSize(0) == 56);
Expand Down
Loading

0 comments on commit 2c2987d

Please sign in to comment.