Skip to content

Commit

Permalink
AoS will be aligned and SoA will be multiblob by default
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jun 30, 2021
1 parent efeaec3 commit e1dfd94
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 54 deletions.
6 changes: 3 additions & 3 deletions examples/alpaka/asyncblur/asyncblur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ struct BlurKernel
{
// Using SoA for the shared memory
constexpr auto sharedChunkSize = ElemsPerBlock + 2 * KernelSize;
const auto sharedMapping = llama::mapping::SoA(
typename View::ArrayDims{sharedChunkSize, sharedChunkSize},
typename View::RecordDim{});
const auto sharedMapping
= llama::mapping::SoA<typename View::ArrayDims, typename View::RecordDim, false>(
{sharedChunkSize, sharedChunkSize});
constexpr auto sharedMemSize = llama::sizeOf<PixelOnAcc> * sharedChunkSize * sharedChunkSize;
auto& sharedMem = alpaka::declareSharedVar<std::byte[sharedMemSize], __COUNTER__>(acc);
return llama::View(sharedMapping, llama::Array<std::byte*, 1>{&sharedMem[0]});
Expand Down
4 changes: 2 additions & 2 deletions examples/alpaka/nbody/nbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ struct UpdateKernel
if constexpr (MappingSM == AoS)
return llama::mapping::AoS{arrayDims, Particle{}};
if constexpr (MappingSM == SoA)
return llama::mapping::SoA{arrayDims, Particle{}};
return llama::mapping::SoA<decltype(arrayDims), Particle, false>{arrayDims};
if constexpr (MappingSM == AoSoA)
return llama::mapping::AoSoA<decltype(arrayDims), Particle, AOSOA_LANES>{arrayDims};
}();
Expand Down Expand Up @@ -268,7 +268,7 @@ void run(std::ostream& plotFile)
if constexpr (MappingGM == AoS)
return llama::mapping::AoS{arrayDims, Particle{}};
if constexpr (MappingGM == SoA)
return llama::mapping::SoA{arrayDims, Particle{}};
return llama::mapping::SoA<decltype(arrayDims), Particle, false>{arrayDims};
// if constexpr (MappingGM == 2)
// return llama::mapping::SoA<decltype(arrayDims), Particle, true>{arrayDims};
if constexpr (MappingGM == AoSoA)
Expand Down
5 changes: 2 additions & 3 deletions examples/alpaka/vectoradd/vectoradd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,13 @@ try
Queue queue(devAcc);

// LLAMA
const auto arrayDims = llama::ArrayDims{PROBLEM_SIZE};

