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

feat: benchmark CLI tool #904

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
23 changes: 20 additions & 3 deletions core/include/detray/definitions/pdg_particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,37 @@ struct pdg_particle {
m_charge(static_cast<scalar_t>(charge)) {}

DETRAY_HOST_DEVICE
std::int32_t pdg_num() const { return m_pdg_num; }
constexpr std::int32_t pdg_num() const { return m_pdg_num; }

DETRAY_HOST_DEVICE
scalar_type mass() const { return m_mass; }
constexpr scalar_type mass() const { return m_mass; }

DETRAY_HOST_DEVICE
scalar_type charge() const { return m_charge; }
constexpr scalar_type charge() const { return m_charge; }

private:
std::int32_t m_pdg_num;
scalar_type m_mass;
scalar_type m_charge;
};

/// Apply the charge conjugation operator to a particle hypothesis @param ptc
template <typename scalar_t>
DETRAY_HOST_DEVICE constexpr pdg_particle<scalar_t> charge_conjugation(
const pdg_particle<scalar_t>& ptc) {
return (ptc.charge() != 0)
? detray::pdg_particle<scalar_t>{-ptc.pdg_num(), ptc.mass(),
-ptc.charge()}
: ptc;
}

/// @returns an updated particle hypothesis according to the track qop
template <typename scalar_t, typename track_t>
DETRAY_HOST_DEVICE constexpr pdg_particle<scalar_t> update_particle_hypothesis(
const pdg_particle<scalar_t>& ptc, const track_t& params) {
return (ptc.charge() * params.qop() > 0.f) ? ptc : charge_conjugation(ptc);
}

