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

Update to detray version v0.74.2 #696

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 4 additions & 13 deletions benchmarks/cuda/toy_detector_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,23 +150,14 @@ BENCHMARK_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {
tp_cuda(spacepoints_cuda_buffer, seeds_cuda_buffer, B);
stream.synchronize();

// Navigation buffer
auto navigation_buffer = detray::create_candidates_buffer(
det,
device_finding.get_config().navigation_buffer_size_scaler *
copy.get_size(seeds_cuda_buffer),
mr.main, mr.host);

// Run CKF track finding
track_candidates_cuda_buffer =
device_finding(det_view, field, navigation_buffer,
measurements_cuda_buffer, params_cuda_buffer);
track_candidates_cuda_buffer = device_finding(
det_view, field, measurements_cuda_buffer, params_cuda_buffer);
stream.synchronize();

// Run track fitting
track_states_cuda_buffer =
device_fitting(det_view, field, navigation_buffer,
track_candidates_cuda_buffer);
device_fitting(det_view, field, track_candidates_cuda_buffer);
stream.synchronize();

// Create a temporary buffer that will receive the device memory.
Expand Down Expand Up @@ -196,4 +187,4 @@ BENCHMARK_F(ToyDetectorBenchmark, CUDA)(benchmark::State& state) {

state.counters["event_throughput_Hz"] = benchmark::Counter(
static_cast<double>(n_events), benchmark::Counter::kIsRate);
}
}
15 changes: 5 additions & 10 deletions core/include/traccc/finding/finding_algorithm.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
* Material interaction
*************************/

// Get intersection at surface
// Get surface corresponding to bound params
const detray::tracking_surface sf{det, in_param.surface_link()};

const cxt_t ctx{};
Expand Down Expand Up @@ -180,14 +180,12 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
break;
}

bound_track_parameters bound_param(in_param.surface_link(),
in_param.vector(),
in_param.covariance());
const auto& meas = measurements[item_id];

track_state<algebra_type> trk_state(meas);

// Run the Kalman update
// Run the Kalman update on a copy of the track parameters
bound_track_parameters bound_param(in_param);
sf.template visit_mask<gain_matrix_updater<algebra_type>>(
trk_state, bound_param);

Expand Down Expand Up @@ -218,10 +216,7 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
orig_param_id,
skip_counter + 1});

bound_track_parameters bound_param(in_param.surface_link(),
in_param.vector(),
in_param.covariance());
updated_params.push_back(bound_param);
updated_params.push_back(in_param);
n_branches++;
}
}
Expand Down Expand Up @@ -272,7 +267,7 @@ finding_algorithm<stepper_t, navigator_t>::operator()(

// Propagate to the next surface
propagator.propagate_sync(propagation,
std::tie(s0, s1, s2, s3, s4));
detray::tie(s0, s1, s2, s3, s4));