const auto mapping = [&]
{
const auto arrayDims = llama::ArrayDims{PROBLEM_SIZE};
if constexpr (MAPPING == 0)
return llama::mapping::AoS{arrayDims, Vector{}};
if constexpr (MAPPING == 1)
return llama::mapping::SoA{arrayDims, Vector{}};
return llama::mapping::SoA<decltype(arrayDims), Vector, false>{arrayDims, Vector{}};
if constexpr (MAPPING == 2)
return llama::mapping::SoA<decltype(arrayDims), Vector, true>{arrayDims};
if constexpr (MAPPING == 3)
Expand Down
6 changes: 4 additions & 2 deletions examples/simpletest/simpletest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ try

// Printing dimensions information at runtime
std::cout << "Record dimension is " << addLineBreaks(type(Name())) << '\n';
std::cout << "AoS address of (0,100) <0,1>: "
<< llama::mapping::AoS<ArrayDims, Name>(adSize).blobNrAndOffset<0, 1>({0, 100}).offset << '\n';
std::cout << "AlignedAoS address of (0,100) <0,1>: "
<< llama::mapping::AlignedAoS<ArrayDims, Name>(adSize).blobNrAndOffset<0, 1>({0, 100}).offset << '\n';
std::cout << "PackedAoS address of (0,100) <0,1>: "
<< llama::mapping::PackedAoS<ArrayDims, Name>(adSize).blobNrAndOffset<0, 1>({0, 100}).offset << '\n';
std::cout << "SoA address of (0,100) <0,1>: "
<< llama::mapping::SoA<ArrayDims, Name>(adSize).blobNrAndOffset<0, 1>({0, 100}).offset << '\n';
std::cout << "sizeOf RecordDim: " << llama::sizeOf<Name> << '\n';
Expand Down
4 changes: 4 additions & 0 deletions include/llama/View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ namespace llama
using iterator = Iterator<View>;
using const_iterator = Iterator<const View>;

static_assert(
!std::is_reference_v<ArrayDims>,
"Mapping::ArrayDims must not be a reference. Are you using decltype(...) as mapping template argument?");

View() = default;

LLAMA_FN_HOST_ACC_INLINE
Expand Down
2 changes: 1 addition & 1 deletion include/llama/mapping/AoS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace llama::mapping
template <
typename T_ArrayDims,
typename T_RecordDim,
bool AlignAndPad = false,
bool AlignAndPad = true,
typename LinearizeArrayDimsFunctor = LinearizeArrayDimsCpp>
struct AoS
{
Expand Down
2 changes: 1 addition & 1 deletion include/llama/mapping/SoA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace llama::mapping
template <
typename T_ArrayDims,
typename T_RecordDim,
bool SeparateBuffers = false,
bool SeparateBuffers = true,
typename LinearizeArrayDimsFunctor = LinearizeArrayDimsCpp>
struct SoA
{
Expand Down
31 changes: 18 additions & 13 deletions tests/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@ namespace
}
} // namespace

TEST_CASE("dump.Particle.AoS")
TEST_CASE("dump.Particle.AoS_Aligned")
{
dump(llama::mapping::AoS{arrayDims, Particle{}});
dump(llama::mapping::AlignedAoS<ArrayDims, Particle>{arrayDims});
}

TEST_CASE("dump.Particle.SoA")
TEST_CASE("dump.Particle.AoS_Packed")
{
dump(llama::mapping::SoA{arrayDims, Particle{}});
dump(llama::mapping::PackedAoS<ArrayDims, Particle>{arrayDims});
}

TEST_CASE("dump.Particle.SoA_SB")
{
dump(llama::mapping::SingleBlobSoA<ArrayDims, Particle>{arrayDims});
}

TEST_CASE("dump.Particle.SoA_MB")
{
dump(llama::mapping::SoA<ArrayDims, Particle, true>{arrayDims});
dump(llama::mapping::MultiBlobSoA<ArrayDims, Particle>{arrayDims});
}

TEST_CASE("dump.Particle.AoSoA8")
Expand Down Expand Up @@ -104,22 +109,22 @@ TEST_CASE("dump.Particle.Split.AoSoA8.AoS.One.SoA")

TEST_CASE("dump.ParticleUnaligned.AoS")
{
dump(llama::mapping::AoS{arrayDims, ParticleUnaligned{}});
dump(llama::mapping::PackedAoS<ArrayDims, ParticleUnaligned>{arrayDims});
}

TEST_CASE("dump.ParticleUnaligned.AoS_Aligned")
{
dump(llama::mapping::AoS<ArrayDims, ParticleUnaligned, true>{arrayDims});
dump(llama::mapping::AlignedAoS<ArrayDims, ParticleUnaligned>{arrayDims});
}

TEST_CASE("dump.ParticleUnaligned.SoA")
TEST_CASE("dump.ParticleUnaligned.SoA_SB")
{
dump(llama::mapping::SoA{arrayDims, ParticleUnaligned{}});
dump(llama::mapping::SingleBlobSoA<ArrayDims, ParticleUnaligned>{arrayDims});
}

TEST_CASE("dump.ParticleUnaligned.SoA_MB")
{
dump(llama::mapping::SoA<ArrayDims, ParticleUnaligned, true>{arrayDims});
dump(llama::mapping::MultiBlobSoA<ArrayDims, ParticleUnaligned>{arrayDims});
}

TEST_CASE("dump.ParticleUnaligned.AoSoA8")
Expand Down Expand Up @@ -199,7 +204,7 @@ TEST_CASE("dump.ParticleUnaligned.Split.AoSoA8.SoA.One.AoS")

TEST_CASE("AoS.Aligned")
{
const auto mapping = llama::mapping::AoS<ArrayDims, ParticleUnaligned, true>{arrayDims};
const auto mapping = llama::mapping::AlignedAoS<ArrayDims, ParticleUnaligned>{arrayDims};
auto view = llama::allocView(mapping);
llama::forEachLeaf<ParticleUnaligned>(
[&](auto rc)
Expand Down Expand Up @@ -246,7 +251,7 @@ using ParticleAligned = llama::Record<
>;
// clang-format on

TEST_CASE("dump.ParticleAligned.AoS")
TEST_CASE("dump.ParticleAligned.PackedAoS")
{
dump(llama::mapping::AoS{arrayDims, ParticleAligned{}});
dump(llama::mapping::PackedAoS<ArrayDims, ParticleAligned>{arrayDims});
}
38 changes: 20 additions & 18 deletions tests/mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
#ifdef __cpp_lib_concepts
TEST_CASE("mapping.concepts")
{
STATIC_REQUIRE(llama::Mapping<llama::mapping::AoS<llama::ArrayDims<2>, Particle>>);
STATIC_REQUIRE(llama::Mapping<llama::mapping::SoA<llama::ArrayDims<2>, Particle>>);
STATIC_REQUIRE(llama::Mapping<llama::mapping::AlignedAoS<llama::ArrayDims<2>, Particle>>);
STATIC_REQUIRE(llama::Mapping<llama::mapping::PackedAoS<llama::ArrayDims<2>, Particle>>);
STATIC_REQUIRE(llama::Mapping<llama::mapping::SingleBlobSoA<llama::ArrayDims<2>, Particle>>);
STATIC_REQUIRE(llama::Mapping<llama::mapping::MultiBlobSoA<llama::ArrayDims<2>, Particle>>);
STATIC_REQUIRE(llama::Mapping<llama::mapping::AoSoA<llama::ArrayDims<2>, Particle, 8>>);
}
#endif

TEST_CASE("address.AoS")
TEST_CASE("address.AoS.Packed")
{
using ArrayDims = llama::ArrayDims<2>;
auto arrayDims = ArrayDims{16, 16};
auto mapping = llama::mapping::AoS<ArrayDims, Particle>{arrayDims};
auto mapping = llama::mapping::PackedAoS<ArrayDims, Particle>{arrayDims};

{
const auto coord = ArrayDims{0, 0};
Expand Down Expand Up @@ -65,12 +67,11 @@ TEST_CASE("address.AoS")
}
}

TEST_CASE("address.AoS.fortran")
TEST_CASE("address.AoS.Packed.fortran")
{
using ArrayDims = llama::ArrayDims<2>;
auto arrayDims = ArrayDims{16, 16};
auto mapping
= llama::mapping::AoS<ArrayDims, Particle, false, llama::mapping::LinearizeArrayDimsFortran>{arrayDims};
auto mapping = llama::mapping::PackedAoS<ArrayDims, Particle, llama::mapping::LinearizeArrayDimsFortran>{arrayDims};

{
const auto coord = ArrayDims{0, 0};
Expand Down Expand Up @@ -118,11 +119,11 @@ TEST_CASE("address.AoS.fortran")
}
}

TEST_CASE("address.AoS.morton")
TEST_CASE("address.AoS.Packed.morton")
{
using ArrayDims = llama::ArrayDims<2>;
auto arrayDims = ArrayDims{16, 16};
auto mapping = llama::mapping::AoS<ArrayDims, Particle, false, llama::mapping::LinearizeArrayDimsMorton>{arrayDims};
auto mapping = llama::mapping::PackedAoS<ArrayDims, Particle, llama::mapping::LinearizeArrayDimsMorton>{arrayDims};

{
const auto coord = ArrayDims{0, 0};
Expand Down Expand Up @@ -170,11 +171,11 @@ TEST_CASE("address.AoS.morton")
}
}

TEST_CASE("address.AoS.aligned")
TEST_CASE("address.AoS.Aligned")
{
using ArrayDims = llama::ArrayDims<2>;
auto arrayDims = ArrayDims{16, 16};
auto mapping = llama::mapping::AoS<ArrayDims, Particle, true>{arrayDims};
auto mapping = llama::mapping::AlignedAoS<ArrayDims, Particle>{arrayDims};

{
const auto coord = ArrayDims{0, 0};
Expand Down Expand Up @@ -222,11 +223,11 @@ TEST_CASE("address.AoS.aligned")
}
}

TEST_CASE("address.SoA")
TEST_CASE("address.SoA.SingleBlob")
{
using ArrayDims = llama::ArrayDims<2>;
auto arrayDims = ArrayDims{16, 16};
auto mapping = llama::mapping::SoA<ArrayDims, Particle>{arrayDims};
auto mapping = llama::mapping::SingleBlobSoA<ArrayDims, Particle>{arrayDims};

{
const auto coord = ArrayDims{0, 0};
Expand Down Expand Up @@ -274,12 +275,12 @@ TEST_CASE("address.SoA")
}
}

TEST_CASE("address.SoA.fortran")
TEST_CASE("address.SoA.SingleBlob.fortran")
{
using ArrayDims = llama::ArrayDims<2>;
auto arrayDims = ArrayDims{16, 16};
auto mapping
= llama::mapping::SoA<ArrayDims, Particle, false, llama::mapping::LinearizeArrayDimsFortran>{arrayDims};
= llama::mapping::SingleBlobSoA<ArrayDims, Particle, llama::mapping::LinearizeArrayDimsFortran>{arrayDims};

{
const auto coord = ArrayDims{0, 0};
Expand Down Expand Up @@ -327,15 +328,16 @@ TEST_CASE("address.SoA.fortran")
}
}

TEST_CASE("address.SoA.morton")
TEST_CASE("address.SoA.SingleBlob.morton")
{
struct Value
{
};

using ArrayDims = llama::ArrayDims<2>;
auto arrayDims = ArrayDims{16, 16};
auto mapping = llama::mapping::SoA<ArrayDims, Particle, false, llama::mapping::LinearizeArrayDimsMorton>{arrayDims};
auto mapping
= llama::mapping::SingleBlobSoA<ArrayDims, Particle, llama::mapping::LinearizeArrayDimsMorton>{arrayDims};

{
const auto coord = ArrayDims{0, 0};
Expand Down Expand Up @@ -387,7 +389,7 @@ TEST_CASE("address.SoA.MultiBlob")
{
using ArrayDims = llama::ArrayDims<2>;
auto arrayDims = ArrayDims{16, 16};
auto mapping = llama::mapping::SoA<ArrayDims, Particle, true>{arrayDims};
auto mapping = llama::mapping::MultiBlobSoA<ArrayDims, Particle>{arrayDims};

{
const auto coord = ArrayDims{0, 0};
Expand Down
15 changes: 11 additions & 4 deletions tests/proofs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@ using Particle = llama::Record<
>;
// clang-format on

TEST_CASE("mapsNonOverlappingly.AoS")
TEST_CASE("mapsNonOverlappingly.PackedAoS")
{
using ArrayDims = llama::ArrayDims<2>;
constexpr auto arrayDims = ArrayDims{32, 32};
constexpr auto mapping = llama::mapping::AoS<ArrayDims, Particle>{arrayDims};
constexpr auto mapping = llama::mapping::PackedAoS<llama::ArrayDims<2>, Particle>{{32, 32}};
#ifdef __cpp_constexpr_dynamic_alloc
STATIC_REQUIRE(llama::mapsNonOverlappingly(mapping));
#else
INFO("Test disabled because compiler does not support __cpp_constexpr_dynamic_alloc");
#endif
}

TEST_CASE("mapsNonOverlappingly.AlignedAoS")
{
constexpr auto mapping = llama::mapping::AlignedAoS<llama::ArrayDims<2>, Particle>{{32, 32}};
#ifdef __cpp_constexpr_dynamic_alloc
STATIC_REQUIRE(llama::mapsNonOverlappingly(mapping));
#else
Expand Down
4 changes: 2 additions & 2 deletions tests/splitmapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <llama/DumpMapping.hpp>
#include <llama/llama.hpp>

TEST_CASE("Split.SoA.AoS.1Buffer")
TEST_CASE("Split.SoA_SingleBlob.AoS_Packed.1Buffer")
{
using ArrayDims = llama::ArrayDims<2>;
auto arrayDims = ArrayDims{16, 16};
Expand All @@ -30,7 +30,7 @@ TEST_CASE("Split.SoA.AoS.1Buffer")
CHECK(mapping.blobNrAndOffset<3, 3>(coord) == llama::NrAndOffset{0, mapping1Size + 55});
}

TEST_CASE("Split.AoSoA8.AoS.One.SoA.4Buffer")
TEST_CASE("Split.AoSoA8.AoS_Packed.One.SoA_SingleBlob.4Buffer")
{
// split out momentum as AoSoA8, mass into a single value, position into AoS, and the flags into SoA, makes 4
// buffers
Expand Down
12 changes: 7 additions & 5 deletions tests/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ TEST_CASE("view.default-ctor")
using ArrayDims = llama::ArrayDims<2>;
constexpr ArrayDims viewSize{16, 16};

[[maybe_unused]] llama::View<llama::mapping::SoA<ArrayDims, RecordDim>, std::byte*> view1;
[[maybe_unused]] llama::View<llama::mapping::AoS<ArrayDims, RecordDim>, std::byte*> view2;
[[maybe_unused]] llama::View<llama::mapping::One<ArrayDims, RecordDim>, std::byte*> view3;
[[maybe_unused]] llama::View<llama::mapping::tree::Mapping<ArrayDims, RecordDim, llama::Tuple<>>, std::byte*> view4;
[[maybe_unused]] llama::View<llama::mapping::AlignedAoS<ArrayDims, RecordDim>, std::byte*> view1;
[[maybe_unused]] llama::View<llama::mapping::PackedAoS<ArrayDims, RecordDim>, std::byte*> view2;
[[maybe_unused]] llama::View<llama::mapping::SingleBlobSoA<ArrayDims, RecordDim>, std::byte*> view3;
[[maybe_unused]] llama::View<llama::mapping::MultiBlobSoA<ArrayDims, RecordDim>, std::byte*> view4;
[[maybe_unused]] llama::View<llama::mapping::One<ArrayDims, RecordDim>, std::byte*> view5;
[[maybe_unused]] llama::View<llama::mapping::tree::Mapping<ArrayDims, RecordDim, llama::Tuple<>>, std::byte*> view6;
}

TEST_CASE("view.move")
Expand Down Expand Up @@ -192,7 +194,7 @@ TEST_CASE("view.addresses")
using ArrayDims = llama::ArrayDims<2>;
ArrayDims arrayDims{16, 16};

using Mapping = llama::mapping::SoA<ArrayDims, Particle>;
using Mapping = llama::mapping::SingleBlobSoA<ArrayDims, Particle>;
Mapping mapping{arrayDims};
auto view = allocView(mapping);

Expand Down

0 comments on commit e1dfd94

Please sign in to comment.