// Macro for declaring the particle
#define DETRAY_DECLARE_PARTICLE(PARTICLE_NAME, PDG_NUM, MASS, CHARGE) \
template <typename scalar_t> \
Expand Down
20 changes: 14 additions & 6 deletions core/include/detray/propagator/actor_chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class actor_chain {
public:
/// Types of the actors that are registered in the chain
using actor_list_type = tuple_t<actors_t...>;
// Tuple of actor states
using state_tuple = tuple_t<typename actors_t::state...>;
// Type of states tuple that is used in the propagator
using state = tuple_t<typename actors_t::state &...>;

Expand All @@ -53,8 +55,7 @@ class actor_chain {
return m_actors;
}

/// @returns a tuple of default constructible actor states and a
/// corresponding tuple of references
/// @returns a tuple of default constructible actor states
DETRAY_HOST_DEVICE
static constexpr auto make_actor_states() {
// Only possible if each state is default initializable
Expand All @@ -67,10 +68,10 @@ class actor_chain {
}

/// @returns a tuple of reference for every state in the tuple @param t
DETRAY_HOST_DEVICE static constexpr state make_ref_tuple(
DETRAY_HOST_DEVICE static constexpr state setup_actor_states(
tuple_t<typename actors_t::state...> &t) {
return make_ref_tuple(t,
std::make_index_sequence<sizeof...(actors_t)>{});
return setup_actor_states(
t, std::make_index_sequence<sizeof...(actors_t)>{});
}

private:
Expand Down Expand Up @@ -111,7 +112,7 @@ class actor_chain {

/// @returns a tuple of reference for every state in the tuple @param t
template <std::size_t... indices>
DETRAY_HOST_DEVICE static constexpr state make_ref_tuple(
DETRAY_HOST_DEVICE static constexpr state setup_actor_states(
tuple_t<typename actors_t::state...> &t,
std::index_sequence<indices...> /*ids*/) {
return detray::tie(detail::get<indices>(t)...);
Expand All @@ -126,6 +127,7 @@ template <>
class actor_chain<> {

public:
using state_tuple = dtuple<>;
/// Empty states replaces a real actor states container
struct state {};

Expand All @@ -138,6 +140,12 @@ class actor_chain<> {
propagator_state_t & /*p_state*/) const {
/*Do nothing*/
}

/// @returns an empty state
DETRAY_HOST_DEVICE static constexpr state setup_actor_states(
const state_tuple &) {
return {};
}
};

} // namespace detray
6 changes: 6 additions & 0 deletions core/include/detray/propagator/propagator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ struct propagator {
explicit constexpr propagator(const propagation::config &cfg)
: m_cfg{cfg} {}

/// @returns the actor chain
DETRAY_HOST_DEVICE
constexpr const actor_chain_t &get_actor_chain() const {
return run_actors;
}

/// Propagation that state aggregates a stepping and a navigation state. It
/// also keeps references to the actor states.
struct state {
Expand Down
35 changes: 35 additions & 0 deletions tests/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,47 @@
#
# Mozilla Public License Version 2.0

# Set the common C++ flags.
include(detray-compiler-options-cpp)
include_directories(
SYSTEM
$<TARGET_PROPERTY:covfie::core,INTERFACE_INCLUDE_DIRECTORIES>
)
include_directories(
SYSTEM
$<TARGET_PROPERTY:dfelibs::dfelibs,INTERFACE_INCLUDE_DIRECTORIES>
)

# Set up a common benchmark library.
file(
GLOB _detray_benchmarks_headers
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
"include/detray/benchmarks/*.hpp"
)

add_library(detray_benchmarks INTERFACE "${_detray_benchmarks_headers}")
add_library(detray::benchmarks ALIAS detray_benchmarks)

target_include_directories(
detray_benchmarks
INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include"
)

target_link_libraries(
detray_benchmarks
INTERFACE benchmark::benchmark vecmem::core detray::core detray::test_utils
)

unset(_detray_benchmarks_headers)

# Set up the host/cpu benchmarks.
if(DETRAY_BUILD_HOST)
add_subdirectory(cpu)
add_subdirectory(include/detray/benchmarks/cpu)
endif()

# Set up all of the "device" benchmarks.
if(DETRAY_BUILD_CUDA)
add_subdirectory(cuda)
add_subdirectory(include/detray/benchmarks/device)
endif()
19 changes: 15 additions & 4 deletions tests/benchmarks/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ message(STATUS "Building detray host benchmarks")
option(DETRAY_BENCHMARK_MULTITHREAD "Enable multithreaded benchmarks" OFF)
option(DETRAY_BENCHMARK_PRINTOUTS "Enable printouts in the benchmarks" OFF)

# Look for openMP, which is used for the CPU benchmark
# Look for openMP, which is used for the CPU propagation benchmark
find_package(OpenMP)

# Macro setting up the CPU benchmarks for a specific algebra plugin.
macro(detray_add_cpu_benchmark algebra)
# Build the benchmark executable.
detray_add_executable(benchmark_cpu_${algebra}
"benchmark_propagator.cpp"
"find_volume.cpp"
"grid.cpp"
"grid2.cpp"
"intersect_all.cpp"
"intersect_surfaces.cpp"
"masks.cpp"
LINK_LIBRARIES benchmark::benchmark benchmark::benchmark_main vecmem::core
LINK_LIBRARIES benchmark::benchmark benchmark::benchmark_main vecmem::core detray::benchmarks
detray::core_${algebra} detray::test_utils
)

Expand All @@ -48,9 +47,21 @@ macro(detray_add_cpu_benchmark algebra)
)
endif()

# Build the benchmark executable for the propagation
detray_add_executable( benchmark_cpu_propagation_${algebra}
"propagation.cpp"
LINK_LIBRARIES detray::benchmark_cpu benchmark::benchmark_main
vecmem::core detray::core_${algebra} detray::test_utils
)

target_compile_options(
detray_benchmark_cpu_propagation_${algebra}
PRIVATE "-march=native" "-ftree-vectorize"
)

if(OpenMP_CXX_FOUND)
target_link_libraries(
detray_benchmark_cpu_${algebra}
detray_benchmark_cpu_propagation_${algebra}
PRIVATE OpenMP::OpenMP_CXX
)
endif()
Expand Down
184 changes: 0 additions & 184 deletions tests/benchmarks/cpu/benchmark_propagator.cpp

This file was deleted.

Loading
Loading