Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdePT integration #517

Merged
merged 4 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions include/llama/Array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ namespace llama
return &element[N];
}

LLAMA_FN_HOST_ACC_INLINE constexpr auto first() -> T&
{
return element[0];
}

LLAMA_FN_HOST_ACC_INLINE constexpr auto first() const -> const T&
{
return element[0];
}

LLAMA_FN_HOST_ACC_INLINE constexpr auto last() -> T&
{
return element[N - 1];
}

LLAMA_FN_HOST_ACC_INLINE constexpr auto last() const -> const T&
{
return element[N - 1];
}

template<typename IndexType>
LLAMA_FN_HOST_ACC_INLINE constexpr auto operator[](IndexType&& idx) -> T&
{
Expand Down
65 changes: 46 additions & 19 deletions include/llama/mapping/Trace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <atomic>
#include <cstdio>
#include <iomanip>
#include <iostream>

#ifndef __cpp_lib_atomic_ref
Expand Down Expand Up @@ -65,6 +66,11 @@ namespace llama::mapping
{
}

template<typename... Args>
LLAMA_FN_HOST_ACC_INLINE explicit Trace(Args&&... innerArgs) : Mapping(std::forward<Args>(innerArgs)...)
{
}

LLAMA_FN_HOST_ACC_INLINE
constexpr auto blobSize(size_type blobIndex) const -> size_type
{
Expand Down Expand Up @@ -136,38 +142,59 @@ namespace llama::mapping
template<typename Blobs>
LLAMA_FN_HOST_ACC_INLINE void printFieldHits(const Blobs& blobs) const
{
const auto& hits = fieldHits(blobs);
printFieldHits(fieldHits(blobs));
}

LLAMA_FN_HOST_ACC_INLINE void printFieldHits(const FieldHitsArray& hits) const
{
constexpr auto columnWidth = 10;
#ifdef __CUDA_ARCH__
if constexpr(MyCodeHandlesProxyReferences)
printf("Trace mapping, number of accesses:\n");
printf("%*s %*s %*s\n", columnWidth, "Field", columnWidth, "Reads", columnWidth, "Writes");
else
printf("Trace mapping, number of memory locations computed:\n");

for(int i = 0; i < hits.size(); i++)
if constexpr(MyCodeHandlesProxyReferences)
printf(
"\t%i:\tR: %lu\tW: %lu\n",
i,
static_cast<unsigned long>(hits[i].reads),
static_cast<unsigned long>(hits[i].writes));
else
printf("\t%i:\t%lu\n", i, static_cast<unsigned long>(hits[i].memLocsComputed));
printf("%*s %*s\n", columnWidth, "Field", columnWidth, "Mlocs comp");
forEachLeafCoord<RecordDim>(
[&](auto rc)
{
const size_type i = flatRecordCoord<RecordDim, decltype(rc)>;
if constexpr(MyCodeHandlesProxyReferences)
printf(
"%*i %*lu %*lu\n",
columnWidth,
i,
columnWidth,
static_cast<unsigned long>(hits[i].reads),
columnWidth,
static_cast<unsigned long>(hits[i].writes));
else
printf(
"%*i %*lu\n",
columnWidth,
i,
columnWidth,
static_cast<unsigned long>(hits[i].memLocsComputed));
});
#else
if constexpr(MyCodeHandlesProxyReferences)
std::cout << "Trace mapping, number of accesses:\n";
std::cout << std::left << std::setw(columnWidth) << "Field" << ' ' << std::right
<< std::setw(columnWidth) << "Reads" << ' ' << std::right << std::setw(columnWidth)
<< "Writes" << '\n';
else
std::cout << "Trace mapping, number of memory locations computed:\n";
std::cout << std::left << std::setw(columnWidth) << "Field" << ' ' << std::right
<< std::setw(columnWidth) << "Mlocs comp" << '\n';
forEachLeafCoord<RecordDim>(
[&](auto rc)
{
const size_type i = flatRecordCoord<RecordDim, decltype(rc)>;
if constexpr(MyCodeHandlesProxyReferences)
std::cout << '\t' << recordCoordTags<RecordDim>(rc) << ":\tR: " << hits[i].reads
<< "\tW: " << hits[i].writes << '\n';
std::cout << std::left << std::setw(columnWidth) << recordCoordTags<RecordDim>(rc) << ' '
<< std::right << std::setw(columnWidth) << hits[i].reads << ' ' << std::right
<< std::setw(columnWidth) << hits[i].writes << '\n';
else
std::cout << '\t' << recordCoordTags<RecordDim>(rc) << ":\t " << hits[i].memLocsComputed
<< '\n';
std::cout << std::left << std::setw(columnWidth) << recordCoordTags<RecordDim>(rc) << ' '
<< std::right << std::setw(columnWidth) << hits[i].memLocsComputed << '\n';
});
std::cout << std::internal;
#endif
}

Expand Down
18 changes: 18 additions & 0 deletions tests/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ TEST_CASE("Array.empty")
STATIC_REQUIRE(!llama::Array{1}.empty());
}

TEST_CASE("Array.first")
{
llama::Array a{1, 2, 3};
CHECK(a.first() == 1);
CHECK(std::as_const(a).first() == 1);
a.first() = 4;
CHECK(a == llama::Array{4, 2, 3});
}

TEST_CASE("Array.last")
{
llama::Array a{1, 2, 3};
CHECK(a.last() == 3);
CHECK(std::as_const(a).last() == 3);
a.last() = 4;
CHECK(a == llama::Array{1, 2, 4});
}

TEST_CASE("Array.operator<<")
{
auto put = [](auto array)
Expand Down
57 changes: 37 additions & 20 deletions tests/mapping.HeatmapTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ TEST_CASE("Heatmap.nbody")
llama::mapping::SingleBlobSoA<llama::ArrayExtents<std::size_t, N>, ParticleHeatmap>{});
}

