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

Introduce traccc::silicon_detector_description, main branch (2024.06.21.) #627

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5cf0dad
Introduced "named detector types" to the project.
krasznaa Mar 15, 2024
e3e40d0
Starting with the re-write of the detector data handling.
krasznaa Mar 13, 2024
0ff8cd2
Starting the move to traccc::detector_description.
krasznaa Apr 30, 2024
44ecb8f
Moved to reading cells using the new detector description.
krasznaa Apr 30, 2024
03f418b
Saving a snapshot of the code.
krasznaa May 3, 2024
57cedbc
Made traccc::io compile against the new detector description.
krasznaa Jun 21, 2024
1ae4286
Made traccc_seq_example work with the new detector description.
krasznaa Jun 21, 2024
3b320b5
Made the host throughput executables work with the new detector descr…
krasznaa Jun 21, 2024
22786e5
Added module dimensionality info to the detector description.
krasznaa Jun 21, 2024
8b4d478
Made traccc::cuda and traccc::sycl build with traccc::detector_descri…
krasznaa Jun 21, 2024
c851bb2
Updated the cpu tests to traccc::detector_description.
krasznaa Jun 25, 2024
e887f96
Updated the CUDA tests to traccc::detector_description.
krasznaa Jun 26, 2024
ebf96ce
Made all host and CUDA example applications build.
krasznaa Jul 31, 2024
7a7100a
Made all the SYCL example and test code build.
krasznaa Aug 2, 2024
3584ef7
Updated the I/O code for the latest Detray version.
krasznaa Aug 2, 2024
e9e6d66
Made traccc_par_example work with the detector description.
krasznaa Aug 13, 2024
7f56865
Made all the Alpaka example and test code build.
krasznaa Aug 13, 2024
103bc21
Made the benchmarks work.
krasznaa Aug 15, 2024
649def5
Made the Kokkos example build.
krasznaa Aug 15, 2024
4ec38cf
Fixed the I/O test failures.
krasznaa Aug 16, 2024
aeccc21
traccc::detector_description -> traccc::silicon_detector_description.
krasznaa Aug 16, 2024
e379d16
Simplify the creation of detray::tracking_surface.
krasznaa Aug 16, 2024
f528eb5
DD member naming changes.
krasznaa Sep 14, 2024
719df46
Simplified the setting of the measurement dimensionality.
krasznaa Sep 16, 2024
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
32 changes: 10 additions & 22 deletions benchmarks/common/benchmarks/toy_detector_benchmark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@

