Skip to content

Commit ae033ba

Browse files
committed
Access the track parameters in a sorted order based on the theta
1 parent 884457a commit ae033ba

9 files changed

+79
-12
lines changed

device/common/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ traccc_add_library( traccc_device_common device_common TYPE SHARED
2626
"include/traccc/edm/device/triplet_counter.hpp"
2727
"include/traccc/edm/device/device_doublet.hpp"
2828
"include/traccc/edm/device/device_triplet.hpp"
29+
"include/traccc/edm/device/theta_id.hpp"
2930
# Clusterization function(s).
3031
"include/traccc/clusterization/device/form_spacepoints.hpp"
3132
"include/traccc/clusterization/device/impl/form_spacepoints.ipp"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/** TRACCC library, part of the ACTS project (R&D line)
2+
*
3+
* (c) 2024 CERN for the benefit of the ACTS project
4+
*
5+
* Mozilla Public License Version 2.0
6+
*/
7+
8+
#pragma once
9+
10+
// Project include(s).
11+
#include "traccc/definitions/primitives.hpp"
12+
13+
namespace traccc::device {
14+
15+
/// Theta of track parameters and its index
16+
struct theta_id {
17+
traccc::scalar theta;
18+
unsigned int id;
19+
}; // struct theta_id
20+
21+
/// Comparator based on theta
22+
struct theta_id_sort_comp {
23+
TRACCC_HOST_DEVICE
24+
bool operator()(const theta_id& lhs, const theta_id& rhs) {
25+
return math::abs(lhs.theta - constant<traccc::scalar>::pi_2) <
26+
math::abs(rhs.theta - constant<traccc::scalar>::pi_2);
27+
}
28+
};
29+
30+
} // namespace traccc::device

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

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ TRACCC_DEVICE inline void add_links_for_holes(
2222
vecmem::data::vector_view<const unsigned int> prev_param_to_link_view,
2323
const unsigned int step, const unsigned int& n_max_candidates,
2424
bound_track_parameters_collection_types::view out_params_view,
25+
vecmem::data::vector_view<device::theta_id> theta_id_view,
2526
vecmem::data::vector_view<candidate_link> links_view,
2627
unsigned int& n_total_candidates);
2728

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

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace traccc::device {
3838
/// @param[in] step Step index
3939
/// @param[in] n_max_candidates Number of maximum candidates
4040
/// @param[out] out_params_view Output parameters
41+
/// @param[out] theta_id_view Pair of theta and id of output parameters
4142
/// @param[out] n_candidates_view Number of candidates per input parameter
4243
/// @param[out] links_view link container for the current step
4344
/// @param[out] n_total_candidates The number of total candidates for the
@@ -56,6 +57,7 @@ TRACCC_DEVICE inline void find_tracks(
5657
vecmem::data::vector_view<const unsigned int> prev_param_to_link_view,
5758
const unsigned int step, const unsigned int& n_max_candidates,
5859
bound_track_parameters_collection_types::view out_params_view,
60+
vecmem::data::vector_view<device::theta_id> theta_id_view,
5961
vecmem::data::vector_view<unsigned int> n_candidates_view,
6062
vecmem::data::vector_view<candidate_link> links_view,
6163
unsigned int& n_total_candidates);

device/common/include/traccc/finding/device/impl/add_links_for_holes.ipp

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ TRACCC_DEVICE inline void add_links_for_holes(
1919
vecmem::data::vector_view<const unsigned int> prev_param_to_link_view,
2020
const unsigned int step, const unsigned int& n_max_candidates,
2121
bound_track_parameters_collection_types::view out_params_view,
22+
vecmem::data::vector_view<device::theta_id> theta_id_view,
2223
vecmem::data::vector_view<candidate_link> links_view,
2324
unsigned int& n_total_candidates) {
2425

@@ -43,6 +44,9 @@ TRACCC_DEVICE inline void add_links_for_holes(
4344
// Output parameters
4445
bound_track_parameters_collection_types::device out_params(out_params_view);
4546

47+
// Theta id
48+
vecmem::device_vector<device::theta_id> theta_id(theta_id_view);
49+
4650
// Links
4751
vecmem::device_vector<candidate_link> links(links_view);
4852

@@ -84,6 +88,7 @@ TRACCC_DEVICE inline void add_links_for_holes(
8488
skip_counter + 1};
8589

8690
out_params.at(l_pos) = in_params.at(globalIndex);
91+
theta_id.at(l_pos) = {out_params.at(l_pos).theta(), l_pos};
8792
}
8893
}
8994

device/common/include/traccc/finding/device/impl/find_tracks.ipp

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ TRACCC_DEVICE inline void find_tracks(
2828
vecmem::data::vector_view<const unsigned int> prev_param_to_link_view,
2929
const unsigned int step, const unsigned int& n_max_candidates,
3030
bound_track_parameters_collection_types::view out_params_view,
31+
vecmem::data::vector_view<device::theta_id> theta_id_view,
3132
vecmem::data::vector_view<unsigned int> n_candidates_view,
3233
vecmem::data::vector_view<candidate_link> links_view,
3334
unsigned int& n_total_candidates) {
@@ -52,6 +53,9 @@ TRACCC_DEVICE inline void find_tracks(
5253
// Output parameters
5354
bound_track_parameters_collection_types::device out_params(out_params_view);
5455

56+
// Theta id
57+
vecmem::device_vector<device::theta_id> theta_id(theta_id_view);
58+
5559
// Number of candidates per parameter
5660
vecmem::device_vector<unsigned int> n_candidates(n_candidates_view);
5761

@@ -145,7 +149,8 @@ TRACCC_DEVICE inline void find_tracks(
145149
n_candidates[in_param_id]);
146150
num_candidates.fetch_add(1);
147151

148-
out_params[l_pos] = trk_state.filtered();
152+
out_params.at(l_pos) = trk_state.filtered();
153+
theta_id.at(l_pos) = {out_params.at(l_pos).theta(), l_pos};
149154
}
150155
}
151156
}

device/common/include/traccc/finding/device/impl/propagate_to_next_surface.ipp

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ TRACCC_DEVICE inline void propagate_to_next_surface(
1515
typename propagator_t::detector_type::view_type det_data,
1616
bfield_t field_data,
1717
bound_track_parameters_collection_types::const_view in_params_view,
18+
vecmem::data::vector_view<const device::theta_id> theta_id_view,
1819
vecmem::data::vector_view<const candidate_link> links_view,
1920
const unsigned int step, const unsigned int& n_in_params,
2021
bound_track_parameters_collection_types::view out_params_view,
@@ -28,6 +29,9 @@ TRACCC_DEVICE inline void propagate_to_next_surface(
2829
return;
2930
}
3031

32+
// Theta id
33+
vecmem::device_vector<const device::theta_id> theta_id(theta_id_view);
34+
3135
// Number of tracks per seed
3236
vecmem::device_vector<unsigned int> n_tracks_per_seed(
3337
n_tracks_per_seed_view);
@@ -71,7 +75,8 @@ TRACCC_DEVICE inline void propagate_to_next_surface(
7175
vecmem::device_vector<unsigned int> param_to_link(param_to_link_view);
7276

7377
// Input bound track parameter
74-
const bound_track_parameters in_par = in_params.at(globalIndex);
78+
const unsigned int in_par_id = theta_id.at(globalIndex).id;
79+
const bound_track_parameters in_par = in_params.at(in_par_id);
7580

7681
// Create propagator
7782
propagator_t propagator(cfg.propagation);

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

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace traccc::device {
2626
/// @param[in] cfg Track finding config object
2727
/// @param[in] det_data Detector view object
2828
/// @param[in] in_params_view Input parameters
29+
/// @param[in] theta_id_view Theta and id of input parameters
2930
/// @param[in] links_view Link container for the current step
3031
/// @param[in] step Step index
3132
/// @param[in] n_in_params The number of input parameters
@@ -41,6 +42,7 @@ TRACCC_DEVICE inline void propagate_to_next_surface(
4142
typename propagator_t::detector_type::view_type det_data,
4243
bfield_t field_data,
4344
bound_track_parameters_collection_types::const_view in_params_view,
45+
vecmem::data::vector_view<const device::theta_id> theta_id_view,
4446
vecmem::data::vector_view<const candidate_link> links_view,
4547
const unsigned int step, const unsigned int& n_in_params,
4648
bound_track_parameters_collection_types::view out_params_view,

device/cuda/src/finding/finding_algorithm.cu

+26-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "traccc/definitions/primitives.hpp"
1414
#include "traccc/definitions/qualifiers.hpp"
1515
#include "traccc/edm/device/finding_global_counter.hpp"
16+
#include "traccc/edm/device/theta_id.hpp"
1617
#include "traccc/finding/candidate_link.hpp"
1718
#include "traccc/finding/device/add_links_for_holes.hpp"
1819
#include "traccc/finding/device/apply_interaction.hpp"
@@ -105,6 +106,7 @@ __global__ void find_tracks(
105106
vecmem::data::vector_view<const unsigned int> prev_param_to_link_view,
106107
const unsigned int step, const unsigned int n_max_candidates,
107108
bound_track_parameters_collection_types::view out_params_view,
109+
vecmem::data::vector_view<device::theta_id> theta_id_view,
108110
vecmem::data::vector_view<unsigned int> n_candidates_view,
109111
vecmem::data::vector_view<candidate_link> links_view,
110112
unsigned int& n_candidates) {
@@ -115,7 +117,7 @@ __global__ void find_tracks(
115117
gid, cfg, det_data, measurements_view, in_params_view,
116118
n_measurements_prefix_sum_view, ref_meas_idx_view, prev_links_view,
117119
prev_param_to_link_view, step, n_max_candidates, out_params_view,
118-
n_candidates_view, links_view, n_candidates);
120+
theta_id_view, n_candidates_view, links_view, n_candidates);
119121
}
120122

121123
/// CUDA kernel for running @c traccc::device::add_links_for_holes
@@ -126,15 +128,16 @@ __global__ void add_links_for_holes(
126128
vecmem::data::vector_view<const unsigned int> prev_param_to_link_view,
127129
const unsigned int step, const unsigned int n_max_candidates,
128130
bound_track_parameters_collection_types::view out_params_view,
131+
vecmem::data::vector_view<device::theta_id> theta_id_view,
129132
vecmem::data::vector_view<candidate_link> links_view,
130133
unsigned int& n_total_candidates) {
131134

132135
int gid = threadIdx.x + blockIdx.x * blockDim.x;
133136

134137
device::add_links_for_holes(gid, n_candidates_view, in_params_view,
135138
prev_links_view, prev_param_to_link_view, step,
136-
n_max_candidates, out_params_view, links_view,
137-
n_total_candidates);
139+
n_max_candidates, out_params_view,
140+
theta_id_view, links_view, n_total_candidates);
138141
}
139142

140143
/// CUDA kernel for running @c traccc::device::propagate_to_next_surface
@@ -144,6 +147,7 @@ __global__ void propagate_to_next_surface(
144147
typename propagator_t::detector_type::view_type det_data,
145148
bfield_t field_data,
146149
bound_track_parameters_collection_types::const_view in_params_view,
150+
vecmem::data::vector_view<const device::theta_id> theta_id_view,
147151
vecmem::data::vector_view<const candidate_link> links_view,
148152
const unsigned int step, const unsigned int& n_candidates,
149153
bound_track_parameters_collection_types::view out_params_view,
@@ -156,9 +160,9 @@ __global__ void propagate_to_next_surface(
156160
int gid = threadIdx.x + blockIdx.x * blockDim.x;
157161

158162
device::propagate_to_next_surface<propagator_t, bfield_t, config_t>(
159-
gid, cfg, det_data, field_data, in_params_view, links_view, step,
160-
n_candidates, out_params_view, param_to_link_view, tips_view,
161-
n_tracks_per_seed_view, n_out_params);
163+
gid, cfg, det_data, field_data, in_params_view, theta_id_view,
164+
links_view, step, n_candidates, out_params_view, param_to_link_view,
165+
tips_view, n_tracks_per_seed_view, n_out_params);
162166
}
163167

164168
/// CUDA kernel for running @c traccc::device::build_tracks
@@ -412,6 +416,8 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
412416

413417
bound_track_parameters_collection_types::buffer updated_params_buffer(
414418
n_in_params * m_cfg.max_num_branches_per_surface, m_mr.main);
419+
vecmem::data::vector_buffer<device::theta_id> theta_and_id_buffer(
420+
n_in_params * m_cfg.max_num_branches_per_surface, m_mr.main);
415421

416422
// Create the link map
417423
link_map[step] = {n_in_params * m_cfg.max_num_branches_per_surface,
@@ -428,7 +434,7 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
428434
n_measurements_prefix_sum_buffer, ref_meas_idx_buffer,
429435
link_map[prev_step], param_to_link_map[prev_step], step,
430436
n_max_candidates, updated_params_buffer,
431-
n_candidates_buffer, link_map[step],
437+
theta_and_id_buffer, n_candidates_buffer, link_map[step],
432438
(*global_counter_device).n_candidates);
433439
TRACCC_CUDA_ERROR_CHECK(cudaGetLastError());
434440
}
@@ -443,7 +449,7 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
443449
kernels::add_links_for_holes<<<nBlocks, nThreads, 0, stream>>>(
444450
n_candidates_buffer, in_params_buffer, link_map[prev_step],
445451
param_to_link_map[prev_step], step, n_max_candidates,
446-
updated_params_buffer, link_map[step],
452+
updated_params_buffer, theta_and_id_buffer, link_map[step],
447453
(*global_counter_device).n_candidates);
448454
TRACCC_CUDA_ERROR_CHECK(cudaGetLastError());
449455
}
@@ -456,6 +462,15 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
456462

457463
m_stream.synchronize();
458464

465+
// Sort the theta_and_id vector with the link vector
466+
vecmem::device_vector<device::theta_id> theta_and_id_device(
467+
theta_and_id_buffer);
468+
vecmem::device_vector<candidate_link> link_device(link_map[step]);
469+
thrust::sort_by_key(
470+
thrust::cuda::par.on(stream), theta_and_id_device.begin(),
471+
theta_and_id_device.begin() + global_counter_host.n_candidates,
472+
link_device.begin(), device::theta_id_sort_comp());
473+
459474
/*****************************************************************
460475
* Kernel6: Propagate to the next surface
461476
*****************************************************************/
@@ -482,8 +497,9 @@ finding_algorithm<stepper_t, navigator_t>::operator()(
482497
config_type>
483498
<<<nBlocks, nThreads, 0, stream>>>(
484499
m_cfg, det_view, field_view, updated_params_buffer,
485-
link_map[step], step, (*global_counter_device).n_candidates,
486-
out_params_buffer, param_to_link_map[step], tips_map[step],
500+
theta_and_id_buffer, link_map[step], step,
501+
(*global_counter_device).n_candidates, out_params_buffer,
502+
param_to_link_map[step], tips_map[step],
487503
n_tracks_per_seed_buffer,
488504
(*global_counter_device).n_out_params);
489505
TRACCC_CUDA_ERROR_CHECK(cudaGetLastError());

0 commit comments

Comments
 (0)