From 78708f2b324ec0bc35ddbeb21030a34301c4d849 Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Mon, 14 Mar 2022 21:27:54 +0100 Subject: [PATCH 1/4] #1544: Add unit test for Collection with indicies over 3 dimensions --- src/vt/topos/mapping/dense/dense.h | 3 +++ .../test_collection_construct_common.h | 18 ++++++++++----- tests/unit/collection/test_construct.cc | 22 ++++++++++++++----- .../test_construct_no_idx.extended.cc | 1 + 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/vt/topos/mapping/dense/dense.h b/src/vt/topos/mapping/dense/dense.h index ed819498e2..83598acfab 100644 --- a/src/vt/topos/mapping/dense/dense.h +++ b/src/vt/topos/mapping/dense/dense.h @@ -74,6 +74,7 @@ using IdxPtr = Index*; template using Idx1DPtr = IdxType1D*; template using Idx2DPtr = IdxType2D*; template using Idx3DPtr = IdxType3D*; +template using IdxNDPtr = vt::index::IdxType*; template NodeType denseBlockMap(IdxPtr idx, IdxPtr max_idx, NodeType nnodes); @@ -84,6 +85,8 @@ template NodeType defaultDenseIndex2DMap(Idx2DPtr idx, Idx2DPtr max, NodeType n); template NodeType defaultDenseIndex3DMap(Idx3DPtr idx, Idx3DPtr max, NodeType n); +template +NodeType defaultDenseIndex3DMap(IdxNDPtr idx, IdxNDPtr max, NodeType n); template NodeType dense1DRoundRobinMap( Idx1DPtr idx, Idx1DPtr max, NodeType n); diff --git a/tests/unit/collection/test_collection_construct_common.h b/tests/unit/collection/test_collection_construct_common.h index 997680c326..8aaed7304e 100644 --- a/tests/unit/collection/test_collection_construct_common.h +++ b/tests/unit/collection/test_collection_construct_common.h @@ -108,6 +108,14 @@ struct ConstructParams { TYPED_TEST_SUITE_P(TestConstruct); TYPED_TEST_SUITE_P(TestConstructDist); +template +typename ColT::IndexType CreateRange(typename ColT::IndexType::DenseIndexType range) { + std::array arr; + std::fill(arr.begin(), arr.end(), range); + + return arr; +} + template void test_construct_1(std::string const& label) { using MsgType = typename ColType::MsgType; @@ -115,8 +123,10 @@ void test_construct_1(std::string const& label) { auto const& this_node = theContext()->getNode(); if (this_node == 0) { auto const& col_size = 32; - auto rng = TestIndex(col_size); + + auto rng = CreateRange(col_size); auto proxy = ConstructParams::construct(label, rng); + proxy.template broadcast< MsgType, ConstructHandlers::handler @@ -129,10 +139,8 @@ void test_construct_distributed_1() { using MsgType = typename ColType::MsgType; auto const& col_size = 32; - auto rng = TestIndex(col_size); - auto proxy = ConstructParams::constructCollective( - rng, "test_construct_distributed_1" - ); + auto rng = CreateRange(col_size); + auto proxy = ConstructParams::constructCollective(rng, "test_construct_distributed_1"); proxy.template broadcast< MsgType, ConstructHandlers::handler diff --git a/tests/unit/collection/test_construct.cc b/tests/unit/collection/test_construct.cc index 6a54b9ab6d..31d60c9212 100644 --- a/tests/unit/collection/test_construct.cc +++ b/tests/unit/collection/test_construct.cc @@ -53,16 +53,26 @@ namespace vt { namespace tests { namespace unit { namespace default_ { -struct ColMsg; -struct TestCol : Collection { - using MsgType = ColMsg; +struct Col1DMsg; +struct Col4DMsg; + +struct TestCol1D : Collection { + using MsgType = Col1DMsg; +}; + +struct TestCol4D : Collection> { + using MsgType = Col4DMsg; }; -struct ColMsg : CollectionMessage { }; +struct Col1DMsg : CollectionMessage { }; +struct Col4DMsg : CollectionMessage { }; } /* end namespace default_ */ -using CollectionTestTypes = testing::Types; -using CollectionTestDistTypes = testing::Types; +using CollectionTestTypes = + testing::Types; + +using CollectionTestDistTypes = + testing::Types; TYPED_TEST_P(TestConstruct, test_construct_basic_1) { test_construct_1("test_construct_basic_1"); diff --git a/tests/unit/collection/test_construct_no_idx.extended.cc b/tests/unit/collection/test_construct_no_idx.extended.cc index 6cec8eb1da..603afc12a0 100644 --- a/tests/unit/collection/test_construct_no_idx.extended.cc +++ b/tests/unit/collection/test_construct_no_idx.extended.cc @@ -57,6 +57,7 @@ struct ColMsg; struct TestCol : Collection { using MsgType = ColMsg; }; + struct ColMsg : CollectionMessage {}; } /* end namespace multi_param_no_idx_ */ From a4832ac81f60b54b4eab1ed9047820668aae5f10 Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Tue, 5 Apr 2022 15:38:57 +0200 Subject: [PATCH 2/4] #1544: collection: Implement default_map for indices with more than 3 dimensions --- src/vt/topos/index/dense/dense_array.h | 2 +- src/vt/topos/index/index.h | 4 ++++ src/vt/topos/mapping/dense/dense.h | 19 ++++++++++++++++--- src/vt/topos/mapping/dense/dense.impl.h | 10 ++++++++++ src/vt/vrt/collection/defaults/default_map.h | 13 +++++++++++-- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/vt/topos/index/dense/dense_array.h b/src/vt/topos/index/dense/dense_array.h index 51ce06ff66..a40a05d215 100644 --- a/src/vt/topos/index/dense/dense_array.h +++ b/src/vt/topos/index/dense/dense_array.h @@ -102,7 +102,7 @@ struct DenseIndexArray : BaseIndex, serialization::ByteCopyTrait { DenseIndexArray(std::array 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; diff --git a/src/vt/topos/index/index.h b/src/vt/topos/index/index.h index fa064bb2a8..4be63a31a5 100644 --- a/src/vt/topos/index/index.h +++ b/src/vt/topos/index/index.h @@ -60,6 +60,7 @@ template using Index1D = DenseIndexArray; template using Index2D = DenseIndexArray; template using Index3D = DenseIndexArray; template using IdxType = DenseIndexArray; +template using IndexND = DenseIndexArray; static_assert(IndexTraits>::is_index, "Does not conform"); static_assert(IndexTraits>::is_index, "Does not conform"); @@ -76,11 +77,14 @@ using IdxBase = index::IdxBase; using Index1D = index::Index1D; using Index2D = index::Index2D; using Index3D = index::Index3D; +template +using IndexND = index::IndexND; template using IdxType = index::IdxType; template using IdxType1D = index::Index1D; template using IdxType2D = index::Index2D; template using IdxType3D = index::Index3D; +template using IdxTypeND = index::IndexND; } // end namespace vt diff --git a/src/vt/topos/mapping/dense/dense.h b/src/vt/topos/mapping/dense/dense.h index 83598acfab..f78c8dec3a 100644 --- a/src/vt/topos/mapping/dense/dense.h +++ b/src/vt/topos/mapping/dense/dense.h @@ -74,7 +74,7 @@ using IdxPtr = Index*; template using Idx1DPtr = IdxType1D*; template using Idx2DPtr = IdxType2D*; template using Idx3DPtr = IdxType3D*; -template using IdxNDPtr = vt::index::IdxType*; +template using IdxNDPtr = vt::index::IdxType*; template NodeType denseBlockMap(IdxPtr idx, IdxPtr max_idx, NodeType nnodes); @@ -85,8 +85,8 @@ template NodeType defaultDenseIndex2DMap(Idx2DPtr idx, Idx2DPtr max, NodeType n); template NodeType defaultDenseIndex3DMap(Idx3DPtr idx, Idx3DPtr max, NodeType n); -template -NodeType defaultDenseIndex3DMap(IdxNDPtr idx, IdxNDPtr max, NodeType n); +template +NodeType defaultDenseIndexNDMap(IdxNDPtr idx, IdxNDPtr max, NodeType n); template NodeType dense1DRoundRobinMap( Idx1DPtr idx, Idx1DPtr max, NodeType n); @@ -94,6 +94,8 @@ template NodeType dense2DRoundRobinMap( Idx2DPtr idx, Idx2DPtr max, NodeType n); template NodeType dense3DRoundRobinMap( Idx3DPtr idx, Idx3DPtr max, NodeType n); +template +NodeType denseNDRoundRobinMap( IdxNDPtr idx, IdxNDPtr max, NodeType n); template NodeType dense1DBlockMap( Idx1DPtr idx, Idx1DPtr max, NodeType n); @@ -101,10 +103,13 @@ template NodeType dense2DBlockMap( Idx2DPtr idx, Idx2DPtr max, NodeType n); template NodeType dense3DBlockMap( Idx3DPtr idx, Idx3DPtr max, NodeType n); +template +NodeType denseNDBlockMap( IdxNDPtr idx, IdxNDPtr max, NodeType n); template using i1D = IdxType1D; template using i2D = IdxType2D; template using i3D = IdxType3D; +template using iND = IdxTypeND; template using Adapt = MapFunctorAdapt; @@ -115,18 +120,26 @@ template using dense2DMapFn = Adapt>, defaultDenseIndex2DMap, i2D >; template using dense3DMapFn = Adapt>, defaultDenseIndex3DMap, i3D >; +template +using denseNDMapFn = Adapt>, defaultDenseIndexNDMap, iND >; + template using dense1DRRMapFn = Adapt>, dense1DRoundRobinMap, i1D>; template using dense2DRRMapFn = Adapt>, dense2DRoundRobinMap, i2D>; template using dense3DRRMapFn = Adapt>, dense3DRoundRobinMap, i3D>; +template +using denseNDRRMapFn = Adapt>, denseNDRoundRobinMap, iND >; + template using dense1DBlkMapFn = Adapt>, dense1DBlockMap, i1D>; template using dense2DBlkMapFn = Adapt>, dense2DBlockMap, i2D>; template using dense3DBlkMapFn = Adapt>, dense3DBlockMap, i3D>; +template +using denseNDBlkMapFn = Adapt>, denseNDBlockMap, iND >; }} // end namespace vt::mapping diff --git a/src/vt/topos/mapping/dense/dense.impl.h b/src/vt/topos/mapping/dense/dense.impl.h index c608104ec7..2d6d83b8c1 100644 --- a/src/vt/topos/mapping/dense/dense.impl.h +++ b/src/vt/topos/mapping/dense/dense.impl.h @@ -68,6 +68,11 @@ NodeType defaultDenseIndex3DMap(Idx3DPtr idx, Idx3DPtr max, NodeType nx) { return dense3DBlockMap(idx, max, nx); } +template +NodeType defaultDenseIndexNDMap(IdxNDPtr idx, IdxNDPtr max, NodeType nx) { + return denseNDBlockMap(idx, max, nx); +} + // Default round robin mappings template NodeType dense1DRoundRobinMap(Idx1DPtr idx, Idx1DPtr max, NodeType nx) { @@ -104,6 +109,11 @@ NodeType dense3DBlockMap(Idx3DPtr idx, Idx3DPtr max, NodeType nx) { return denseBlockMap, 3>(idx, max, nx); } +template +NodeType denseNDBlockMap(IdxNDPtr idx, IdxNDPtr max, NodeType nx) { + return denseBlockMap, N>(idx, max, nx); +} + template inline NodeType blockMapDenseFlatIndex( IndexElmType* flat_idx_ptr, IndexElmType* num_elems_ptr, diff --git a/src/vt/vrt/collection/defaults/default_map.h b/src/vt/vrt/collection/defaults/default_map.h index 36b2b5979f..af3091f4f2 100644 --- a/src/vt/vrt/collection/defaults/default_map.h +++ b/src/vt/vrt/collection/defaults/default_map.h @@ -61,8 +61,17 @@ struct DefaultMapBase { using MapParamPackType = std::tuple; }; -template -struct DefaultMap; +template +struct DefaultMap : DefaultMapBase { + using BaseType = typename CollectionT::IndexType::DenseIndexType; + using BlockMapType = + ::vt::mapping::denseNDMapFn; + using RRMapType = + ::vt::mapping::denseNDRRMapFn; + using DefaultMapType = + ::vt::mapping::denseNDMapFn; + using MapType = DefaultMapType; +}; /* * Default mappings for Index1D: RR, Block, etc. From 25e57dfd2cd385b78a49d79ca436faf7b55c0d63 Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Mon, 18 Apr 2022 20:18:56 +0200 Subject: [PATCH 3/4] #1544: Tests: Reduce number of elements for 4 dim Collection in test_construct --- src/vt/topos/index/index.h | 5 ++--- src/vt/topos/mapping/dense/dense.impl.h | 7 +++++++ .../test_collection_construct_common.h | 18 ++++++++++++------ tests/unit/collection/test_construct.cc | 2 +- .../test_construct_no_idx.extended.cc | 1 - 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/vt/topos/index/index.h b/src/vt/topos/index/index.h index 4be63a31a5..dda8c096fa 100644 --- a/src/vt/topos/index/index.h +++ b/src/vt/topos/index/index.h @@ -60,7 +60,6 @@ template using Index1D = DenseIndexArray; template using Index2D = DenseIndexArray; template using Index3D = DenseIndexArray; template using IdxType = DenseIndexArray; -template using IndexND = DenseIndexArray; static_assert(IndexTraits>::is_index, "Does not conform"); static_assert(IndexTraits>::is_index, "Does not conform"); @@ -78,13 +77,13 @@ using Index1D = index::Index1D; using Index2D = index::Index2D; using Index3D = index::Index3D; template -using IndexND = index::IndexND; +using IndexND = index::IdxType; template using IdxType = index::IdxType; template using IdxType1D = index::Index1D; template using IdxType2D = index::Index2D; template using IdxType3D = index::Index3D; -template using IdxTypeND = index::IndexND; +template using IdxTypeND = index::IdxType; } // end namespace vt diff --git a/src/vt/topos/mapping/dense/dense.impl.h b/src/vt/topos/mapping/dense/dense.impl.h index 2d6d83b8c1..8c553ade18 100644 --- a/src/vt/topos/mapping/dense/dense.impl.h +++ b/src/vt/topos/mapping/dense/dense.impl.h @@ -93,6 +93,13 @@ NodeType dense3DRoundRobinMap(Idx3DPtr idx, Idx3DPtr max, NodeType nx) { return lin_idx % nx; } +template +NodeType denseNDRoundRobinMap(IdxNDPtr idx, IdxNDPtr max, NodeType nx) { + using IndexElmType = typename IdxTypeND::DenseIndexType; + auto const& lin_idx = linearizeDenseIndexColMajor(idx, max); + return lin_idx % nx; +} + // Default block mappings template NodeType dense1DBlockMap(Idx1DPtr idx, Idx1DPtr max, NodeType nx) { diff --git a/tests/unit/collection/test_collection_construct_common.h b/tests/unit/collection/test_collection_construct_common.h index 8aaed7304e..c597a0409c 100644 --- a/tests/unit/collection/test_collection_construct_common.h +++ b/tests/unit/collection/test_collection_construct_common.h @@ -122,11 +122,12 @@ void test_construct_1(std::string const& label) { auto const& this_node = theContext()->getNode(); if (this_node == 0) { - auto const& col_size = 32; + // 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(col_size); + auto rng = CreateRange(col_size); auto proxy = ConstructParams::construct(label, rng); - proxy.template broadcast< MsgType, ConstructHandlers::handler @@ -138,9 +139,14 @@ template void test_construct_distributed_1() { using MsgType = typename ColType::MsgType; - auto const& col_size = 32; - auto rng = CreateRange(col_size); - auto proxy = ConstructParams::constructCollective(rng, "test_construct_distributed_1"); + // 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(col_size); + auto proxy = ConstructParams::constructCollective( + rng, "test_construct_distributed_1" + ); proxy.template broadcast< MsgType, ConstructHandlers::handler diff --git a/tests/unit/collection/test_construct.cc b/tests/unit/collection/test_construct.cc index 31d60c9212..35595716cc 100644 --- a/tests/unit/collection/test_construct.cc +++ b/tests/unit/collection/test_construct.cc @@ -100,7 +100,7 @@ TEST_F(TestConstructLabel, test_labels) { auto const range = Index1D(num_nodes); std::string const label = "test_labels"; - auto proxy = makeCollection(label) + auto proxy = makeCollection(label) .bounds(range) .bulkInsert() .wait(); diff --git a/tests/unit/collection/test_construct_no_idx.extended.cc b/tests/unit/collection/test_construct_no_idx.extended.cc index 603afc12a0..6cec8eb1da 100644 --- a/tests/unit/collection/test_construct_no_idx.extended.cc +++ b/tests/unit/collection/test_construct_no_idx.extended.cc @@ -57,7 +57,6 @@ struct ColMsg; struct TestCol : Collection { using MsgType = ColMsg; }; - struct ColMsg : CollectionMessage {}; } /* end namespace multi_param_no_idx_ */ From c2f3118f1d7d908d721250c877c1935570d0f4ef Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Wed, 8 Jun 2022 01:07:56 +0200 Subject: [PATCH 4/4] #1544: Mapping: Remove redundant type aliases for N-dim indices --- src/vt/topos/index/index.h | 1 - src/vt/topos/mapping/dense/dense.h | 4 ++-- src/vt/topos/mapping/dense/dense.impl.h | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/vt/topos/index/index.h b/src/vt/topos/index/index.h index dda8c096fa..90056943d2 100644 --- a/src/vt/topos/index/index.h +++ b/src/vt/topos/index/index.h @@ -83,7 +83,6 @@ template using IdxType = index::IdxType; template using IdxType1D = index::Index1D; template using IdxType2D = index::Index2D; template using IdxType3D = index::Index3D; -template using IdxTypeND = index::IdxType; } // end namespace vt diff --git a/src/vt/topos/mapping/dense/dense.h b/src/vt/topos/mapping/dense/dense.h index f78c8dec3a..355065aa82 100644 --- a/src/vt/topos/mapping/dense/dense.h +++ b/src/vt/topos/mapping/dense/dense.h @@ -74,7 +74,7 @@ using IdxPtr = Index*; template using Idx1DPtr = IdxType1D*; template using Idx2DPtr = IdxType2D*; template using Idx3DPtr = IdxType3D*; -template using IdxNDPtr = vt::index::IdxType*; +template using IdxNDPtr = IdxType*; template NodeType denseBlockMap(IdxPtr idx, IdxPtr max_idx, NodeType nnodes); @@ -109,7 +109,7 @@ NodeType denseNDBlockMap( IdxNDPtr idx, IdxNDPtr max, NodeType n template using i1D = IdxType1D; template using i2D = IdxType2D; template using i3D = IdxType3D; -template using iND = IdxTypeND; +template using iND = IdxType; template using Adapt = MapFunctorAdapt; diff --git a/src/vt/topos/mapping/dense/dense.impl.h b/src/vt/topos/mapping/dense/dense.impl.h index 8c553ade18..3b8b43ee87 100644 --- a/src/vt/topos/mapping/dense/dense.impl.h +++ b/src/vt/topos/mapping/dense/dense.impl.h @@ -95,7 +95,7 @@ NodeType dense3DRoundRobinMap(Idx3DPtr idx, Idx3DPtr max, NodeType nx) { template NodeType denseNDRoundRobinMap(IdxNDPtr idx, IdxNDPtr max, NodeType nx) { - using IndexElmType = typename IdxTypeND::DenseIndexType; + using IndexElmType = typename IdxType::DenseIndexType; auto const& lin_idx = linearizeDenseIndexColMajor(idx, max); return lin_idx % nx; } @@ -118,7 +118,7 @@ NodeType dense3DBlockMap(Idx3DPtr idx, Idx3DPtr max, NodeType nx) { template NodeType denseNDBlockMap(IdxNDPtr idx, IdxNDPtr max, NodeType nx) { - return denseBlockMap, N>(idx, max, nx); + return denseBlockMap, N>(idx, max, nx); } template