Skip to content

Commit

Permalink
Use mp11 directly in the unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Feb 22, 2023
1 parent 405eb12 commit 987c605
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 127 deletions.
9 changes: 6 additions & 3 deletions tests/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
#include <string>
#include <typeinfo>

// make boost::mp11 directly available in all testing code
using namespace boost::mp11; // NOLINT(google-global-names-in-headers)

// NOLINTNEXTLINE(google-runtime-int)
using SizeTypes = boost::mp11::mp_list<int, unsigned, long, unsigned long, long long, unsigned long long>;
static_assert(boost::mp11::mp_contains<SizeTypes, std::size_t>::value);
using SizeTypes = mp_list<int, unsigned, long, unsigned long, long long, unsigned long long>;
static_assert(mp_contains<SizeTypes, std::size_t>::value);

// clang-format off
namespace tag
Expand Down Expand Up @@ -195,7 +198,7 @@ struct ModulusMapping : TArrayExtents
using ArrayExtents = TArrayExtents;
using ArrayIndex = typename ArrayExtents::Index;
using RecordDim = TRecordDim;
static constexpr std::size_t blobCount = boost::mp11::mp_size<llama::FlatRecordDim<RecordDim>>::value;
static constexpr std::size_t blobCount = mp_size<llama::FlatRecordDim<RecordDim>>::value;

LLAMA_FN_HOST_ACC_INLINE
constexpr explicit ModulusMapping(ArrayExtents extents, RecordDim = {}) : ArrayExtents(extents)
Expand Down
2 changes: 1 addition & 1 deletion tests/computedprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace
using ArrayExtents = TArrayExtents;
using ArrayIndex = typename ArrayExtents::Index;
using RecordDim = TRecordDim;
static constexpr std::size_t blobCount = boost::mp11::mp_size<llama::FlatRecordDim<RecordDim>>::value;
static constexpr std::size_t blobCount = mp_size<llama::FlatRecordDim<RecordDim>>::value;

constexpr CompressedBoolMapping() = default;

Expand Down
35 changes: 17 additions & 18 deletions tests/copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace
}

// Do not test all combinations as this exlodes the unit test compile and runtime.
using AoSMappings = boost::mp11::mp_list<
using AoSMappings = mp_list<
llama::mapping::
AoS<ArrayExtents, RecordDim, llama::mapping::FieldAlignment::Pack, llama::mapping::LinearizeArrayDimsCpp>,
// llama::mapping::AoS<ArrayExtents, RecordDim, llama::mapping::FieldAlignment::Pack,
Expand All @@ -35,7 +35,7 @@ namespace
llama::mapping::FieldAlignment::Align,
llama::mapping::LinearizeArrayDimsFortran>>;

using OtherMappings = boost::mp11::mp_list<
using OtherMappings = mp_list<
llama::mapping::SoA<
ArrayExtents,
RecordDim,
Expand Down Expand Up @@ -65,27 +65,26 @@ namespace
// llama::mapping::AoSoA<ArrayExtents, RecordDim, 8, llama::mapping::LinearizeArrayDimsCpp>,
llama::mapping::AoSoA<ArrayExtents, RecordDim, 8, llama::mapping::LinearizeArrayDimsFortran>>;

using AllMappings = boost::mp11::mp_append<AoSMappings, OtherMappings>;
using AllMappings = mp_append<AoSMappings, OtherMappings>;

using AllMappingsProduct = boost::mp11::mp_product<boost::mp11::mp_list, AllMappings, AllMappings>;
using AllMappingsProduct = mp_product<mp_list, AllMappings, AllMappings>;

template<typename List>
using BothAreSoAOrHaveDifferentLinearizer = std::bool_constant<
(llama::mapping::isSoA<boost::mp11::mp_first<List>> && llama::mapping::isSoA<boost::mp11::mp_second<List>>)
(llama::mapping::isSoA<mp_first<List>> && llama::mapping::isSoA<mp_second<List>>)
|| !std::is_same_v<
typename boost::mp11::mp_first<List>::LinearizeArrayDimsFunctor,
typename boost::mp11::mp_second<List>::LinearizeArrayDimsFunctor>>;
typename mp_first<List>::LinearizeArrayDimsFunctor,
typename mp_second<List>::LinearizeArrayDimsFunctor>>;

