Skip to content

Commit

Permalink
Add CPU benchmark cli tools
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Dec 18, 2024
1 parent 2e93b55 commit e4423f1
Show file tree
Hide file tree
Showing 9 changed files with 304 additions and 35 deletions.
2 changes: 1 addition & 1 deletion tests/benchmarks/cpu/propagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int main(int argc, char** argv) {
n_tracks);

// Specific configuration for the random track generation
trk_cfg.seed(42u);
trk_cfg.seed(detail::random_numbers<scalar>::default_seed());

// Add additional tracks for warmup
bench_cfg.n_warmup(static_cast<int>(
Expand Down
4 changes: 2 additions & 2 deletions tests/include/detray/test/common/detector_scan_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace detray::test {
template <typename track_generator_t>
struct detector_scan_config : public test::fixture_base<>::configuration {
using base_type = test::fixture_base<>;
using scalar_type = typename base_type::scalar_type;
using vector3_type = typename base_type::vector3_type;
using scalar_type = typename base_type::scalar;
using vector3_type = typename base_type::vector3;
using trk_gen_config_t = typename track_generator_t::configuration;

/// Name of the test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ namespace detray::test {
/// @brief Configuration for a detector scan test.
struct material_validation_config : public test::fixture_base<>::configuration {
using base_type = test::fixture_base<>;
using scalar_type = typename base_type::scalar_type;
using vector3_type = typename base_type::vector3_type;
using scalar_type = typename base_type::scalar;
using vector3_type = typename base_type::vector3;

/// Name of the test
std::string m_name{"material_validation"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace detray::test {
struct navigation_validation_config
: public test::fixture_base<>::configuration {
using base_type = test::fixture_base<>;
using scalar_type = typename base_type::scalar_type;
using vector3_type = typename base_type::vector3_type;
using scalar_type = typename base_type::scalar;
using vector3_type = typename base_type::vector3;

/// Name of the test
std::string m_name{"navigation_validation"};
Expand Down
1 change: 0 additions & 1 deletion tests/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ target_link_libraries(
INTERFACE
Boost::program_options
vecmem::core
detray::core_array
detray::test_common
detray::io
detray::csv_io
Expand Down
1 change: 1 addition & 0 deletions tests/tools/include/detray/options/propagation_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ void configure_options<detray::stepping::config>(

cfg.path_limit = path_limit * unit<float>::m;
}
cfg.do_covariance_transport = false;
if (vm.count("covariance_transport")) {
cfg.do_covariance_transport = true;
}
Expand Down
112 changes: 88 additions & 24 deletions tests/tools/include/detray/options/track_generator_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,22 @@ void add_uniform_track_gen_options(
boost::program_options::value<std::size_t>()->default_value(
cfg.eta_steps()),
"No. eta steps for particle gun")(
"random_seed",
boost::program_options::value<std::size_t>()->default_value(cfg.seed()),
"Seed for the random number generator")(
"eta_range",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Min, Max range of eta values for particle gun")(
"randomize_charge", "Randomly flip charge sign per track")(
"origin",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Coordintates for particle gun origin position [mm]")(
"p_tot",
boost::program_options::value<scalar_t>()->default_value(
static_cast<scalar_t>(cfg.m_p_mag) / unit<scalar_t>::GeV),
"Total momentum of the test particle [GeV]")(
"p_T",
boost::program_options::value<scalar_t>()->default_value(
static_cast<scalar_t>(cfg.m_p_mag) / unit<scalar_t>::GeV),
"Transverse momentum of the test particle [GeV]");
"p_range",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Total momentum [range] of the test particle [GeV]")(
"pT_range",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Transverse momentum [range] of the test particle [GeV]");
}

/// Add options for detray event generation
Expand All @@ -63,6 +64,7 @@ void configure_uniform_track_gen_options(

cfg.phi_steps(vm["phi_steps"].as<std::size_t>());
cfg.eta_steps(vm["eta_steps"].as<std::size_t>());
cfg.seed(vm["random_seed"].as<std::size_t>());
cfg.randomize_charge(vm.count("randomize_charge"));

if (vm.count("eta_range")) {
Expand All @@ -84,15 +86,47 @@ void configure_uniform_track_gen_options(
"Particle gun origin needs three arguments");
}
}
if (!vm["p_T"].defaulted() && !vm["p_tot"].defaulted()) {
if (vm.count("pT_range") && vm.count("p_range")) {
throw std::invalid_argument(
"Transverse and total momentum cannot be specified at the same "
"time");
}
if (!vm["p_T"].defaulted()) {
cfg.p_T(vm["p_T"].as<scalar_t>() * unit<scalar_t>::GeV);
if (vm.count("pT_range")) {
const auto pt_range = vm["pT_range"].as<std::vector<scalar_t>>();

// Default
if (pt_range.empty()) {
cfg.p_T(static_cast<scalar_t>(cfg.m_p_mag) * unit<scalar_t>::GeV);
} else if (pt_range.size() == 1u) {
cfg.p_T(pt_range[0] * unit<scalar_t>::GeV);
} else if (pt_range.size() == 2u) {
std::cout << "WARNING: Momentum range not possible with uniform "
"track generator: Using first value."
<< std::endl;
cfg.p_T(pt_range[0] * unit<scalar_t>::GeV);
} else {
throw std::invalid_argument(
"Wrong number of arguments for pT range: Need one argument or "
"range");
}
} else {
cfg.p_tot(vm["p_tot"].as<scalar_t>() * unit<scalar_t>::GeV);
const auto p_range = vm["p_range"].as<std::vector<scalar_t>>();

// Default
if (p_range.empty()) {
cfg.p_tot(static_cast<scalar_t>(cfg.m_p_mag) * unit<scalar_t>::GeV);
} else if (p_range.size() == 1u) {
cfg.p_tot(p_range[0] * unit<scalar_t>::GeV);
} else if (p_range.size() == 2u) {
std::cout << "WARNING: Momentum range not possible with uniform "
"track generator: Using first value."
<< std::endl;
cfg.p_tot(p_range[0] * unit<scalar_t>::GeV);
} else {
throw std::invalid_argument(
"Wrong number of arguments for p_tot range: Need one argument "
"or range");
}
}
}

Expand All @@ -107,6 +141,9 @@ void add_rnd_track_gen_options(
boost::program_options::value<std::size_t>()->default_value(
cfg.n_tracks()),
"No. of tracks for particle gun")(
"random_seed",
boost::program_options::value<std::size_t>()->default_value(cfg.seed()),
"Seed for the random number generator")(
"theta_range",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Min, Max range of theta values for particle gun")(
Expand All @@ -117,14 +154,12 @@ void add_rnd_track_gen_options(
"origin",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Coordintates for particle gun origin position")(
"p_tot",
boost::program_options::value<scalar_t>()->default_value(
static_cast<scalar_t>(cfg.mom_range()[0]) / unit<scalar_t>::GeV),
"Total momentum of the test particle [GeV]")(
"p_T",
boost::program_options::value<scalar_t>()->default_value(
static_cast<scalar_t>(cfg.mom_range()[0]) / unit<scalar_t>::GeV),
"Transverse momentum of the test particle [GeV]");
"p_range",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Total momentum [range] of the test particle [GeV]")(
"pT_range",
boost::program_options::value<std::vector<scalar_t>>()->multitoken(),
"Transverse momentum [range] of the test particle [GeV]");
}

/// Add options for detray event generation
Expand All @@ -134,6 +169,7 @@ void configure_rnd_track_gen_options(
random_track_generator_config<scalar_t> &cfg) {

cfg.n_tracks(vm["n_tracks"].as<std::size_t>());
cfg.seed(vm["random_seed"].as<std::size_t>());
cfg.randomize_charge(vm.count("randomize_charge"));

if (vm.count("eta_range") && vm.count("theta_range")) {
Expand Down Expand Up @@ -173,15 +209,43 @@ void configure_rnd_track_gen_options(
"Particle gun origin needs three arguments");
}
}
if (!vm["p_T"].defaulted() && !vm["p_tot"].defaulted()) {
if (vm.count("pT_range") && vm.count("p_range")) {
throw std::invalid_argument(
"Transverse and total momentum cannot be specified at the same "
"time");
}
if (!vm["p_T"].defaulted()) {
cfg.p_T(vm["p_T"].as<scalar_t>() * unit<scalar_t>::GeV);
if (vm.count("pT_range")) {
const auto pt_range = vm["pT_range"].as<std::vector<scalar_t>>();

// Default
if (pt_range.empty()) {
cfg.p_T(cfg.mom_range()[0] * unit<scalar_t>::GeV);
} else if (pt_range.size() == 1u) {
cfg.p_T(pt_range[0] * unit<scalar_t>::GeV);
} else if (pt_range.size() == 2u) {
cfg.pT_range(pt_range[0] * unit<scalar_t>::GeV,
pt_range[1] * unit<scalar_t>::GeV);
} else {
throw std::invalid_argument(
"Wrong number of arguments for pT range: Need one argument or "
"range");
}
} else {
cfg.p_tot(vm["p_tot"].as<scalar_t>() * unit<scalar_t>::GeV);
const auto p_range = vm["p_range"].as<std::vector<scalar_t>>();

// Default
if (p_range.empty()) {
cfg.p_tot(cfg.mom_range()[0] * unit<scalar_t>::GeV);
} else if (p_range.size() == 1u) {
cfg.p_tot(p_range[0] * unit<scalar_t>::GeV);
} else if (p_range.size() == 2u) {
cfg.mom_range(p_range[0] * unit<scalar_t>::GeV,
p_range[1] * unit<scalar_t>::GeV);
} else {
throw std::invalid_argument(
"Wrong number of arguments for p_tot range: Need one argument "
"or range");
}
}
}

Expand Down
49 changes: 46 additions & 3 deletions tests/tools/src/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,65 @@ detray_add_executable(generate_telescope_detector
# Build the visualization executable.
detray_add_executable(detector_display
"detector_display.cpp"
LINK_LIBRARIES Boost::program_options detray::tools
LINK_LIBRARIES Boost::program_options detray::core_array detray::tools
detray::svgtools
)

# Build the detector validation executable.
detray_add_executable(detector_validation
"detector_validation.cpp"
LINK_LIBRARIES GTest::gtest GTest::gtest_main
Boost::program_options detray::tools detray::test_utils
Boost::program_options detray::core_array detray::tools detray::test_utils
detray::svgtools
)

# Build the material validation executable.
detray_add_executable(material_validation
"material_validation.cpp"
LINK_LIBRARIES GTest::gtest GTest::gtest_main
Boost::program_options detray::tools detray::test_utils
Boost::program_options detray::core_array detray::tools detray::test_utils
detray::svgtools
)

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

# Build the propagation benchmark executable.
macro(detray_add_propagation_benchmark algebra)
detray_add_executable(propagation_benchmark_${algebra}
"propagation_benchmark.cpp"
LINK_LIBRARIES Boost::program_options benchmark::benchmark benchmark::benchmark_main vecmem::core detray::core_${algebra} detray::benchmarks detray::benchmark_cpu detray::tools detray::detectors
)

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

if(OpenMP_CXX_FOUND)
target_link_libraries(
detray_propagation_benchmark_${algebra}
PRIVATE OpenMP::OpenMP_CXX
)
endif()
endmacro()

# Build the array benchmark.
detray_add_propagation_benchmark( array )

# Build the Eigen benchmark executable.
if(DETRAY_EIGEN_PLUGIN)
detray_add_propagation_benchmark( eigen )
endif()

# Build the SMatrix benchmark executable.
if(DETRAY_SMATRIX_PLUGIN)
detray_add_propagation_benchmark( smatrix )
endif()

# Build the Vc benchmark executable.
if(DETRAY_VC_AOS_PLUGIN)
detray_add_propagation_benchmark( vc_aos )
endif()
endif()
Loading

0 comments on commit e4423f1

Please sign in to comment.