Skip to content

Commit fcd75b7

Browse files
authored
Constant Detector, main branch (2025.08.15.) (#1127)
* Use constant access in device code for the tracking geometry. * Make the device code use constant detector access. * Make the test and benchmark code produce constant detector views. * Make the example code produce constant detector views.
1 parent c8d55d8 commit fcd75b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+98
-53
lines changed

benchmarks/cuda/toy_detector_cuda.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ BENCHMARK_DEFINE_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {
6969
async_copy, stream);
7070

7171
// Copy detector to device
72-
auto det_buffer = detray::get_buffer(det, device_mr, copy);
72+
const auto det_buffer = detray::get_buffer(det, device_mr, copy);
7373
// Detector view object
7474
auto det_view = detray::get_data(det_buffer);
7575

core/include/traccc/geometry/detector.hpp

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** TRACCC library, part of the ACTS project (R&D line)
22
*
3-
* (c) 2024 CERN for the benefit of the ACTS project
3+
* (c) 2024-2025 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -16,7 +16,34 @@
1616
#include <detray/detectors/telescope_metadata.hpp>
1717
#include <detray/detectors/toy_metadata.hpp>
1818

19+
// VecMem include(s).
20+
#include <vecmem/containers/device_vector.hpp>
21+
22+
// System include(s).
23+
#include <type_traits>
24+
1925
namespace traccc {
26+
namespace details {
27+
28+
/// Type used instead of @c detray::device_container_types
29+
///
30+
/// This is meant as a template for how @c detray::device_container_types should
31+
/// change. So that it would correctly reflect that all data access on a device
32+
/// is constant. Not modifying the detector's payload.
33+
///
34+
/// Also note that with all the types present in @c detray::container_types
35+
/// it's really only @c vector_type that is actually used by @c detray::detector
36+
/// at this point.
37+
///
38+
struct device_detector_container_types {
39+
40+
/// Vector type to use in device code
41+
template <typename T>
42+
using vector_type = vecmem::device_vector<std::add_const_t<T>>;
43+
44+
}; // struct device_detector_container_types
45+
46+
} // namespace details
2047

2148
/// Base struct for the different detector types supported by the project.
2249
template <typename metadata_t>
@@ -28,13 +55,11 @@ struct detector {
2855
/// Host type of the detector.
2956
using host = detray::detector<metadata_type, detray::host_container_types>;
3057
/// Device type of the detector.
31-
using device =
32-
detray::detector<metadata_type, detray::device_container_types>;
58+
using device = detray::detector<metadata_type,
59+
details::device_detector_container_types>;
3360

3461
/// Non-const view of the detector.
35-
using view = typename host::view_type;
36-
/// Const view of the detector.
37-
using const_view = typename host::const_view_type;
62+
using view = typename host::const_view_type;
3863

3964
/// Buffer for a detector's data.
4065
using buffer = typename host::buffer_type;

device/alpaka/include/traccc/alpaka/seeding/spacepoint_formation_algorithm.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace traccc::alpaka {
3333
template <typename detector_t>
3434
class spacepoint_formation_algorithm
3535
: public algorithm<edm::spacepoint_collection::buffer(
36-
const typename detector_t::view_type&,
36+
const typename detector_t::const_view_type&,
3737
const measurement_collection_types::const_view&)>,
3838
public messaging {
3939

@@ -57,7 +57,7 @@ class spacepoint_formation_algorithm
5757
/// measurement
5858
///
5959
edm::spacepoint_collection::buffer operator()(
60-
const typename detector_t::view_type& det_view,
60+
const typename detector_t::const_view_type& det_view,
6161
const measurement_collection_types::const_view& measurements_view)
6262
const override;
6363

device/alpaka/src/finding/combinatorial_kalman_filter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ struct build_tracks {
198198
template <typename detector_t, typename bfield_t>
199199
edm::track_candidate_collection<default_algebra>::buffer
200200
combinatorial_kalman_filter(
201-
const typename detector_t::view_type& det, const bfield_t& field,
201+
const typename detector_t::const_view_type& det, const bfield_t& field,
202202
const measurement_collection_types::const_view& measurements,
203203
const bound_track_parameters_collection_types::const_view& seeds,
204204
const finding_config& config, const memory_resource& mr, vecmem::copy& copy,

device/alpaka/src/fitting/kalman_fitting.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ struct fit_backward {
113113
///
114114
template <typename detector_t, typename bfield_t>
115115
track_state_container_types::buffer kalman_fitting(
116-
const typename detector_t::view_type& det_view, const bfield_t& field_view,
116+
const typename detector_t::const_view_type& det_view,
117+
const bfield_t& field_view,
117118
const typename edm::track_candidate_container<
118119
typename detector_t::algebra_type>::const_view& track_candidates_view,
119120
const fitting_config& config, const memory_resource& mr, vecmem::copy& copy,

device/alpaka/src/seeding/spacepoint_formation_algorithm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ template <typename detector_t>
2222
struct FormSpacepointsKernel {
2323
template <typename TAcc>
2424
ALPAKA_FN_ACC void operator()(
25-
TAcc const& acc, typename detector_t::view_type det_view,
25+
TAcc const& acc, typename detector_t::const_view_type det_view,
2626
measurement_collection_types::const_view measurements_view,
2727
edm::spacepoint_collection::view spacepoints_view) const {
2828

@@ -43,7 +43,7 @@ spacepoint_formation_algorithm<detector_t>::spacepoint_formation_algorithm(
4343
template <typename detector_t>
4444
edm::spacepoint_collection::buffer
4545
spacepoint_formation_algorithm<detector_t>::operator()(
46-
const typename detector_t::view_type& det_view,
46+
const typename detector_t::const_view_type& det_view,
4747
const measurement_collection_types::const_view& measurements_view) const {
4848

4949
// Get a convenience variable for the queue that we'll be using.

device/common/include/traccc/finding/device/apply_interaction.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct apply_interaction_payload {
2626
/**
2727
* @brief View object describing the tracking detector
2828
*/
29-
typename detector_t::view_type det_data;
29+
typename detector_t::const_view_type det_data;
3030

3131
/**
3232
* @brief Total number of input parameters (including non-live ones)

device/common/include/traccc/finding/device/find_tracks.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct find_tracks_payload {
3434
/**
3535
* @brief View object to the tracking detector description
3636
*/
37-
typename detector_t::view_type det_data;
37+
typename detector_t::const_view_type det_data;
3838

3939
/**
4040
* @brief View object to the vector of bound track parameters

device/common/include/traccc/finding/device/propagate_to_next_surface.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct propagate_to_next_surface_payload {
2828
/**
2929
* @brief View object to the tracking detector description
3030
*/
31-
typename propagator_t::detector_type::view_type det_data;
31+
typename propagator_t::detector_type::const_view_type det_data;
3232

3333
/**
3434
* @brief View object to the magnetic field

device/common/include/traccc/fitting/device/fit.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct fit_payload {
2626
/**
2727
* @brief View object to the detector description
2828
*/
29-
typename fitter_t::detector_type::view_type det_data;
29+
typename fitter_t::detector_type::const_view_type det_data;
3030

3131
/**
3232
* @brief View object to the magnetic field description

0 commit comments

Comments
 (0)