Skip to content

Commit

Permalink
allow to configure submappings of OffsetTable
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jul 7, 2021
1 parent fbc3414 commit bf0f7fc
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 8 deletions.
4 changes: 2 additions & 2 deletions include/llama/DumpMapping.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ namespace llama
return infos;
}

template <typename ArrayDims, typename RecordDim>
auto boxesFromMapping(const mapping::OffsetTable<ArrayDims, RecordDim>& mapping)
template <typename ArrayDims, typename RecordDim, typename SubMappings>
auto boxesFromMapping(const mapping::OffsetTable<ArrayDims, RecordDim, SubMappings>& mapping)
-> std::vector<FieldBox<ArrayDims::rank>>
{
std::size_t previousBlobs = 0;
Expand Down
47 changes: 43 additions & 4 deletions include/llama/mapping/OffsetTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,55 @@ namespace llama::mapping
};
} // namespace internal

template <typename T_ArrayDims, typename T_RecordDim>
/// A type list containing mappings.
template <template <typename, typename> typename... SubMappings>
struct MappingList;

namespace internal
{
template <typename SubRecordDims, typename Mappings>
struct MapSubRecordDims;

template <typename... SubRecordDims, template <typename, typename> typename... SubMappings>
struct MapSubRecordDims<boost::mp11::mp_list<SubRecordDims...>, MappingList<SubMappings...>>
{
static_assert(
sizeof...(SubRecordDims) == sizeof...(SubMappings),
"There must be as many mappings as sub record dimensions");
using List = boost::mp11::mp_list<SubMappings<ArrayDims<1>, SubRecordDims>...>;
};

template <typename... SubRecordDims, template <typename, typename> typename Mapping>
struct MapSubRecordDims<boost::mp11::mp_list<SubRecordDims...>, MappingList<Mapping>>
{
private:
template <typename SubRecordDim>
using MapRecordDim = Mapping<ArrayDims<1>, SubRecordDim>;

public:
using List = boost::mp11::mp_transform<MapRecordDim, boost::mp11::mp_list<SubRecordDims...>>;
};
} // namespace internal

/// Meta mapping splitting off sub branches of the given record dimension tree at each field which's type is a
/// dynamic array. Each dynamic array field is then replaced by an integral offset of type \ref EndOffsetType. This
/// offset is used to navigate from a virtual record into a dynamic sub array member using a dynamic index. Two
/// computed fields are added per dynamic array field, which are named \ref EndOffset and \ref Size, giving access
/// to the offset value and the size of a dynamic sub array. The list of sub record dimensions is then further
/// mapped using a list of sub mappings.
///
/// @tparam T_RecordDim A record dimension, possibly including field types which are dynamic arrays.
/// @tparam SubMappings A \ref MappingList of mappings that will be used to map the sub record dimensions after
/// splitting T_RecordDim at each dynamic array field. If the mapping list contains a single mapping, this one will
/// be used to map all sub record dimensions. Otherwise, a mapping needs to be given for each sub record dimension.
template <typename T_ArrayDims, typename T_RecordDim, typename SubMappings = MappingList<PreconfiguredAoS<>::type>>
struct OffsetTable
{
using RDS = internal::ReplaceDynamicSubarrays<T_RecordDim, RecordCoord<>>;
using SubRecordDims = boost::mp11::mp_push_front<typename RDS::SubRecordDims, typename RDS::Replaced>;
using SplitCoords = typename RDS::SplitCoords;

template <typename SubRecordDim>
using MapRecordDim = AlignedAoS<llama::ArrayDims<1>, SubRecordDim>; // TODO: make this configureable
using MappedSubRecordDims = boost::mp11::mp_transform<MapRecordDim, SubRecordDims>;
using MappedSubRecordDims = typename internal::MapSubRecordDims<SubRecordDims, SubMappings>::List;

boost::mp11::mp_rename<MappedSubRecordDims, Tuple> subMappings;

Expand Down
59 changes: 57 additions & 2 deletions tests/recorddimension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,6 @@ TEST_CASE("edm")
llama::ArrayDims{3},
llama::ArrayDims{5},
llama::ArrayDims{4}};
std::ofstream{"dump.edm.svg"} << llama::toSvg(mapping);
std::ofstream{"dump.edm.html"} << llama::toHtml(mapping);
auto view = llama::allocView(mapping);

// setup offset table
Expand Down Expand Up @@ -426,3 +424,60 @@ TEST_CASE("edm")
CHECK(view(2)(Muons{})(0) (Mass{}) == value++);
CHECK(view(2)(Muons{})(0) (Phi{}) == value++);
}

TEST_CASE("dump.edm.AlignedAoS")
{
auto mapping = llama::mapping::OffsetTable<llama::ArrayDims<1>, Event>{
llama::ArrayDims{30},
llama::ArrayDims{50},
llama::ArrayDims{40}};
std::ofstream{"dump.edm.AlignedAoS.svg"} << llama::toSvg(mapping);
std::ofstream{"dump.edm.AlignedAoS.html"} << llama::toHtml(mapping);
}

TEST_CASE("dump.edm.MultiBlobSoA")
{
auto mapping = llama::mapping::
OffsetTable<llama::ArrayDims<1>, Event, llama::mapping::MappingList<llama::mapping::PreconfiguredSoA<>::type>>{
llama::ArrayDims{30},
llama::ArrayDims{50},
llama::ArrayDims{40}};
std::ofstream{"dump.edm.MultiBlobSoA.svg"} << llama::toSvg(mapping);
std::ofstream{"dump.edm.MultiBlobSoA.html"} << llama::toHtml(mapping);
}

TEST_CASE("dump.edm.AlignedAoS_MultiBlobSoA")
{
auto mapping = llama::mapping::OffsetTable<
llama::ArrayDims<1>,
Event,
llama::mapping::MappingList<
llama::mapping::PreconfiguredAoS<>::type,
llama::mapping::PreconfiguredSoA<>::type,
llama::mapping::PreconfiguredSoA<>::type>>{
llama::ArrayDims{30},
llama::ArrayDims{50},
llama::ArrayDims{40}};
std::ofstream{"dump.edm.AlignedAoS_MultiBlobSoA.svg"} << llama::toSvg(mapping);
std::ofstream{"dump.edm.AlignedAoS_MultiBlobSoA.html"} << llama::toHtml(mapping);
}

TEST_CASE("dump.edm.Split_AlignedAoS_MultiBlobSoA")
{
auto mapping = llama::mapping::OffsetTable<
llama::ArrayDims<1>,
Event,
llama::mapping::MappingList<
llama::mapping::PreconfiguredSplit<
llama::RecordCoord<2>,
llama::mapping::PreconfiguredAoS<>::type,
llama::mapping::PreconfiguredAoS<>::type,
true>::type,
llama::mapping::PreconfiguredSoA<>::type,
llama::mapping::PreconfiguredSoA<>::type>>{
llama::ArrayDims{30},
llama::ArrayDims{50},
llama::ArrayDims{40}};
std::ofstream{"dump.edm.Split_AlignedAoS_MultiBlobSoA.svg"} << llama::toSvg(mapping);
std::ofstream{"dump.edm.Split_AlignedAoS_MultiBlobSoA.html"} << llama::toHtml(mapping);
}

0 comments on commit bf0f7fc

Please sign in to comment.