class ToyDetectorBenchmark : public benchmark::Fixture {
public:
// VecMem memory resource(s)
vecmem::host_memory_resource host_mr;

static const int n_events = 100u;
static const int n_tracks = 5000u;

Expand Down Expand Up @@ -80,9 +83,6 @@ class ToyDetectorBenchmark : public benchmark::Fixture {
"the simulation data."
<< std::endl;

// VecMem memory resource(s)
vecmem::host_memory_resource host_mr;

// 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 @@ -139,7 +139,7 @@ class ToyDetectorBenchmark : public benchmark::Fixture {
.replace_files(true)
.write_grids(true)
.write_material(true)
.path(sim_dir);
.path(full_path);
detray::io::write_detector(det, name_map, writer_cfg);
}

Expand All @@ -157,30 +157,18 @@ class ToyDetectorBenchmark : public benchmark::Fixture {

void SetUp(::benchmark::State& /*state*/) {

// VecMem memory resource(s)
vecmem::host_memory_resource host_mr;

// Build the detector
auto [det, name_map] =
detray::build_toy_detector(host_mr, get_toy_config());

// Read geometry
traccc::geometry surface_transforms =
traccc::io::alt_read_geometry(det);

// Read events
for (std::size_t i_evt = 0; i_evt < n_events; i_evt++) {

// Read the hits from the relevant event file
traccc::io::spacepoint_reader_output readOut(&host_mr);
traccc::io::read_spacepoints(readOut, i_evt, sim_dir,
surface_transforms);
spacepoints.push_back(readOut.spacepoints);
traccc::spacepoint_collection_types::host sp{&host_mr};
traccc::io::read_spacepoints(sp, i_evt, sim_dir);
spacepoints.push_back(sp);

// Read measurements
traccc::io::measurement_reader_output meas_read_out(&host_mr);
traccc::io::read_measurements(meas_read_out, i_evt, sim_dir);
measurements.push_back(meas_read_out.measurements);
traccc::measurement_collection_types::host meas{&host_mr};
traccc::io::read_measurements(meas, i_evt, sim_dir);
measurements.push_back(meas);
}
}
};
24 changes: 11 additions & 13 deletions benchmarks/cpu/toy_detector_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* Mozilla Public License Version 2.0
*/

// Traccc core include(s).
#include "traccc/geometry/detector.hpp"

// Traccc algorithm include(s).
#include "traccc/finding/finding_algorithm.hpp"
#include "traccc/fitting/fitting_algorithm.hpp"
Expand All @@ -13,6 +16,7 @@

// Traccc IO include(s).
#include "traccc/io/event_map2.hpp"
#include "traccc/io/read_detector.hpp"
#include "traccc/io/read_geometry.hpp"
#include "traccc/io/read_measurements.hpp"
#include "traccc/io/read_spacepoints.hpp"
Expand Down Expand Up @@ -41,23 +45,17 @@ BENCHMARK_F(ToyDetectorBenchmark, CPU)(benchmark::State& state) {
detray::rk_stepper<b_field_t::view_t,
typename detector_type::algebra_type,
detray::constrained_step<>>;
using host_detector_type = detray::detector<detray::default_metadata>;
using host_detector_type = traccc::default_detector::host;
using host_navigator_type = detray::navigator<const host_detector_type>;
using host_fitter_type =
traccc::kalman_fitter<rk_stepper_type, host_navigator_type>;

// VecMem memory resource(s)
vecmem::host_memory_resource host_mr;

// Read back detector file
const std::string path = sim_dir;
detray::io::detector_reader_config reader_cfg{};
reader_cfg.add_file(path + "toy_detector_geometry.json")
.add_file(path + "toy_detector_homogeneous_material.json")
.add_file(path + "toy_detector_surface_grids.json");

auto [det, names] =
detray::io::read_detector<host_detector_type>(host_mr, reader_cfg);
host_detector_type det{host_mr};
traccc::io::read_detector(
det, host_mr, sim_dir + "toy_detector_geometry.json",
sim_dir + "toy_detector_homogeneous_material.json",
sim_dir + "toy_detector_surface_grids.json");

// B field
auto field = detray::bfield::create_const_field(B);
Expand Down Expand Up @@ -95,4 +93,4 @@ BENCHMARK_F(ToyDetectorBenchmark, CPU)(benchmark::State& state) {

state.counters["event_throughput_Hz"] = benchmark::Counter(
static_cast<double>(n_events), benchmark::Counter::kIsRate);
}
}
78 changes: 25 additions & 53 deletions benchmarks/cuda/toy_detector_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include "traccc/cuda/seeding/seeding_algorithm.hpp"
#include "traccc/cuda/seeding/track_params_estimation.hpp"
#include "traccc/device/container_d2h_copy_alg.hpp"
#include "traccc/geometry/detector.hpp"
#include "traccc/io/event_map2.hpp"
#include "traccc/io/read_detector.hpp"
#include "traccc/io/read_geometry.hpp"
#include "traccc/io/read_measurements.hpp"
#include "traccc/io/read_spacepoints.hpp"
Expand Down Expand Up @@ -45,16 +47,13 @@ BENCHMARK_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {
detray::rk_stepper<b_field_t::view_t,
typename detector_type::algebra_type,
detray::constrained_step<>>;
using host_detector_type = detray::detector<detray::default_metadata>;
using device_detector_type =
detray::detector<detray::default_metadata,
detray::device_container_types>;
using host_detector_type = traccc::default_detector::host;
using device_detector_type = traccc::default_detector::device;
using device_navigator_type = detray::navigator<const device_detector_type>;
using device_fitter_type =
traccc::kalman_fitter<rk_stepper_type, device_navigator_type>;

// Memory resources used by the application.
vecmem::host_memory_resource host_mr;
vecmem::cuda::host_memory_resource cuda_host_mr;
vecmem::cuda::device_memory_resource device_mr;
traccc::memory_resource mr{device_mr, &cuda_host_mr};
Expand All @@ -67,14 +66,11 @@ BENCHMARK_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {
vecmem::cuda::async_copy async_copy{stream.cudaStream()};

// Read back detector file
const std::string path = sim_dir;
detray::io::detector_reader_config reader_cfg{};
reader_cfg.add_file(path + "toy_detector_geometry.json")
.add_file(path + "toy_detector_homogeneous_material.json")
.add_file(path + "toy_detector_surface_grids.json");

auto [det, names] =
detray::io::read_detector<host_detector_type>(mng_mr, reader_cfg);
host_detector_type det{mng_mr};
traccc::io::read_detector(
det, mng_mr, sim_dir + "toy_detector_geometry.json",
sim_dir + "toy_detector_homogeneous_material.json",
sim_dir + "toy_detector_surface_grids.json");

// B field
auto field = detray::bfield::create_const_field(B);
Expand All @@ -93,7 +89,7 @@ BENCHMARK_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {

// D2H copy object
traccc::device::container_d2h_copy_alg<traccc::track_state_container_types>
track_state_d2h{mr, copy};
track_state_d2h{{device_mr, &host_mr}, copy};

for (auto _ : state) {

Expand All @@ -115,20 +111,6 @@ BENCHMARK_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {
auto& spacepoints_per_event = spacepoints[i_evt];
auto& measurements_per_event = measurements[i_evt];

// Initialize the containers
traccc::seed_collection_types::buffer seeds_cuda_buffer(0,
*(mr.host));
traccc::bound_track_parameters_collection_types::buffer
params_cuda_buffer(0, *mr.host);

traccc::track_candidate_container_types::buffer
track_candidates_cuda_buffer{{{}, *(mr.host)},
{{}, *(mr.host), mr.host}};

traccc::track_state_container_types::buffer
track_states_cuda_buffer{{{}, *(mr.host)},
{{}, *(mr.host), mr.host}};

// Copy the spacepoint and module data to the device.
traccc::spacepoint_collection_types::buffer spacepoints_cuda_buffer(
spacepoints_per_event.size(), mr.main);
Expand All @@ -142,23 +124,24 @@ BENCHMARK_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {
measurements_cuda_buffer);

// Run seeding
seeds_cuda_buffer = sa_cuda(spacepoints_cuda_buffer);
stream.synchronize();
traccc::seed_collection_types::buffer seeds_cuda_buffer =
sa_cuda(spacepoints_cuda_buffer);

// Run track parameter estimation
params_cuda_buffer =
tp_cuda(spacepoints_cuda_buffer, seeds_cuda_buffer, B);
stream.synchronize();
traccc::bound_track_parameters_collection_types::buffer
params_cuda_buffer =
tp_cuda(spacepoints_cuda_buffer, seeds_cuda_buffer, B);

// Run CKF track finding
track_candidates_cuda_buffer = device_finding(
det_view, field, measurements_cuda_buffer, params_cuda_buffer);
stream.synchronize();
traccc::track_candidate_container_types::buffer
track_candidates_cuda_buffer =
device_finding(det_view, field, measurements_cuda_buffer,
params_cuda_buffer);

// Run track fitting
track_states_cuda_buffer =
device_fitting(det_view, field, track_candidates_cuda_buffer);
stream.synchronize();
traccc::track_state_container_types::buffer
track_states_cuda_buffer = device_fitting(
det_view, field, track_candidates_cuda_buffer);

// Create a temporary buffer that will receive the device memory.
auto size = track_states_cuda_buffer.headers.size();
Expand All @@ -168,20 +151,9 @@ BENCHMARK_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {
capacities.begin(),
[](const auto& view) { return view.capacity(); });

traccc::track_state_container_types::buffer
track_states_host_buffer{{size, *(mr.host)},
{capacities, *(mr.host), mr.host}};
host_copy.setup(track_states_host_buffer.headers);
host_copy.setup(track_states_host_buffer.items);

// Copy the device container into this temporary host buffer.
vecmem::copy::event_type header_event =
copy(track_states_cuda_buffer.headers,
track_states_host_buffer.headers,
vecmem::copy::type::device_to_host);
vecmem::copy::event_type item_event = copy(
track_states_cuda_buffer.items, track_states_host_buffer.items,
vecmem::copy::type::device_to_host);
// Copy the track states back to the host.
traccc::track_state_container_types::host track_states_host =
track_state_d2h(track_states_cuda_buffer);
}
}

Expand Down
4 changes: 3 additions & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ traccc_add_library( traccc_core core TYPE SHARED
"include/traccc/edm/track_state.hpp"
"include/traccc/edm/cell.hpp"
# Geometry description.
"include/traccc/geometry/detector.hpp"
"include/traccc/geometry/module_map.hpp"
"include/traccc/geometry/geometry.hpp"
"include/traccc/geometry/pixel_data.hpp"
"include/traccc/geometry/silicon_detector_description.hpp"
# Utilities.
"include/traccc/utils/algorithm.hpp"
"include/traccc/utils/type_traits.hpp"
Expand Down Expand Up @@ -103,7 +105,7 @@ traccc_add_library( traccc_core core TYPE SHARED
"include/traccc/ambiguity_resolution/greedy_ambiguity_resolution_algorithm.hpp"
"src/ambiguity_resolution/greedy_ambiguity_resolution_algorithm.cpp" )
target_link_libraries( traccc_core
PUBLIC Eigen3::Eigen vecmem::core detray::core traccc::Thrust
PUBLIC Eigen3::Eigen vecmem::core detray::core detray::utils traccc::Thrust
traccc::algebra )

# Prevent Eigen from getting confused when building code for a
Expand Down
11 changes: 6 additions & 5 deletions core/include/traccc/clusterization/clusterization_algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "traccc/clusterization/sparse_ccl_algorithm.hpp"
#include "traccc/edm/cell.hpp"
#include "traccc/edm/measurement.hpp"
#include "traccc/geometry/silicon_detector_description.hpp"
#include "traccc/utils/algorithm.hpp"

// VecMem include(s).
Expand All @@ -31,7 +32,7 @@ namespace traccc::host {
class clusterization_algorithm
: public algorithm<measurement_collection_types::host(
const cell_collection_types::const_view&,
const cell_module_collection_types::const_view&)> {
const silicon_detector_description::const_view&)> {

public:
using config_type = std::monostate;
Expand All @@ -45,12 +46,12 @@ class clusterization_algorithm
/// Construct measurements for each detector module
///
/// @param cells_view The cells for every detector module in the event
/// @param modules_view A collection of detector modules
/// @param dd_view The detector description
/// @return The measurements reconstructed for every detector module
///
output_type operator()(const cell_collection_types::const_view& cells_view,
const cell_module_collection_types::const_view&
modules_view) const override;
output_type operator()(
const cell_collection_types::const_view& cells_view,
const silicon_detector_description::const_view& dd_view) const override;

private:
/// @name Sub-algorithms used by this algorithm
Expand Down
40 changes: 22 additions & 18 deletions core/include/traccc/clusterization/details/measurement_creation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,50 @@
#include "traccc/definitions/qualifiers.hpp"
#include "traccc/edm/cell.hpp"
#include "traccc/edm/measurement.hpp"
#include "traccc/geometry/silicon_detector_description.hpp"

namespace traccc::details {

/// Function used for retrieving the cell signal based on the module id
TRACCC_HOST_DEVICE
inline scalar signal_cell_modelling(scalar signal_in, const cell_module& mod);
inline scalar signal_cell_modelling(
scalar signal_in, const silicon_detector_description::const_device&);

/// Function for pixel segmentation
TRACCC_HOST_DEVICE
inline vector2 position_from_cell(const cell& cell, const cell_module& mod);
inline vector2 position_from_cell(
const cell& cell,
const silicon_detector_description::const_device& det_descr);

/// Function used for calculating the properties of the cluster during
/// measurement creation
///
/// @param[in] cluster The vector of cells describing the identified cluster
/// @param[in] mod The cell module
/// @param[out] mean The mean position of the cluster/measurement
/// @param[out] var The variation on the mean position of the
/// cluster/measurement
/// @param[in] cluster The vector of cells describing the identified cluster
/// @param[in] det_descr The detector description
/// @param[out] mean The mean position of the cluster/measurement
/// @param[out] var The variation on the mean position of the
/// cluster/measurement
/// @param[out] totalWeight The total weight of the cluster/measurement
///
TRACCC_HOST_DEVICE inline void calc_cluster_properties(
const cell_collection_types::const_device& cluster, const cell_module& mod,
point2& mean, point2& var, scalar& totalWeight);
const cell_collection_types::const_device& cluster,
const silicon_detector_description::const_device& det_descr, point2& mean,
point2& var, scalar& totalWeight);

/// Function used for calculating the properties of the cluster during
/// measurement creation
///
/// @param[out] measurements is the measurement collection where the measurement
/// object will be filled
/// @param[in] measurement_index is the index of the measurement object to fill
/// @param[in] cluster is the input cell vector
/// @param[in] mod is the cell module where the cluster belongs to
/// @param[in] mod_link is the module index
/// @param[out] measurements Measurement collection where the measurement is to
/// be filled
/// @param[in] index Index of the measurement object to fill
/// @param[in] cluster Cell vector describing the measurement's cluster
/// @param[in] det_descr Detector description
///
TRACCC_HOST_DEVICE inline void fill_measurement(
measurement_collection_types::device& measurements,
std::size_t measurement_index,
const cell_collection_types::const_device& cluster, const cell_module& mod,
const unsigned int mod_link);
measurement_collection_types::device::size_type index,
const cell_collection_types::const_device& cluster,
const silicon_detector_description::const_device& det_descr);

} // namespace traccc::details

Expand Down
Loading
Loading