TEST_CASE("Trace.ctor")
{
using AE = llama::ArrayExtentsDynamic<int, 1>;
using Mapping = llama::mapping::AoS<AE, ParticleHeatmap>;

// mapping ctor
{
Mapping mapping{AE{42}};
auto trace = llama::mapping::Trace<Mapping>{mapping};
CHECK(trace.extents() == AE{42});
}

// forwarding ctor
{
auto trace = llama::mapping::Trace<Mapping>{AE{42}};
CHECK(trace.extents() == AE{42});
}
}

TEMPLATE_LIST_TEST_CASE("Trace.nbody.mem_locs_computed", "", SizeTypes)
{
auto run = [&](auto mapping)
Expand All @@ -77,16 +96,15 @@ TEMPLATE_LIST_TEST_CASE("Trace.nbody.mem_locs_computed", "", SizeTypes)
std::streambuf* old = std::cout.rdbuf(buffer.rdbuf());
particles.mapping().printFieldHits(particles.storageBlobs);
std::cout.rdbuf(old);
CHECK(
buffer.str()
== "Trace mapping, number of memory locations computed:\n"
"\tPos.X:\t 10300\n"
"\tPos.Y:\t 10300\n"
"\tPos.Z:\t 10300\n"
"\tVel.X:\t 300\n"
"\tVel.Y:\t 300\n"
"\tVel.Z:\t 300\n"
"\tMass:\t 10200\n");
CHECK(buffer.str() == R"(Field Mlocs comp
Pos.X 10300
Pos.Y 10300
Pos.Z 10300
Vel.X 300
Vel.Y 300
Vel.Z 300
Mass 10200
)");
};
run(llama::mapping::AlignedAoS<llama::ArrayExtents<std::size_t, N>, ParticleHeatmap>{});
run(llama::mapping::SingleBlobSoA<llama::ArrayExtents<std::size_t, N>, ParticleHeatmap>{});
Expand Down Expand Up @@ -119,16 +137,15 @@ TEMPLATE_LIST_TEST_CASE("Trace.nbody.reads_writes", "", SizeTypes)
std::streambuf* old = std::cout.rdbuf(buffer.rdbuf());
particles.mapping().printFieldHits(particles.storageBlobs);
std::cout.rdbuf(old);
CHECK(
buffer.str()
== "Trace mapping, number of accesses:\n"
"\tPos.X:\tR: 10200\tW: 200\n"
"\tPos.Y:\tR: 10200\tW: 200\n"
"\tPos.Z:\tR: 10200\tW: 200\n"
"\tVel.X:\tR: 200\tW: 100\n"
"\tVel.Y:\tR: 200\tW: 100\n"
"\tVel.Z:\tR: 200\tW: 100\n"
"\tMass:\tR: 10100\tW: 100\n");
CHECK(buffer.str() == R"(Field Reads Writes
Pos.X 10200 200
Pos.Y 10200 200
Pos.Z 10200 200
Vel.X 200 100
Vel.Y 200 100
Vel.Z 200 100
Mass 10100 100
)");
};
run(llama::mapping::AlignedAoS<llama::ArrayExtents<std::size_t, N>, ParticleHeatmap>{});
run(llama::mapping::SingleBlobSoA<llama::ArrayExtents<std::size_t, N>, ParticleHeatmap>{});
Expand Down