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/utils/logging.hpp"
0011 
0012 // Detray benchmark include(s)
0013 #include "detray/benchmarks/types.hpp"
0014 
0015 // Detray test include(s)
0016 #include "detray/test/common/build_toy_detector.hpp"
0017 
0018 // VecMem include(s).
0019 #include <vecmem/memory/host_memory_resource.hpp>
0020 
0021 // Google include(s).
0022 #include <benchmark/benchmark.h>
0023 
0024 // System include(s).
0025 #include <iostream>
0026 
0027 // Use the detray:: namespace implicitly.
0028 using namespace detray;
0029 
0030 using bench_algebra = benchmarks::algebra;
0031 using scalar = benchmarks::scalar;
0032 
0033 // Benchmarks the cost of searching a volume by position
0034 void BM_FIND_VOLUMES(benchmark::State &state) {
0035   // This test is broken at the moment, don't run it.
0036   state.SkipWithError("Benchmark disabled for the toy geometry");
0037   return;
0038 
0039   // Detector configuration
0040   vecmem::host_memory_resource host_mr;
0041   toy_det_config<scalar> toy_cfg{};
0042   toy_cfg.n_edc_layers(7u);
0043   auto [d, names] = build_toy_detector<bench_algebra>(host_mr, toy_cfg);
0044 
0045   static const unsigned int itest = 10000u;
0046 
0047   constexpr auto vol_grid_idx{decltype(d)::accel::id::e_volume_default};
0048   auto volume_grid = d.accelerator_store().template get<vol_grid_idx>()[0];
0049 
0050   const auto &axis_r = volume_grid.get_axis<axis::label::e_r>();
0051   const auto &axis_z = volume_grid.get_axis<axis::label::e_z>();
0052 
0053   // Get a rough step size from irregular axes
0054   auto range0 = axis_r.span();
0055   auto range1 = axis_z.span();
0056 
0057   scalar step0{(range0[1] - range0[0]) / itest};
0058   scalar step1{(range1[1] - range1[0]) / itest};
0059 
0060   std::size_t successful{0u};
0061   std::size_t unsuccessful{0u};
0062 
0063   for (auto _ : state) {
0064     for (unsigned int i1 = 0u; i1 < itest; ++i1) {
0065       for (unsigned int i0 = 0u; i0 < itest; ++i0) {
0066         benchmarks::vector3 rz{static_cast<scalar>(i0) * step0,
0067                                static_cast<scalar>(0.f),
0068                                static_cast<scalar>(i1) * step1};
0069         const auto &v = d.volume(rz);
0070 
0071         benchmark::DoNotOptimize(successful);
0072         benchmark::DoNotOptimize(unsuccessful);
0073         if (v.index() == dindex_invalid) {
0074           ++unsuccessful;
0075         } else {
0076           ++successful;
0077         }
0078         benchmark::ClobberMemory();
0079       }
0080     }
0081   }
0082 
0083 #ifdef DETRAY_BENCHMARK_PRINTOUTS
0084   DETRAY_INFO_HOST("Successful   : " << successful);
0085   DETRAY_INFO_HOST("Unsuccessful : " << unsuccessful);
0086 #endif  // DETRAY_BENCHMARK_PRINTOUTS
0087 }
0088 
0089 BENCHMARK(BM_FIND_VOLUMES)
0090 #ifdef DETRAY_BENCHMARK_MULTITHREAD
0091     ->ThreadRange(1, benchmark::CPUInfo::Get().num_cpus)
0092 #endif
0093     ->Unit(benchmark::kMillisecond);