Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:11

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 // Project include(s)
0010 #include "detray/navigation/caching_navigator.hpp"
0011 #include "detray/propagator/actors.hpp"
0012 #include "detray/propagator/rk_stepper.hpp"
0013 #include "detray/tracks/tracks.hpp"
0014 
0015 // Detray benchmark include(s)
0016 #include "detray/benchmarks/device/cuda/propagation_benchmark.hpp"
0017 #include "detray/benchmarks/types.hpp"
0018 
0019 // Detray test include(s)
0020 #include "detray/test/common/bfield.hpp"
0021 #include "detray/test/common/build_toy_detector.hpp"
0022 #include "detray/test/common/build_wire_chamber.hpp"
0023 #include "detray/test/common/track_generators.hpp"
0024 
0025 // Vecmem include(s)
0026 #include <vecmem/memory/cuda/device_memory_resource.hpp>
0027 #include <vecmem/memory/host_memory_resource.hpp>
0028 
0029 // System include(s)
0030 #include <iostream>
0031 #include <string>
0032 
0033 using namespace detray;
0034 
0035 int main(int argc, char** argv) {
0036   using toy_detector_t = detector<benchmarks::toy_metadata>;
0037   using bench_algebra = typename toy_detector_t::algebra_type;
0038   using scalar = dscalar<bench_algebra>;
0039   using vector3 = dvector3D<bench_algebra>;
0040 
0041   using free_track_parameters_t = free_track_parameters<bench_algebra>;
0042   using uniform_gen_t =
0043       detail::random_numbers<scalar, std::uniform_real_distribution<scalar>>;
0044   using track_generator_t =
0045       random_track_generator<free_track_parameters_t, uniform_gen_t>;
0046   using field_bknd_t = bfield::const_bknd_t<scalar>;
0047 
0048   vecmem::host_memory_resource host_mr;
0049   vecmem::cuda::device_memory_resource dev_mr;
0050 
0051   //
0052   // Configuration
0053   //
0054 
0055   // Constant magnetic field
0056   vector3 B{0.f, 0.f, 2.f * unit<scalar>::T};
0057 
0058   // Configure toy detector
0059   toy_det_config<scalar> toy_cfg{};
0060   toy_cfg.use_material_maps(false).n_brl_layers(4u).n_edc_layers(7u);
0061 
0062   std::clog << toy_cfg << std::endl;
0063 
0064   // Configure wire chamber
0065   wire_chamber_config<scalar> wire_chamber_cfg{};
0066   wire_chamber_cfg.half_z(500.f * unit<scalar>::mm);
0067 
0068   std::clog << wire_chamber_cfg << std::endl;
0069 
0070   // Configure propagation
0071   propagation::config prop_cfg{};
0072   prop_cfg.navigation.search_window = {3u, 3u};
0073   // No scattering in test tracks
0074   prop_cfg.navigation.estimate_scattering_noise = false;
0075 
0076   std::clog << prop_cfg << std::endl;
0077 
0078   // Benchmark config
0079   detray::benchmarks::benchmark_base::configuration bench_cfg{};
0080 
0081   std::vector<int> n_tracks{8 * 8,     16 * 16,   32 * 32,  64 * 64,
0082                             128 * 128, 256 * 256, 512 * 512};
0083 
0084   auto trk_cfg =
0085       detray::benchmarks::get_default_trk_gen_config<track_generator_t>(
0086           n_tracks);
0087 
0088   // Specific configuration for the random track generation
0089   trk_cfg.seed(detail::random_numbers<scalar>::default_seed());
0090 
0091   // Add additional tracks for warmup
0092   bench_cfg.n_warmup(static_cast<int>(
0093       std::ceil(0.1f * static_cast<float>(trk_cfg.n_tracks()))));
0094   bench_cfg.do_warmup(true);
0095 
0096   //
0097   // Prepare data
0098   //
0099   auto track_samples =
0100       detray::benchmarks::generate_track_samples<track_generator_t>(
0101           &host_mr, n_tracks, trk_cfg, true);
0102 
0103   const auto [toy_det, names] =
0104       build_toy_detector<bench_algebra>(host_mr, toy_cfg);
0105   const auto [wire_chamber, _] =
0106       build_wire_chamber<bench_algebra>(host_mr, wire_chamber_cfg);
0107 
0108   auto bfield = create_const_field<scalar>(B);
0109 
0110   dtuple<> empty_state{};
0111 
0112   actor::parameter_updater_state<bench_algebra> updater_state{prop_cfg};
0113   actor::pointwise_material_interactor<bench_algebra>::state interactor_state{};
0114 
0115   auto actor_states =
0116       detail::make_tuple<dtuple>(updater_state, interactor_state);
0117 
0118   //
0119   // Register benchmarks
0120   //
0121   std::clog << "Propagation Benchmarks\n"
0122             << "----------------------\n\n";
0123 
0124   prop_cfg.stepping.do_covariance_transport = true;
0125   detray::benchmarks::register_benchmark<
0126       detray::benchmarks::cuda_propagation_bm,
0127       detray::benchmarks::cuda_propagator_type<
0128           detray::benchmarks::toy_metadata, field_bknd_t,
0129           detray::benchmarks::default_chain, true>>(
0130       "TOY_DETECTOR_W_COV_TRANSPORT", bench_cfg, prop_cfg, toy_det, bfield,
0131       &actor_states, track_samples, n_tracks, &dev_mr);
0132 
0133   prop_cfg.stepping.do_covariance_transport = false;
0134   detray::benchmarks::register_benchmark<
0135       detray::benchmarks::cuda_propagation_bm,
0136       detray::benchmarks::cuda_propagator_type<
0137           detray::benchmarks::toy_metadata, field_bknd_t,
0138           detray::benchmarks::empty_chain, false>>(
0139       "TOY_DETECTOR", bench_cfg, prop_cfg, toy_det, bfield, &empty_state,
0140       track_samples, n_tracks, &dev_mr);
0141 
0142   prop_cfg.stepping.do_covariance_transport = true;
0143   detray::benchmarks::register_benchmark<
0144       detray::benchmarks::cuda_propagation_bm,
0145       detray::benchmarks::cuda_propagator_type<
0146           detray::benchmarks::wire_chamber_metadata, field_bknd_t,
0147           detray::benchmarks::default_chain, true>>(
0148       "WIRE_CHAMBER_W_COV_TRANSPORT", bench_cfg, prop_cfg, wire_chamber, bfield,
0149       &actor_states, track_samples, n_tracks, &dev_mr);
0150 
0151   prop_cfg.stepping.do_covariance_transport = false;
0152   detray::benchmarks::register_benchmark<
0153       detray::benchmarks::cuda_propagation_bm,
0154       detray::benchmarks::cuda_propagator_type<
0155           detray::benchmarks::wire_chamber_metadata, field_bknd_t,
0156           detray::benchmarks::empty_chain, false>>(
0157       "WIRE_CHAMBER", bench_cfg, prop_cfg, wire_chamber, bfield, &empty_state,
0158       track_samples, n_tracks, &dev_mr);
0159 
0160   // Run benchmarks
0161   ::benchmark::Initialize(&argc, argv);
0162   ::benchmark::RunSpecifiedBenchmarks();
0163   ::benchmark::Shutdown();
0164 }