Skip to content

Commit

Permalink
Merge pull request #1730 from DARMA-tasking/1544-add-backup-option-fo…
Browse files Browse the repository at this point in the history
…r-default-map

1544: Implement default_map for indices with more than 3 dimensions
  • Loading branch information
lifflander authored Jun 14, 2022
2 parents a9753fe + c2f3118 commit 39230e6
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/vt/topos/index/dense/dense_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct DenseIndexArray : BaseIndex, serialization::ByteCopyTrait {
DenseIndexArray(std::array<IndexType, ndim> in_array);
DenseIndexArray(DenseIndexArraySingleInitTag, IndexType const& init_value);

NumDimensionsType ndims() const { return ndim; }
static constexpr NumDimensionsType ndims() { return ndim; }

IndexType& operator[](IndexType const& index);
IndexType const& operator[](IndexType const& index) const;
Expand Down
2 changes: 2 additions & 0 deletions src/vt/topos/index/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ using IdxBase = index::IdxBase;
using Index1D = index::Index1D<index::IdxBase>;
using Index2D = index::Index2D<index::IdxBase>;
using Index3D = index::Index3D<index::IdxBase>;
template <int8_t N>
using IndexND = index::IdxType<index::IdxBase, N>;

template <typename T, int8_t N> using IdxType = index::IdxType<T, N>;
template <typename T> using IdxType1D = index::Index1D<T>;
Expand Down
16 changes: 16 additions & 0 deletions src/vt/topos/mapping/dense/dense.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ using IdxPtr = Index*;
template <typename T = IdxBase> using Idx1DPtr = IdxType1D<T>*;
template <typename T = IdxBase> using Idx2DPtr = IdxType2D<T>*;
template <typename T = IdxBase> using Idx3DPtr = IdxType3D<T>*;
template <typename T, int8_t N> using IdxNDPtr = IdxType<T, N>*;

template <typename Idx, index::NumDimensionsType ndim>
NodeType denseBlockMap(IdxPtr<Idx> idx, IdxPtr<Idx> max_idx, NodeType nnodes);
Expand All @@ -84,24 +85,31 @@ template <typename T = IdxBase>
NodeType defaultDenseIndex2DMap(Idx2DPtr<T> idx, Idx2DPtr<T> max, NodeType n);
template <typename T = IdxBase>
NodeType defaultDenseIndex3DMap(Idx3DPtr<T> idx, Idx3DPtr<T> max, NodeType n);
template <typename T, int8_t N>
NodeType defaultDenseIndexNDMap(IdxNDPtr<T,N> idx, IdxNDPtr<T,N> max, NodeType n);

template <typename T = IdxBase>
NodeType dense1DRoundRobinMap( Idx1DPtr<T> idx, Idx1DPtr<T> max, NodeType n);
template <typename T = IdxBase>
NodeType dense2DRoundRobinMap( Idx2DPtr<T> idx, Idx2DPtr<T> max, NodeType n);
template <typename T = IdxBase>
NodeType dense3DRoundRobinMap( Idx3DPtr<T> idx, Idx3DPtr<T> max, NodeType n);
template <typename T, int8_t N>
NodeType denseNDRoundRobinMap( IdxNDPtr<T,N> idx, IdxNDPtr<T,N> max, NodeType n);

template <typename T = IdxBase>
NodeType dense1DBlockMap( Idx1DPtr<T> idx, Idx1DPtr<T> max, NodeType n);
template <typename T = IdxBase>
NodeType dense2DBlockMap( Idx2DPtr<T> idx, Idx2DPtr<T> max, NodeType n);
template <typename T = IdxBase>
NodeType dense3DBlockMap( Idx3DPtr<T> idx, Idx3DPtr<T> max, NodeType n);
template <typename T, int8_t N>
NodeType denseNDBlockMap( IdxNDPtr<T,N> idx, IdxNDPtr<T,N> max, NodeType n);

template <typename T = IdxBase> using i1D = IdxType1D<T>;
template <typename T = IdxBase> using i2D = IdxType2D<T>;
template <typename T = IdxBase> using i3D = IdxType3D<T>;
template <typename T, int8_t N> using iND = IdxType<T,N>;

template <typename F, F* f, typename IndexT>
using Adapt = MapFunctorAdapt<F, f, IndexT>;
Expand All @@ -112,18 +120,26 @@ template <typename T = IdxBase>
using dense2DMapFn = Adapt<MapAdapter<i2D<T>>, defaultDenseIndex2DMap<T>, i2D<T> >;
template <typename T = IdxBase>
using dense3DMapFn = Adapt<MapAdapter<i3D<T>>, defaultDenseIndex3DMap<T>, i3D<T> >;
template <typename T, int8_t N>
using denseNDMapFn = Adapt<MapAdapter<iND<T, N>>, defaultDenseIndexNDMap<T>, iND<T, N> >;

template <typename T = IdxBase>
using dense1DRRMapFn = Adapt<MapAdapter<i1D<T>>, dense1DRoundRobinMap<T>, i1D<T>>;
template <typename T = IdxBase>
using dense2DRRMapFn = Adapt<MapAdapter<i2D<T>>, dense2DRoundRobinMap<T>, i2D<T>>;
template <typename T = IdxBase>
using dense3DRRMapFn = Adapt<MapAdapter<i3D<T>>, dense3DRoundRobinMap<T>, i3D<T>>;
template <typename T, int8_t N>
using denseNDRRMapFn = Adapt<MapAdapter<iND<T, N>>, denseNDRoundRobinMap<T>, iND<T, N> >;

template <typename T = IdxBase>
using dense1DBlkMapFn = Adapt<MapAdapter<i1D<T>>, dense1DBlockMap<T>, i1D<T>>;
template <typename T = IdxBase>
using dense2DBlkMapFn = Adapt<MapAdapter<i2D<T>>, dense2DBlockMap<T>, i2D<T>>;
template <typename T = IdxBase>
using dense3DBlkMapFn = Adapt<MapAdapter<i3D<T>>, dense3DBlockMap<T>, i3D<T>>;
template <typename T, int8_t N>
using denseNDBlkMapFn = Adapt<MapAdapter<iND<T, N>>, denseNDBlockMap<T>, iND<T, N> >;

}} // end namespace vt::mapping