using AoSoAMappingsProduct = boost::mp11::mp_remove_if<
boost::mp11::mp_product<boost::mp11::mp_list, OtherMappings, OtherMappings>,
BothAreSoAOrHaveDifferentLinearizer>;
using AoSoAMappingsProduct
= mp_remove_if<mp_product<mp_list, OtherMappings, OtherMappings>, BothAreSoAOrHaveDifferentLinearizer>;
} // namespace

// NOLINTNEXTLINE(cert-err58-cpp)
TEMPLATE_LIST_TEST_CASE("copy", "", AllMappingsProduct)
{
using SrcMapping = boost::mp11::mp_first<TestType>;
using DstMapping = boost::mp11::mp_second<TestType>;
using SrcMapping = mp_first<TestType>;
using DstMapping = mp_second<TestType>;
testCopy<SrcMapping, DstMapping>([](const auto& srcView, auto& dstView) { llama::copy(srcView, dstView); });
}

Expand All @@ -98,26 +97,26 @@ TEMPLATE_LIST_TEST_CASE("blobMemcpy", "", AllMappings)
// NOLINTNEXTLINE(cert-err58-cpp)
TEMPLATE_LIST_TEST_CASE("fieldWiseCopy", "", AllMappingsProduct)
{
using SrcMapping = boost::mp11::mp_first<TestType>;
using DstMapping = boost::mp11::mp_second<TestType>;
using SrcMapping = mp_first<TestType>;
using DstMapping = mp_second<TestType>;
testCopy<SrcMapping, DstMapping>([](const auto& srcView, auto& dstView)
{ llama::fieldWiseCopy(srcView, dstView); });
}

// NOLINTNEXTLINE(cert-err58-cpp)
TEMPLATE_LIST_TEST_CASE("aosoaCommonBlockCopy.readOpt", "", AoSoAMappingsProduct)
{
using SrcMapping = boost::mp11::mp_first<TestType>;
using DstMapping = boost::mp11::mp_second<TestType>;
using SrcMapping = mp_first<TestType>;
using DstMapping = mp_second<TestType>;
testCopy<SrcMapping, DstMapping>([](const auto& srcView, auto& dstView)
{ llama::aosoaCommonBlockCopy(srcView, dstView, true); });
}

// NOLINTNEXTLINE(cert-err58-cpp)
TEMPLATE_LIST_TEST_CASE("aosoaCommonBlockCopy.writeOpt", "", AoSoAMappingsProduct)
{
using SrcMapping = boost::mp11::mp_first<TestType>;
using DstMapping = boost::mp11::mp_second<TestType>;
using SrcMapping = mp_first<TestType>;
using DstMapping = mp_second<TestType>;
testCopy<SrcMapping, DstMapping>([](const auto& srcView, auto& dstView)
{ llama::aosoaCommonBlockCopy(srcView, dstView, false); });
}
24 changes: 11 additions & 13 deletions tests/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,9 @@ TEST_CASE("GetCoordFromTags")

TEST_CASE("GetCoordFromTags.List")
{
STATIC_REQUIRE(std::is_same_v<llama::GetCoordFromTags<Particle, boost::mp11::mp_list<>>, llama::RecordCoord<>>);
STATIC_REQUIRE(std::is_same_v<
llama::GetCoordFromTags<Particle, boost::mp11::mp_list<tag::Vel, tag::Z>>,
llama::RecordCoord<2, 2>>);
STATIC_REQUIRE(std::is_same_v<llama::GetCoordFromTags<Particle, mp_list<>>, llama::RecordCoord<>>);
STATIC_REQUIRE(
std::is_same_v<llama::GetCoordFromTags<Particle, mp_list<tag::Vel, tag::Z>>, llama::RecordCoord<2, 2>>);
}

