Skip to content

Commit

Permalink
Add a compile time benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Nov 16, 2023
1 parent 31fb36d commit b7f6a7b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ if (LLAMA_BUILD_EXAMPLES)
add_subdirectory("examples/memmap")
add_subdirectory("examples/stream")
add_subdirectory("examples/falsesharing")
add_subdirectory("examples/comptime")

# alpaka examples
find_package(alpaka 1.0)
Expand Down
18 changes: 18 additions & 0 deletions examples/comptime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 Bernhard Manfred Gruber
# SPDX-License-Identifier: LGPL-3.0-or-later

cmake_minimum_required (VERSION 3.18.3)
project(llama-comptime CXX)

set(LLAMA_COMPTIME_RECORD_DIM_SIZE 20 CACHE STRING "comptime example record dimension size")

if (NOT TARGET llama::llama)
find_package(llama REQUIRED)
endif()
add_executable(${PROJECT_NAME} comptime.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE llama::llama)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DLLAMA_COMPTIME_RECORD_DIM_SIZE=${LLAMA_COMPTIME_RECORD_DIM_SIZE})

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
target_compile_options(${PROJECT_NAME} PRIVATE -fbracket-depth=1500)
endif()
8 changes: 8 additions & 0 deletions examples/comptime/benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# the record dim has 1095 entries
for i in {0..1000..20}; do
cmake -DLLAMA_COMPTIME_RECORD_DIM_SIZE=$i .. > /dev/null 2>&1
s=$(\time -f "%e" make llama-comptime 2>&1 > /dev/null)
echo $i $s
done
38 changes: 38 additions & 0 deletions examples/comptime/comptime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2023 Bernhard Manfred Gruber
// SPDX-License-Identifier: LGPL-3.0-or-later

#ifndef LLAMA_COMPTIME_RECORD_DIM_SIZE
# define LLAMA_COMPTIME_RECORD_DIM_SIZE 20
#endif

#include "../common/ttjet_13tev_june2019.hpp"

#include <llama/llama.hpp>

using RecordDim = boost::mp11::mp_take_c<Event, LLAMA_COMPTIME_RECORD_DIM_SIZE>;

auto main() -> int
try
{
constexpr auto extents = llama::ArrayExtents{1024 * 1024};
using ArrayExtents = std::remove_const_t<decltype(extents)>;
// const auto packedAoSMapping = llama::mapping::PackedAoS<ArrayExtents, RecordDim>{extents};
const auto alignedAoSMapping = llama::mapping::AlignedAoS<ArrayExtents, RecordDim>{extents};
// const auto multiBlobSoAMapping = llama::mapping::MultiBlobSoA<ArrayExtents, RecordDim>{extents};
// const auto aosoa8Mapping = llama::mapping::AoSoA<ArrayExtents, RecordDim, 8>{extents};
// const auto aosoa32Mapping = llama::mapping::AoSoA<ArrayExtents, RecordDim, 32>{extents};
// const auto aosoa64Mapping = llama::mapping::AoSoA<ArrayExtents, RecordDim, 64>{extents};

auto view = llama::allocViewUninitialized(alignedAoSMapping);
llama::forEachLeafCoord<RecordDim>(
[&](auto coord)
{
using Type = llama::GetType<Event, decltype(coord)>;
for(std::size_t i = 0; i < extents[0]; i++)
view(i)(coord) = Type{};
});
}
catch(const std::exception& e)
{
std::cerr << "Exception: " << e.what() << '\n';
}

0 comments on commit b7f6a7b

Please sign in to comment.