Skip to content

Commit d31f168

Browse files
Minor fixes to the track building kernel (#859)
This commit makes some minor fixes and improvements to the track building kernel. In particular, it: 1. Fixes an error where we were comparing measurements indices to see if they were _larger_ than the total number of measurements, but they should be check also for _equality_. 2. Fail more gracefully if we cannot find any true measurements, i.e. register the failed track as a candidate for pruning. 3. Simplify the control flow of the kernel by removing an unnecessary break statement. Co-authored-by: beomki-yeo <63090140+beomki-yeo@users.noreply.github.com>
1 parent fd5699c commit d31f168

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

core/include/traccc/finding/details/find_tracks.hpp

+9-11
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ track_candidate_container_types::host find_tracks(
362362
unsigned int n_skipped{0u};
363363
while (true) {
364364

365-
if (L.meas_idx > n_meas) {
365+
if (L.meas_idx >= n_meas) {
366366
n_skipped++;
367367
}
368368

@@ -393,20 +393,19 @@ track_candidate_container_types::host find_tracks(
393393
for (auto it = cands_per_track.rbegin(); it != cands_per_track.rend();
394394
it++) {
395395

396-
while (L.meas_idx > n_meas) {
396+
while (L.meas_idx >= n_meas) {
397397
const auto link_pos =
398398
param_to_link[L.previous.first][L.previous.second];
399399

400400
L = links[L.previous.first][link_pos];
401401
}
402402

403403
// Break if the measurement is still invalid
404-
if (L.meas_idx > measurements.size()) {
404+
if (L.meas_idx >= measurements.size()) {
405405
break;
406406
}
407407

408-
auto& cand = *it;
409-
cand = measurements.at(L.meas_idx);
408+
*it = measurements.at(L.meas_idx);
410409

411410
// Break the loop if the iterator is at the first candidate and
412411
// fill the seed
@@ -416,13 +415,12 @@ track_candidate_container_types::host find_tracks(
416415

417416
// Add seed and track candidates to the output container
418417
output_candidates.push_back(cand_seed, cands_per_track);
419-
break;
420-
}
421-
422-
const auto l_pos =
423-
param_to_link[L.previous.first][L.previous.second];
418+
} else {
419+
const auto l_pos =
420+
param_to_link[L.previous.first][L.previous.second];
424421

425-
L = links[L.previous.first][l_pos];
422+
L = links[L.previous.first][l_pos];
423+
}
426424
}
427425
}
428426

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

+11-8
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ TRACCC_DEVICE inline void build_tracks(const global_index_t globalIndex,
6565
// Resize the candidates with the exact size
6666
cands_per_track.resize(n_cands);
6767

68+
bool success = true;
69+
6870
// Reversely iterate to fill the track candidates
6971
for (auto it = cands_per_track.rbegin(); it != cands_per_track.rend();
7072
it++) {
7173

72-
while (L.meas_idx > n_meas &&
74+
while (L.meas_idx >= n_meas &&
7375
L.previous.first !=
7476
std::numeric_limits<
7577
candidate_link::link_index_type::first_type>::max()) {
@@ -78,26 +80,27 @@ TRACCC_DEVICE inline void build_tracks(const global_index_t globalIndex,
7880
}
7981

8082
// Break if the measurement is still invalid
81-
if (L.meas_idx > measurements.size()) {
83+
if (L.meas_idx >= measurements.size()) {
84+
success = false;
8285
break;
8386
}
8487

85-
auto& cand = *it;
86-
cand = {measurements.at(L.meas_idx)};
88+
*it = {measurements.at(L.meas_idx)};
8789

8890
// Break the loop if the iterator is at the first candidate and fill the
8991
// seed
9092
if (it == cands_per_track.rend() - 1) {
9193
seed = seeds.at(L.previous.second);
92-
break;
94+
} else {
95+
L = links[L.previous.first][L.previous.second];
9396
}
94-
95-
L = links[L.previous.first][L.previous.second];
9697
}
9798

99+
// NOTE: We may at some point want to assert that `success` is true
100+
98101
// Criteria for valid tracks
99102
if (n_cands >= cfg.min_track_candidates_per_track &&
100-
n_cands <= cfg.max_track_candidates_per_track) {
103+
n_cands <= cfg.max_track_candidates_per_track && success) {
101104

102105
vecmem::device_atomic_ref<unsigned int> num_valid_tracks(
103106
*payload.n_valid_tracks);

0 commit comments

Comments
 (0)