// If a surface found, add the parameter for the next
// step
Expand Down
5 changes: 0 additions & 5 deletions core/include/traccc/finding/finding_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ struct finding_config {
****************************/
/// The number of measurements to be iterated per thread
unsigned int n_measurements_per_thread = 8;

/// Max number of candidates per seed used for navigation buffer creation
/// @NOTE: This is supposed to be larger than (at least equal to)
/// max_num_branches_per_seed
unsigned int navigation_buffer_size_scaler = 20;
};

} // namespace traccc
34 changes: 14 additions & 20 deletions core/include/traccc/fitting/kalman_filter/kalman_fitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ class kalman_fitter {

// vector type
template <typename T>
using vector_type = typename navigator_t::template vector_type<T>;

// navigator candidate type
using intersection_type = typename navigator_t::intersection_type;
using vector_type = typename detector_type::template vector_type<T>;

/// Configuration type
using config_type = fitting_config;
Expand All @@ -67,7 +64,7 @@ class kalman_fitter {
using resetter = detray::parameter_resetter<algebra_type>;

using actor_chain_type =
detray::actor_chain<std::tuple, aborter, transporter, interactor,
detray::actor_chain<detray::dtuple, aborter, transporter, interactor,
fit_actor, resetter, kalman_step_aborter>;

// Propagator type
Expand Down Expand Up @@ -102,9 +99,9 @@ class kalman_fitter {
/// @return the actor chain state
TRACCC_HOST_DEVICE
typename actor_chain_type::state operator()() {
return std::tie(m_aborter_state, m_transporter_state,
m_interactor_state, m_fit_actor_state,
m_resetter_state, m_step_aborter_state);
return detray::tie(m_aborter_state, m_transporter_state,
m_interactor_state, m_fit_actor_state,
m_resetter_state, m_step_aborter_state);
}

/// Individual actor states
Expand All @@ -126,9 +123,8 @@ class kalman_fitter {
/// @param seed_params seed track parameter
/// @param fitter_state the state of kalman fitter
template <typename seed_parameters_t>
TRACCC_HOST_DEVICE void fit(
const seed_parameters_t& seed_params, state& fitter_state,
vector_type<intersection_type>&& nav_candidates = {}) {
TRACCC_HOST_DEVICE void fit(const seed_parameters_t& seed_params,
state& fitter_state) {

// Run the kalman filtering for a given number of iterations
for (std::size_t i = 0; i < m_cfg.n_iterations; i++) {
Expand All @@ -137,16 +133,15 @@ class kalman_fitter {
fitter_state.m_fit_actor_state.reset();

if (i == 0) {
filter(seed_params, fitter_state, std::move(nav_candidates));
filter(seed_params, fitter_state);
}
// From the second iteration, seed parameter is the smoothed track
// parameter at the first surface
else {
const auto& new_seed_params =
fitter_state.m_fit_actor_state.m_track_states[0].smoothed();

filter(new_seed_params, fitter_state,
std::move(nav_candidates));
filter(new_seed_params, fitter_state);
}
}
}
Expand All @@ -158,9 +153,8 @@ class kalman_fitter {
/// @param seed_params seed track parameter
/// @param fitter_state the state of kalman fitter
template <typename seed_parameters_t>
TRACCC_HOST_DEVICE void filter(
const seed_parameters_t& seed_params, state& fitter_state,
vector_type<intersection_type>&& nav_candidates = {}) {
TRACCC_HOST_DEVICE void filter(const seed_parameters_t& seed_params,
state& fitter_state) {

// Create propagator
propagator_type propagator(m_cfg.propagation);
Expand All @@ -170,8 +164,8 @@ class kalman_fitter {
m_cfg.propagation.stepping.path_limit);

// Create propagator state
typename propagator_type::state propagation(
seed_params, m_field, m_detector, std::move(nav_candidates));
typename propagator_type::state propagation(seed_params, m_field,
m_detector);
propagation.set_particle(detail::correct_particle_hypothesis(
m_cfg.ptc_hypothesis, seed_params));

Expand Down Expand Up @@ -212,7 +206,7 @@ class kalman_fitter {
// considered to be the filtered one, we can reversly iterate the
// algorithm to obtain the smoothed parameter of other surfaces
auto& last = track_states.back();
last.smoothed().set_vector(last.filtered().vector());
last.smoothed().set_parameter_vector(last.filtered());
last.smoothed().set_covariance(last.filtered().covariance());
last.smoothed_chi2() = last.filtered_chi2();

Expand Down
8 changes: 3 additions & 5 deletions core/include/traccc/utils/seed_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct seed_generator {
const detray::tracking_surface sf{m_detector, surface_link};

const cxt_t ctx{};
auto bound_vec = sf.free_to_bound_vector(ctx, free_param.vector());
auto bound_vec = sf.free_to_bound_vector(ctx, free_param);

auto bound_cov =
matrix_operator().template zero<e_bound_size, e_bound_size>();
Expand All @@ -78,10 +78,8 @@ struct seed_generator {

for (std::size_t i = 0; i < e_bound_size; i++) {

matrix_operator().element(bound_param.vector(), i, 0) =
std::normal_distribution<scalar>(
matrix_operator().element(bound_param.vector(), i, 0),
m_stddevs[i])(generator);
bound_param[i] = std::normal_distribution<scalar>(
bound_param[i], m_stddevs[i])(generator);

matrix_operator().element(bound_param.covariance(), i, i) =
m_stddevs[i] * m_stddevs[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TRACCC_DEVICE inline void apply_interaction(

auto& bound_param = params.at(globalIndex);

// Get intersection at surface
// Get surface corresponding to bound params
const detray::tracking_surface sf{det, bound_param.surface_link()};
const typename detector_t::geometry_context ctx{};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ TRACCC_DEVICE inline void propagate_to_next_surface(
std::size_t globalIndex, const config_t cfg,
typename propagator_t::detector_type::view_type det_data,
bfield_t field_data,
vecmem::data::jagged_vector_view<typename propagator_t::intersection_type>
nav_candidates_buffer,
bound_track_parameters_collection_types::const_view in_params_view,
vecmem::data::vector_view<const candidate_link> links_view,
const unsigned int step, const unsigned int& n_in_params,
Expand All @@ -40,18 +38,13 @@ TRACCC_DEVICE inline void propagate_to_next_surface(
// Seed id
unsigned int orig_param_id = links.at(globalIndex).seed_idx;

// Navigation candidate buffer
vecmem::jagged_device_vector<typename propagator_t::intersection_type>
nav_candidates(nav_candidates_buffer);

// Count the number of tracks per seed
vecmem::device_atomic_ref<unsigned int> num_tracks_per_seed(
n_tracks_per_seed.at(orig_param_id));

const unsigned int s_pos = num_tracks_per_seed.fetch_add(1);

if (s_pos >= cfg.max_num_branches_per_seed ||
globalIndex >= nav_candidates.size()) {
if (s_pos >= cfg.max_num_branches_per_seed) {
return;
}

Expand Down Expand Up @@ -84,8 +77,7 @@ TRACCC_DEVICE inline void propagate_to_next_surface(
propagator_t propagator(cfg.propagation);

// Create propagator state
typename propagator_t::state propagation(
in_par, field_data, det, std::move(nav_candidates.at(globalIndex)));
typename propagator_t::state propagation(in_par, field_data, det);
propagation.set_particle(
detail::correct_particle_hypothesis(cfg.ptc_hypothesis, in_par));
propagation._stepping
Expand Down Expand Up @@ -114,7 +106,7 @@ TRACCC_DEVICE inline void propagate_to_next_surface(
propagation._navigation.set_volume(in_par.surface_link().volume());

// Propagate to the next surface
propagator.propagate_sync(propagation, std::tie(s0, s1, s2, s3, s4));
propagator.propagate_sync(propagation, detray::tie(s0, s1, s2, s3, s4));

// If a surface found, add the parameter for the next step
if (s4.success) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace traccc::device {
/// @param[in] globalIndex The index of the current thread
/// @param[in] cfg Track finding config object
/// @param[in] det_data Detector view object
/// @param[in] nav_candidates_buffer Navgation buffer
/// @param[in] in_params_view Input parameters
/// @param[in] links_view Link container for the current step
/// @param[in] step Step index
Expand All @@ -41,8 +40,6 @@ TRACCC_DEVICE inline void propagate_to_next_surface(
std::size_t globalIndex, const config_t cfg,
typename propagator_t::detector_type::view_type det_data,
bfield_t field_data,
vecmem::data::jagged_vector_view<typename propagator_t::intersection_type>
nav_candidates_buffer,
bound_track_parameters_collection_types::const_view in_params_view,
vecmem::data::vector_view<const candidate_link> links_view,
const unsigned int step, const unsigned int& n_in_params,
Expand All @@ -56,4 +53,4 @@ TRACCC_DEVICE inline void propagate_to_next_surface(
} // namespace traccc::device

// Include the implementation.
#include "traccc/finding/device/impl/propagate_to_next_surface.ipp"
#include "traccc/finding/device/impl/propagate_to_next_surface.ipp"
8 changes: 3 additions & 5 deletions device/common/include/traccc/fitting/device/fit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ namespace traccc::device {
///
/// @param[in] globalIndex The index of the current thread
/// @param[in] det_data Detector view object
/// @param[in] nav_candidates_buffer Buffer for navigation candidate objects
/// @param[in] track_candidates_view The input track candidates
/// @param[out] track_states_view The output of fitted track states
///
template <typename fitter_t, typename detector_view_t>
template <typename fitter_t>
TRACCC_HOST_DEVICE inline void fit(
std::size_t globalIndex, detector_view_t det_data,
std::size_t globalIndex,
typename fitter_t::detector_type::view_type det_data,
const typename fitter_t::bfield_type field_data,
const typename fitter_t::config_type cfg,
vecmem::data::jagged_vector_view<typename fitter_t::intersection_type>
nav_candidates_buffer,
track_candidate_container_types::const_view track_candidates_view,
track_state_container_types::view track_states_view);

Expand Down
16 changes: 6 additions & 10 deletions device/common/include/traccc/fitting/device/impl/fit.ipp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2022 CERN for the benefit of the ACTS project
* (c) 2022-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand All @@ -9,21 +9,17 @@

namespace traccc::device {

template <typename fitter_t, typename detector_view_t>
template <typename fitter_t>
TRACCC_HOST_DEVICE inline void fit(
std::size_t globalIndex, detector_view_t det_data,
std::size_t globalIndex,
typename fitter_t::detector_type::view_type det_data,
const typename fitter_t::bfield_type field_data,
const typename fitter_t::config_type cfg,
vecmem::data::jagged_vector_view<typename fitter_t::intersection_type>
nav_candidates_buffer,
track_candidate_container_types::const_view track_candidates_view,
track_state_container_types::view track_states_view) {

typename fitter_t::detector_type det(det_data);

vecmem::jagged_device_vector<typename fitter_t::intersection_type>
nav_candidates(nav_candidates_buffer);

track_candidate_container_types::const_device track_candidates(
track_candidates_view);

Expand Down Expand Up @@ -52,10 +48,10 @@ TRACCC_HOST_DEVICE inline void fit(
typename fitter_t::state fitter_state(track_states_per_track);

// Run fitting
fitter.fit(seed_param, fitter_state, nav_candidates.at(globalIndex));
fitter.fit(seed_param, fitter_state);

// Get the final fitting information
track_states[globalIndex].header = fitter_state.m_fit_res;
}

} // namespace traccc::device
} // namespace traccc::device
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class finding_algorithm
: public algorithm<track_candidate_container_types::buffer(
const typename navigator_t::detector_type::view_type&,
const typename stepper_t::magnetic_field_type&,
const vecmem::data::jagged_vector_view<
typename navigator_t::intersection_type>&,
const typename measurement_collection_types::view&,
const bound_track_parameters_collection_types::buffer&)> {

Expand All @@ -63,7 +61,7 @@ class finding_algorithm

/// Actor chain for propagate to the next surface and its propagator type
using actor_type =
detray::actor_chain<std::tuple, detray::pathlimit_aborter,
detray::actor_chain<detray::dtuple, detray::pathlimit_aborter,
detray::parameter_transporter<algebra_type>,
interaction_register<interactor>, interactor,
ckf_aborter>;
Expand All @@ -90,13 +88,10 @@ class finding_algorithm
/// Run the algorithm
///
/// @param det_view Detector view object
/// @param navigation_buffer Buffer for navigation candidates
/// @param seeds Input seeds
track_candidate_container_types::buffer operator()(
const typename detector_type::view_type& det_view,
const bfield_type& field_view,
const vecmem::data::jagged_vector_view<
typename navigator_t::intersection_type>& navigation_buffer,
const typename measurement_collection_types::view& measurements,
const bound_track_parameters_collection_types::buffer& seeds)
const override;
Expand Down
Loading
Loading