TEST_CASE("GetCoordFromTags.RecordCoord")
Expand Down Expand Up @@ -243,10 +242,10 @@ TEST_CASE("GetType")
TEST_CASE("GetTags")
{
// clang-format off
STATIC_REQUIRE(std::is_same_v<llama::GetTags<Particle, llama::RecordCoord<0, 0>>, boost::mp11::mp_list<tag::Pos, tag::X >>);
STATIC_REQUIRE(std::is_same_v<llama::GetTags<Particle, llama::RecordCoord<0 >>, boost::mp11::mp_list<tag::Pos >>);
STATIC_REQUIRE(std::is_same_v<llama::GetTags<Particle, llama::RecordCoord< >>, boost::mp11::mp_list< >>);
STATIC_REQUIRE(std::is_same_v<llama::GetTags<Particle, llama::RecordCoord<2, 1>>, boost::mp11::mp_list<tag::Vel, tag::Y >>);
STATIC_REQUIRE(std::is_same_v<llama::GetTags<Particle, llama::RecordCoord<0, 0>>, mp_list<tag::Pos, tag::X >>);
STATIC_REQUIRE(std::is_same_v<llama::GetTags<Particle, llama::RecordCoord<0 >>, mp_list<tag::Pos >>);
STATIC_REQUIRE(std::is_same_v<llama::GetTags<Particle, llama::RecordCoord< >>, mp_list< >>);
STATIC_REQUIRE(std::is_same_v<llama::GetTags<Particle, llama::RecordCoord<2, 1>>, mp_list<tag::Vel, tag::Y >>);
// clang-format on
}