Expand Down
17 changes: 17 additions & 0 deletions src/vt/topos/mapping/dense/dense.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ NodeType defaultDenseIndex3DMap(Idx3DPtr<T> idx, Idx3DPtr<T> max, NodeType nx) {
return dense3DBlockMap<T>(idx, max, nx);
}

template <typename T, int8_t N>
NodeType defaultDenseIndexNDMap(IdxNDPtr<T,N> idx, IdxNDPtr<T,N> max, NodeType nx) {
return denseNDBlockMap<T>(idx, max, nx);
}

// Default round robin mappings
template <typename T>
NodeType dense1DRoundRobinMap(Idx1DPtr<T> idx, Idx1DPtr<T> max, NodeType nx) {
Expand All @@ -88,6 +93,13 @@ NodeType dense3DRoundRobinMap(Idx3DPtr<T> idx, Idx3DPtr<T> max, NodeType nx) {
return lin_idx % nx;
}

template <typename T, int8_t N>
NodeType denseNDRoundRobinMap(IdxNDPtr<T,N> idx, IdxNDPtr<T,N> max, NodeType nx) {
using IndexElmType = typename IdxType<T, N>::DenseIndexType;
auto const& lin_idx = linearizeDenseIndexColMajor<IndexElmType, N>(idx, max);
return lin_idx % nx;
}

// Default block mappings
template <typename T>
NodeType dense1DBlockMap(Idx1DPtr<T> idx, Idx1DPtr<T> max, NodeType nx) {
Expand All @@ -104,6 +116,11 @@ NodeType dense3DBlockMap(Idx3DPtr<T> idx, Idx3DPtr<T> max, NodeType nx) {
return denseBlockMap<IdxType3D<T>, 3>(idx, max, nx);
}

template <typename T, int8_t N>
NodeType denseNDBlockMap(IdxNDPtr<T,N> idx, IdxNDPtr<T,N> max, NodeType nx) {
return denseBlockMap<IdxType<T,N>, N>(idx, max, nx);
}

template <typename IndexElmType, typename PhysicalType>
inline NodeType blockMapDenseFlatIndex(
IndexElmType* flat_idx_ptr, IndexElmType* num_elems_ptr,
Expand Down
13 changes: 11 additions & 2 deletions src/vt/vrt/collection/defaults/default_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@ struct DefaultMapBase {
using MapParamPackType = std::tuple<IndexPtrType,IndexPtrType,NodeType>;
};

template <typename CollectionT, typename Enable=void>
struct DefaultMap;
template <typename CollectionT, typename Enable = void>
struct DefaultMap : DefaultMapBase<CollectionT> {
using BaseType = typename CollectionT::IndexType::DenseIndexType;
using BlockMapType =
::vt::mapping::denseNDMapFn<BaseType, CollectionT::IndexType::ndims()>;
using RRMapType =
::vt::mapping::denseNDRRMapFn<BaseType, CollectionT::IndexType::ndims()>;
using DefaultMapType =
::vt::mapping::denseNDMapFn<BaseType, CollectionT::IndexType::ndims()>;
using MapType = DefaultMapType;
};

/*
* Default mappings for Index1D: RR, Block, etc.
Expand Down
22 changes: 18 additions & 4 deletions tests/unit/collection/test_collection_construct_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,25 @@ struct ConstructParams {
TYPED_TEST_SUITE_P(TestConstruct);
TYPED_TEST_SUITE_P(TestConstructDist);

template <typename ColT, uint8_t N>
typename ColT::IndexType CreateRange(typename ColT::IndexType::DenseIndexType range) {
std::array<typename ColT::IndexType::DenseIndexType, N> arr;
std::fill(arr.begin(), arr.end(), range);

return arr;
}

template<typename ColType>
void test_construct_1(std::string const& label) {
using MsgType = typename ColType::MsgType;

auto const& this_node = theContext()->getNode();
if (this_node == 0) {
auto const& col_size = 32;
auto rng = TestIndex(col_size);
// We don't want too many elements for 4 dimensions
auto constexpr num_dims = ColType::IndexType::ndims();
auto constexpr col_size = 8 / num_dims;

auto rng = CreateRange<ColType, num_dims>(col_size);
auto proxy = ConstructParams<ColType>::construct(label, rng);
proxy.template broadcast<
MsgType,
Expand All @@ -128,8 +139,11 @@ template<typename ColType>
void test_construct_distributed_1() {
using MsgType = typename ColType::MsgType;

auto const& col_size = 32;
auto rng = TestIndex(col_size);
// We don't want too many elements for 4 dimensions
auto constexpr num_dims = ColType::IndexType::ndims();
auto constexpr col_size = 8 / num_dims;

auto rng = CreateRange<ColType, num_dims>(col_size);
auto proxy = ConstructParams<ColType>::constructCollective(
rng, "test_construct_distributed_1"
);
Expand Down
24 changes: 17 additions & 7 deletions tests/unit/collection/test_construct.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,26 @@
namespace vt { namespace tests { namespace unit {

namespace default_ {
struct ColMsg;
struct TestCol : Collection<TestCol,vt::Index1D> {
using MsgType = ColMsg;
struct Col1DMsg;
struct Col4DMsg;

struct TestCol1D : Collection<TestCol1D, vt::Index1D> {
using MsgType = Col1DMsg;
};

struct TestCol4D : Collection<TestCol4D, vt::IndexND<4>> {
using MsgType = Col4DMsg;
};

struct ColMsg : CollectionMessage<TestCol> { };
struct Col1DMsg : CollectionMessage<TestCol1D> { };
struct Col4DMsg : CollectionMessage<TestCol4D> { };
} /* end namespace default_ */

using CollectionTestTypes = testing::Types<default_::TestCol>;
using CollectionTestDistTypes = testing::Types<default_::TestCol>;
using CollectionTestTypes =
testing::Types<default_::TestCol1D, default_::TestCol4D>;

using CollectionTestDistTypes =
testing::Types<default_::TestCol1D, default_::TestCol4D>;

TYPED_TEST_P(TestConstruct, test_construct_basic_1) {
test_construct_1<TypeParam>("test_construct_basic_1");
Expand Down Expand Up @@ -90,7 +100,7 @@ TEST_F(TestConstructLabel, test_labels) {
auto const range = Index1D(num_nodes);
std::string const label = "test_labels";

auto proxy = makeCollection<default_::TestCol>(label)
auto proxy = makeCollection<default_::TestCol1D>(label)
.bounds(range)
.bulkInsert()
.wait();
Expand Down

0 comments on commit 39230e6

Please sign in to comment.