Skip to content

Commit

Permalink
Remove step size constraints from performance measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Feb 7, 2025
1 parent bb63381 commit 7f28d28
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
28 changes: 17 additions & 11 deletions benchmarks/common/benchmarks/toy_detector_benchmark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ToyDetectorBenchmark : public benchmark::Fixture {
traccc::seedfinder_config seeding_cfg;
traccc::seedfilter_config filter_cfg;
traccc::spacepoint_grid_config grid_cfg{seeding_cfg};
traccc::finding_config finding_cfg = get_trk_finding_config();
traccc::finding_config finding_cfg;
traccc::fitting_config fitting_cfg;

static constexpr std::array<float, 2> phi_range{
Expand Down Expand Up @@ -81,6 +81,10 @@ class ToyDetectorBenchmark : public benchmark::Fixture {
"the simulation data."
<< std::endl;

// Apply correct propagation config
apply_propagation_config(finding_cfg);
apply_propagation_config(fitting_cfg);

// Use deterministic random number generator for testing
using uniform_gen_t = detray::detail::random_numbers<
traccc::scalar, std::uniform_real_distribution<traccc::scalar>>;
Expand Down Expand Up @@ -126,11 +130,11 @@ class ToyDetectorBenchmark : public benchmark::Fixture {
detray::muon<traccc::scalar>(), n_events, det, field,
std::move(generator), std::move(smearer_writer_cfg), full_path);

// Same propagation configuration for sim and reco
apply_propagation_config(sim.get_config());
// Set constrained step size to 1 mm
sim.get_config().propagation.stepping.step_constraint =
1.f * detray::unit<float>::mm;
// Otherwise same propagation configuration for sim and reco
sim.get_config().propagation = finding_cfg.propagation;

sim.run();

Expand All @@ -156,16 +160,18 @@ class ToyDetectorBenchmark : public benchmark::Fixture {
return toy_cfg;
}

traccc::finding_config get_trk_finding_config() const {

traccc::finding_config finding_cfg{};
template <typename config_t>
void apply_propagation_config(config_t& cfg) const {

// Configure the propagation for the toy detector
finding_cfg.propagation.navigation.search_window = {3, 3};
finding_cfg.propagation.navigation.overstep_tolerance =
-300.f * detray::unit<traccc::scalar>::um;

return finding_cfg;
cfg.propagation.navigation.search_window = {3, 3};
cfg.propagation.navigation.overstep_tolerance =
-300.f * detray::unit<float>::um;
cfg.propagation.navigation.min_mask_tolerance =
1e-5f * detray::unit<float>::mm;
cfg.propagation.navigation.max_mask_tolerance =
3.f * detray::unit<float>::mm;
cfg.propagation.navigation.mask_tolerance_scalor = 0.05f;
}

void SetUp(::benchmark::State& /*state*/) {
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/cuda/toy_detector_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
// VecMem include(s).
#include <vecmem/memory/cuda/device_memory_resource.hpp>
#include <vecmem/memory/cuda/host_memory_resource.hpp>
#include <vecmem/memory/cuda/managed_memory_resource.hpp>
#include <vecmem/memory/host_memory_resource.hpp>
#include <vecmem/utils/cuda/async_copy.hpp>
#include <vecmem/utils/cuda/copy.hpp>
Expand All @@ -56,7 +55,6 @@ BENCHMARK_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {
vecmem::cuda::host_memory_resource cuda_host_mr;
vecmem::cuda::device_memory_resource device_mr;
traccc::memory_resource mr{device_mr, &cuda_host_mr};
vecmem::cuda::managed_memory_resource mng_mr;

// Copy and stream
vecmem::copy host_copy;
Expand All @@ -65,9 +63,9 @@ BENCHMARK_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {
vecmem::cuda::async_copy async_copy{stream.cudaStream()};

// Read back detector file
host_detector_type det{mng_mr};
host_detector_type det{cuda_host_mr};
traccc::io::read_detector(
det, mng_mr, sim_dir + "toy_detector_geometry.json",
det, cuda_host_mr, sim_dir + "toy_detector_geometry.json",
sim_dir + "toy_detector_homogeneous_material.json",
sim_dir + "toy_detector_surface_grids.json");

Expand All @@ -84,8 +82,10 @@ BENCHMARK_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {
traccc::cuda::fitting_algorithm<device_fitter_type> device_fitting(
fitting_cfg, mr, async_copy, stream);

// Copy detector to device
auto det_fixed_buff = detray::get_buffer(det, device_mr, copy);
// Detector view object
auto det_view = detray::get_data(det);
auto det_view = detray::get_data(det_fixed_buff);

// D2H copy object
traccc::device::container_d2h_copy_alg<traccc::track_state_container_types>
Expand Down
5 changes: 3 additions & 2 deletions io/src/read_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
namespace {

/// Common implementation for constructing a detector from a set of input files
template <typename detector_t>
/// @tparam CAP Grid bin capacity 0: dynamic bin capacity
template <typename detector_t, unsigned int CAP = 0u>
void read_detector(detector_t& detector, vecmem::memory_resource& mr,
const std::string_view& geometry_file,
const std::string_view& material_file,
Expand All @@ -37,7 +38,7 @@ void read_detector(detector_t& detector, vecmem::memory_resource& mr,
}

// Read the detector.
auto det = detray::io::read_detector<detector_t>(mr, cfg);
auto det = detray::io::read_detector<detector_t, CAP>(mr, cfg);
detector = std::move(det.first);
}

Expand Down

0 comments on commit 7f28d28

Please sign in to comment.