Expand All @@ -264,7 +263,7 @@ TEST_CASE("LeafRecordCoords")
{
STATIC_REQUIRE(std::is_same_v<
llama::LeafRecordCoords<Particle>,
boost::mp11::mp_list<
mp_list<
llama::RecordCoord<0, 0>,
llama::RecordCoord<0, 1>,
llama::RecordCoord<0, 2>,
Expand Down Expand Up @@ -331,10 +330,9 @@ TEST_CASE("hasSameTags")

TEST_CASE("FlatRecordDim")
{
STATIC_REQUIRE(
std::is_same_v<
llama::FlatRecordDim<Particle>,
boost::mp11::mp_list<double, double, double, float, double, double, double, bool, bool, bool, bool>>);
STATIC_REQUIRE(std::is_same_v<
llama::FlatRecordDim<Particle>,
mp_list<double, double, double, float, double, double, double, bool, bool, bool, bool>>);
}

TEST_CASE("flatRecordCoord")
Expand Down
2 changes: 1 addition & 1 deletion tests/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ TEST_CASE("dump.ParticleUnaligned.Split.Multilist.SoA.One")
dump(llama::mapping::Split<
ArrayExtents,
Particle,
boost::mp11::mp_list<llama::RecordCoord<0>, llama::RecordCoord<2>>,
mp_list<llama::RecordCoord<0>, llama::RecordCoord<2>>,
llama::mapping::BindSoA<>::fn,
llama::mapping::AlignedOne,
true>{extents});
Expand Down
6 changes: 3 additions & 3 deletions tests/mapping.BitPackedInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ TEMPLATE_TEST_CASE(
std::uint64_t)
{
using Integral = TestType;
boost::mp11::mp_for_each<boost::mp11::mp_list<std::uint32_t, std::uint64_t>>(
mp_for_each<mp_list<std::uint32_t, std::uint64_t>>(
[](auto si)
{
using StoredIntegral = decltype(si);
Expand Down Expand Up @@ -428,7 +428,7 @@ TEMPLATE_TEST_CASE(
std::uint64_t)
{
using Integral = TestType;
boost::mp11::mp_for_each<boost::mp11::mp_list<std::uint32_t, std::uint64_t>>(
mp_for_each<mp_list<std::uint32_t, std::uint64_t>>(
[](auto si)
{
using StoredIntegral = decltype(si);
Expand Down Expand Up @@ -469,7 +469,7 @@ TEMPLATE_TEST_CASE(
std::uint64_t)
{
using Integral = TestType;
boost::mp11::mp_for_each<boost::mp11::mp_list<std::uint32_t, std::uint64_t>>(
mp_for_each<mp_list<std::uint32_t, std::uint64_t>>(
[]<typename StoredIntegral>(StoredIntegral)
{
if constexpr(sizeof(StoredIntegral) >= sizeof(TestType))
Expand Down
4 changes: 1 addition & 3 deletions tests/mapping.Bytesplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ TEST_CASE("mapping.ByteSplit.ChangeType.SoA")
using Mapping = llama::mapping::Bytesplit<
llama::ArrayExtentsDynamic<std::size_t, 1>,
Vec3I,
llama::mapping::BindChangeType<
llama::mapping::BindSoA<>::fn,
boost::mp11::mp_list<boost::mp11::mp_list<std::byte, unsigned char>>>::fn>;
llama::mapping::BindChangeType<llama::mapping::BindSoA<>::fn, mp_list<mp_list<std::byte, unsigned char>>>::fn>;

STATIC_REQUIRE(std::is_same_v<Mapping::RecordDim, Vec3I>);
STATIC_REQUIRE(std::is_same_v<
Expand Down
17 changes: 7 additions & 10 deletions tests/mapping.ChangeType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TEST_CASE("mapping.ChangeType.AoS")
llama::ArrayExtents<std::size_t, 128>,
Vec3D,
llama::mapping::BindAoS<llama::mapping::FieldAlignment::Pack>::fn,
boost::mp11::mp_list<>>{{}};
mp_list<>>{{}};
CHECK(mapping.blobSize(0) == 3072);
auto view = llama::allocView(mapping);
iotaFillView(view);
Expand All @@ -24,7 +24,7 @@ TEST_CASE("mapping.ChangeType.AoS.doubleToFloat")
llama::ArrayExtents<std::size_t, 128>,
Vec3D,
llama::mapping::BindAoS<llama::mapping::FieldAlignment::Pack>::fn,
boost::mp11::mp_list<boost::mp11::mp_list<double, float>>>{{}};
mp_list<mp_list<double, float>>>{{}};
CHECK(mapping.blobSize(0) == 1536);
auto view = llama::allocView(mapping);
iotaFillView(view);
Expand All @@ -37,7 +37,7 @@ TEST_CASE("mapping.ChangeType.AoS.Coord1ToFloat")
llama::ArrayExtents<std::size_t, 128>,
Vec3D,
llama::mapping::BindAoS<llama::mapping::FieldAlignment::Pack>::fn,
boost::mp11::mp_list<boost::mp11::mp_list<llama::RecordCoord<1>, float>>>{{}};
mp_list<mp_list<llama::RecordCoord<1>, float>>>{{}};
CHECK(mapping.blobSize(0) == 2560);
auto view = llama::allocView(mapping);
iotaFillView(view);
Expand All @@ -50,8 +50,8 @@ TEST_CASE("mapping.ChangeType.AoS.CoordsAndTypes")
llama::ArrayExtents<std::size_t, 128>,
Vec3D,
llama::mapping::BindAoS<llama::mapping::FieldAlignment::Pack>::fn,
boost::mp11::
mp_list<boost::mp11::mp_list<double, float>, boost::mp11::mp_list<llama::RecordCoord<1>, double>>>{{}};

mp_list<mp_list<double, float>, mp_list<llama::RecordCoord<1>, double>>>{{}};
CHECK(mapping.blobSize(0) == 2048);
auto view = llama::allocView(mapping);
iotaFillView(view);
Expand All @@ -67,10 +67,7 @@ TEST_CASE("mapping.ChangeType.SoA.particle.types")
llama::ArrayExtents<std::size_t, 128>,
Particle,
llama::mapping::BindAoS<llama::mapping::FieldAlignment::Pack>::fn,
boost::mp11::mp_list<
boost::mp11::mp_list<double, float>,
boost::mp11::mp_list<float, std::int16_t>,
boost::mp11::mp_list<bool, std::int32_t>>>{{}};
mp_list<mp_list<double, float>, mp_list<float, std::int16_t>, mp_list<bool, std::int32_t>>>{{}};
CHECK(mapping.blobSize(0) == 128 * (6 * sizeof(float) + 1 * sizeof(std::int16_t) + 4 * sizeof(std::int32_t)));
auto view = llama::allocView(mapping);
iotaFillView(view);
Expand Down Expand Up @@ -106,7 +103,7 @@ TEST_CASE("mapping.ChangeType.ProxyRef.SwapAndAssign")
llama::ArrayExtents<std::size_t, 128>,
Vec3D,
llama::mapping::BindAoS<llama::mapping::FieldAlignment::Pack>::fn,
boost::mp11::mp_list<>>{{}};
mp_list<>>{{}};
auto view = llama::allocView(mapping);

view(0) = 1.0;
Expand Down
15 changes: 7 additions & 8 deletions tests/mapping.Projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TEST_CASE("mapping.Projection.AoS")
llama::ArrayExtents<std::size_t, 128>,
Vec3D,
llama::mapping::BindAoS<llama::mapping::FieldAlignment::Pack>::fn,
boost::mp11::mp_list<>>{{}};
mp_list<>>{{}};
CHECK(mapping.blobSize(0) == 3072);
auto view = llama::allocView(mapping);
iotaFillView(view);
Expand Down Expand Up @@ -40,7 +40,7 @@ TEST_CASE("mapping.Projection.AoS.DoubleToFloat")
llama::ArrayExtents<std::size_t, 128>,
Vec3D,
llama::mapping::BindAoS<llama::mapping::FieldAlignment::Pack>::fn,
boost::mp11::mp_list<boost::mp11::mp_list<double, DoubleToFloat>>>{{}};
mp_list<mp_list<double, DoubleToFloat>>>{{}};
CHECK(mapping.blobSize(0) == 1536);
auto view = llama::allocView(mapping);
iotaFillView(view);
Expand All @@ -53,7 +53,7 @@ TEST_CASE("mapping.Projection.ProxyRef.SwapAndAssign")
llama::ArrayExtents<int, 2>,
double,
llama::mapping::BindAoS<>::fn,
boost::mp11::mp_list<boost::mp11::mp_list<double, DoubleToFloat>>>{{}};
mp_list<mp_list<double, DoubleToFloat>>>{{}};
auto view = llama::allocView(mapping);

view(0) = 1.0;
Expand Down Expand Up @@ -89,7 +89,7 @@ TEST_CASE("mapping.Projection.AoS.Sqrt")
llama::ArrayExtents<std::size_t, 128>,
Vec3D,
llama::mapping::BindAoS<llama::mapping::FieldAlignment::Pack>::fn,
boost::mp11::mp_list<boost::mp11::mp_list<double, Sqrt>>>{{}};
mp_list<mp_list<double, Sqrt>>>{{}};
CHECK(mapping.blobSize(0) == 1536);
auto view = llama::allocView(mapping);
iotaFillView(view);
Expand All @@ -102,7 +102,7 @@ TEST_CASE("mapping.Projection.AoS.Coord1.Sqrt")
llama::ArrayExtents<std::size_t, 128>,
Vec3D,
llama::mapping::BindAoS<llama::mapping::FieldAlignment::Pack>::fn,
boost::mp11::mp_list<boost::mp11::mp_list<llama::RecordCoord<1>, Sqrt>>>{{}};
mp_list<mp_list<llama::RecordCoord<1>, Sqrt>>>{{}};
CHECK(mapping.blobSize(0) == 2560);
auto view = llama::allocView(mapping);
iotaFillView(view);
Expand All @@ -115,9 +115,8 @@ TEST_CASE("mapping.Projection.AoS.CoordsAndTypes")
llama::ArrayExtents<std::size_t, 128>,
Vec3D,
llama::mapping::BindAoS<llama::mapping::FieldAlignment::Pack>::fn,
boost::mp11::
mp_list<boost::mp11::mp_list<double, DoubleToFloat>, boost::mp11::mp_list<llama::RecordCoord<1>, Sqrt>>>{
{}};

mp_list<mp_list<double, DoubleToFloat>, mp_list<llama::RecordCoord<1>, Sqrt>>>{{}};
CHECK(mapping.blobSize(0) == 1536);
auto view = llama::allocView(mapping);
iotaFillView(view);
Expand Down

0 comments on commit 987c605

Please sign in to comment.