Skip to content
Open
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
30 changes: 9 additions & 21 deletions test/source/kitgenbench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <sys/types.h>

#include <alpaka/core/Common.hpp>
#include <cstdint>
#include <string>

#include "nlohmann/json.hpp"
Expand Down Expand Up @@ -44,9 +45,9 @@ namespace setups {
typename TLogger = kitgenbench::setup::NoLogger,
typename TChecker = kitgenbench::setup::NoChecker>
struct InstructionDetails {
Aggregate<kitgenbench::setup::NoRecipe> recipes{};
Aggregate<kitgenbench::setup::NoLogger> loggers{};
Aggregate<kitgenbench::setup::NoChecker> checkers{};
Aggregate<TRecipe> recipes{};
Aggregate<TLogger> loggers{};
Aggregate<TChecker> checkers{};

auto sendTo([[maybe_unused]] auto const& device, [[maybe_unused]] auto& queue) {
// This is not exactly how it's supposed to be used (or at least it's not necessary). You
Expand Down Expand Up @@ -122,14 +123,15 @@ TEST_CASE("Single size malloc") {
namespace setups::mallocFreeManySize {

struct MallocFreeRecipe {
std::vector<std::uint32_t> sizes{};
const std::array<std::uint32_t, 9> sizes{16U, 256U, 1024U, 16U, 16U, 256U, 16U, 1024U, 1024U};
std::uint32_t currentIndex{0U};
void* currentPointer{nullptr};

ALPAKA_FN_ACC auto next([[maybe_unused]] const auto& acc) {
if (currentIndex >= sizes.size())
if (currentIndex >= sizes.size()) {
return std::make_tuple(kitgenbench::Actions::STOP,
std::span<std::byte>{static_cast<std::byte*>(nullptr), 0U});
}

if (currentPointer == nullptr) {
currentPointer = malloc(sizes[currentIndex]);
Expand All @@ -150,33 +152,19 @@ namespace setups::mallocFreeManySize {
nlohmann::json generateReport() { return {}; }
};

std::vector<std::uint32_t> ALLOCATION_SIZES
= {16U, 256U, 1024U, 16U, 16U, 256U, 16U, 1024U, 1024U};
auto makeInstructionDetails() { return InstructionDetails<MallocFreeRecipe>{}; }

namespace detail {
template <typename T> T unique(T const& values) {
// It's a pity but the following are algorithms and not "adaptors", so the pipe operator
// doesn't work.
T tmp = values;
std::ranges::sort(tmp);
const auto [new_end, old_end] = std::ranges::unique(tmp);
return {std::begin(tmp), new_end};
}
} // namespace detail

auto composeSetup() {
return composeSetup("mallocFreeManySize", makeExecutionDetails(), makeInstructionDetails(),
{{"what it does",
"This setup runs through a given vector of allocation sizes, allocating "
"and deallocating each size one after another."},
{"number of allocations", ALLOCATION_SIZES.size()},
{"available allocation sizes [bytes]", detail::unique(ALLOCATION_SIZES)}});
{"number of allocations", MallocFreeRecipe{}.sizes.size()}});
}

} // namespace setups::mallocFreeManySize

TEST_CASE("Malloc free many size") {
auto setup = setups::mallocFreeManySize::composeSetup();
auto benchmarkReports = runBenchmarks(setup);
auto benchmarkReports = kitgenbench::runBenchmarks(setup);
}
Loading