Skip to content

Commit 6a59196

Browse files
committed
Enable device logging
1 parent a5449ab commit 6a59196

File tree

14 files changed

+317
-26
lines changed

14 files changed

+317
-26
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ include( traccc-functions )
5252
set( TRACCC_CUSTOM_SCALARTYPE "float" CACHE STRING
5353
"Scalar type to use in the TRACCC code" )
5454

55+
# Temporary setting for the traccc device log level, until it can be removed.
56+
set( TRACCC_DEVICE_LOG_LVL "NONE" CACHE STRING
57+
"Log level for traccc and detray device code" )
58+
5559
# Flags controlling which parts of traccc to build.
5660
option( TRACCC_BUILD_CUDA "Build the CUDA sources included in traccc" FALSE )
5761
option( TRACCC_BUILD_HIP "Build the HIP sources included in traccc" FALSE)

core/include/traccc/finding/actors/ckf_aborter.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
// Project include(s)
1111
#include "traccc/definitions/primitives.hpp"
1212
#include "traccc/definitions/qualifiers.hpp"
13+
#include "traccc/utils/logging.hpp"
1314

1415
// detray include(s)
16+
#include <detray/definitions/indexing.hpp>
1517
#include <detray/propagator/base_actor.hpp>
1618

1719
// System include(s)
@@ -43,13 +45,18 @@ struct ckf_aborter : detray::actor {
4345
abrt_state.count++;
4446
abrt_state.path_from_surface += stepping.step_size();
4547

48+
TRACCC_VERBOSE_HOST_DEVICE("Checking CKF aborter");
49+
4650
// Stop at the next sensitive surface
4751
if (navigation.is_on_sensitive() &&
4852
abrt_state.path_from_surface > abrt_state.min_step_length) {
4953
prop_state._heartbeat &= navigation.pause();
5054
abrt_state.success = true;
5155
}
5256

57+
TRACCC_VERBOSE_HOST_DEVICE("-> Found sensitive surface: %d",
58+
navigation.barcode().index());
59+
5360
// Reset path from surface
5461
if (navigation.is_on_sensitive()) {
5562
abrt_state.path_from_surface = 0.f;

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

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "traccc/finding/candidate_link.hpp"
1616
#include "traccc/finding/details/combinatorial_kalman_filter_types.hpp"
1717
#include "traccc/finding/finding_config.hpp"
18+
#include "traccc/finding/propagation_data.hpp"
1819
#include "traccc/fitting/kalman_filter/gain_matrix_updater.hpp"
1920
#include "traccc/fitting/kalman_filter/is_line_visitor.hpp"
2021
#include "traccc/fitting/status_codes.hpp"
@@ -63,7 +64,7 @@ combinatorial_kalman_filter(
6364
const measurement_collection_types::const_view& measurements_view,
6465
const bound_track_parameters_collection_types::const_view& seeds_view,
6566
const finding_config& config, vecmem::memory_resource& mr,
66-
const Logger& log) {
67+
const Logger& /*log*/) {
6768

6869
assert(config.min_step_length_for_next_surface >
6970
math::fabs(config.propagation.navigation.overstep_tolerance) &&
@@ -77,7 +78,8 @@ combinatorial_kalman_filter(
7778
using scalar_type = detray::dscalar<algebra_type>;
7879

7980
// Create a logger.
80-
auto logger = [&log]() -> const Logger& { return log; };
81+
// @TODO: Turn back on, once detray can use the ACTS logger
82+
// auto logger = [&log]() -> const Logger& { return log; };
8183

8284
/*****************************************************************
8385
* Measurement Operations
@@ -144,12 +146,13 @@ combinatorial_kalman_filter(
144146
for (unsigned int step = 0u; step < config.max_track_candidates_per_track;
145147
step++) {
146148

147-
TRACCC_VERBOSE("Starting step "
148-
<< step + 1 << " / "
149-
<< config.max_track_candidates_per_track);
149+
TRACCC_VERBOSE_HOST("Starting step "
150+
<< step + 1 << " / "
151+
<< config.max_track_candidates_per_track);
150152

151153
// Iterate over input parameters
152154
const std::size_t n_in_params = in_params.size();
155+
TRACCC_VERBOSE_HOST("No. Params: " << n_in_params);
153156

154157
// Terminate if there is no parameter to proceed
155158
if (n_in_params == 0) {
@@ -199,10 +202,13 @@ combinatorial_kalman_filter(
199202
: links[step - 1][param_to_link[step - 1][in_param_id]]
200203
.ndf_sum);
201204

202-
TRACCC_VERBOSE("Processing input parameter "
203-
<< in_param_id + 1 << " / " << n_in_params << ": "
204-
<< in_param << " (orig_param_id=" << orig_param_id
205-
<< ", skip_counter=" << skip_counter << ")");
205+
TRACCC_VERBOSE_HOST("Processing input parameter "
206+
<< in_param_id + 1 << " / " << n_in_params);
207+
TRACCC_VERBOSE_HOST("-> orig_param_id="
208+
<< orig_param_id << ", skip_counter="
209+
<< skip_counter << "\nVec:\n"
210+
<< in_param.vector());
211+
TRACCC_DEBUG_HOST("Cov:\n" << in_param.covariance());
206212

207213
/*************************
208214
* Material interaction
@@ -211,8 +217,8 @@ combinatorial_kalman_filter(
211217
// Get surface corresponding to bound params
212218
const detray::tracking_surface sf{det, in_param.surface_link()};
213219

214-
TRACCC_VERBOSE(
215-
" free params: " << sf.bound_to_free_vector({}, in_param));
220+
TRACCC_VERBOSE_HOST(" Free params:\n"
221+
<< sf.bound_to_free_vector({}, in_param));
216222

217223
// Apply interactor
218224
if (sf.has_material()) {
@@ -241,7 +247,10 @@ combinatorial_kalman_filter(
241247
best_links;
242248

243249
// Iterate over the measurements
250+
TRACCC_VERBOSE_HOST("No. measurements: " << (up - lo));
244251
for (unsigned int meas_id = lo; meas_id < up; meas_id++) {
252+
TRACCC_VERBOSE_HOST("Testing measurement: " << meas_id);
253+
245254
// The measurement on surface to handle.
246255
const measurement& meas = measurements.at(meas_id);
247256

@@ -258,9 +267,13 @@ combinatorial_kalman_filter(
258267

259268
const traccc::scalar chi2 = trk_state.filtered_chi2();
260269

270+
TRACCC_DEBUG_HOST("KF status: " << fitter_debug_msg{res}());
271+
261272
// The chi2 from Kalman update should be less than chi2_max
262273
if (res == kalman_fitter_status::SUCCESS &&
263-
chi2 < config.chi2_max) {
274+
(chi2 < config.chi2_max)) {
275+
276+
TRACCC_VERBOSE_HOST("Found measurement: " << meas_id);
264277

265278
best_links.push_back(
266279
{{.step = step,
@@ -285,9 +298,9 @@ combinatorial_kalman_filter(
285298
const unsigned int n_branches =
286299
std::min(config.max_num_branches_per_surface,
287300
static_cast<unsigned int>(best_links.size()));
288-
TRACCC_VERBOSE("Found " << n_branches << " branches for step "
289-
<< step << " and input parameter "
290-
<< in_param_id);
301+
TRACCC_VERBOSE_HOST("Found " << n_branches << " branches for step "
302+
<< step << " and input parameter "
303+
<< in_param_id + 1);
291304
for (unsigned int i = 0; i < n_branches; ++i) {
292305
const auto& [link, filtered_params] = best_links[i];
293306

@@ -296,9 +309,9 @@ combinatorial_kalman_filter(
296309

297310
// Add the updated parameter to the updated parameters
298311
updated_params.push_back(filtered_params);
299-
TRACCC_VERBOSE("updated_params["
300-
<< updated_params.size() - 1
301-
<< "] = " << updated_params.back());
312+
TRACCC_DEBUG_HOST("updated_params["
313+
<< updated_params.size() - 1
314+
<< "] = " << updated_params.back());
302315
}
303316

304317
/*****************************************************************
@@ -319,10 +332,12 @@ combinatorial_kalman_filter(
319332
.chi2_sum = prev_chi2_sum,
320333
.ndf_sum = prev_ndf_sum});
321334

335+
TRACCC_VERBOSE_HOST("Hole state created");
336+
322337
updated_params.push_back(in_param);
323-
TRACCC_VERBOSE("updated_params["
324-
<< updated_params.size() - 1
325-
<< "] = " << updated_params.back());
338+
TRACCC_DEBUG_HOST("updated_params["
339+
<< updated_params.size() - 1
340+
<< "] = " << updated_params.back());
326341
}
327342
}
328343

@@ -439,6 +454,8 @@ combinatorial_kalman_filter(
439454
}
440455

441456
if (this_is_dominated) {
457+
TRACCC_VERBOSE_HOST(
458+
"Track is dead (deduplication)!");
442459
param_liveness.at(tracks.at(i)) = 0u;
443460
break;
444461
}
@@ -466,11 +483,15 @@ combinatorial_kalman_filter(
466483
// link to be a tip
467484
if (links.at(step).at(link_id).n_skipped >
468485
config.max_num_skipping_per_cand) {
486+
TRACCC_WARNING_HOST(
487+
"Create tip: Max no. of holes reached! Bound param:\n"
488+
<< updated_params[link_id].vector());
469489
tips.push_back({step, link_id});
470490
continue;
471491
}
472492

473493
const auto& param = updated_params[link_id];
494+
474495
// Create propagator state
475496
typename traccc::details::ckf_propagator_t<
476497
detector_t, bfield_t>::state propagation(param, field, det);
@@ -489,15 +510,19 @@ combinatorial_kalman_filter(
489510
typename detector_t::algebra_type>::state s3{prop_cfg};
490511
typename detray::momentum_aborter<scalar_type>::state s4{};
491512
typename ckf_aborter::state s5;
513+
492514
// Update the actor config
493515
s4.min_pT(static_cast<scalar_type>(config.min_pT));
494516
s4.min_p(static_cast<scalar_type>(config.min_p));
495517
s5.min_step_length = config.min_step_length_for_next_surface;
496518
s5.max_count = config.max_step_counts_for_next_surface;
497519

498520
// Propagate to the next surface
521+
TRACCC_DEBUG_HOST("Propagating... ");
499522
propagator.propagate(propagation,
500523
detray::tie(s0, s1, s2, s3, s4, s5));
524+
TRACCC_DEBUG_HOST("Finished propagation: On surface "
525+
<< propagation._navigation.barcode());
501526

502527
// If a surface found, add the parameter for the next
503528
// step
@@ -511,14 +536,18 @@ combinatorial_kalman_filter(
511536
const scalar theta = out_param.theta();
512537
if (theta <= 0.f ||
513538
theta >= 2.f * constant<traccc::scalar>::pi) {
539+
TRACCC_ERROR_HOST("Theta is hit pole after propagation");
514540
valid_track = false;
515541
}
516542

517543
if (!std::isfinite(out_param.phi())) {
544+
TRACCC_ERROR_HOST(
545+
"Phi is infinite after propagation (Matrix inversion)");
518546
valid_track = false;
519547
}
520548

521549
if (math::fabs(out_param.qop()) == 0.f) {
550+
TRACCC_ERROR_HOST("q over p is zero after propagation");
522551
valid_track = false;
523552
}
524553

@@ -531,13 +560,19 @@ combinatorial_kalman_filter(
531560
// tip
532561
if (!valid_track &&
533562
(step >= (config.min_track_candidates_per_track - 1u))) {
563+
if (!s5.success) {
564+
TRACCC_VERBOSE_HOST("Create tip: No next sensitive found");
565+
} else {
566+
TRACCC_VERBOSE_HOST("Create tip: Encountered error");
567+
}
534568
tips.push_back({step, link_id});
535569
}
536570

537571
// If no more CKF step is expected, current candidate is
538572
// kept as a tip
539573
if (s5.success &&
540574
(step == (config.max_track_candidates_per_track - 1u))) {
575+
TRACCC_ERROR_HOST("Create tip: Max no. candidates");
541576
tips.push_back({step, link_id});
542577
}
543578
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/** TRACCC library, part of the ACTS project (R&D line)
2+
*
3+
* (c) 2025 CERN for the benefit of the ACTS project
4+
*
5+
* Mozilla Public License Version 2.0
6+
*/
7+
8+
#pragma once
9+
10+
// Detray include(s).
11+
#include <detray/definitions/indexing.hpp>
12+
13+
namespace traccc {
14+
15+
/// Data from the propagation loop that has to be kept between CKF steps
16+
struct propagation_data {
17+
/// The surface that was visited before the current one (overlaps
18+
/// resolution)
19+
detray::dindex prev_surface{detray::dindex_invalid};
20+
21+
/// Is the current surface hit in the extended tolerance band?
22+
bool is_edge{false};
23+
};
24+
25+
} // namespace traccc

core/include/traccc/fitting/kalman_filter/gain_matrix_updater.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "traccc/edm/measurement_helpers.hpp"
1515
#include "traccc/edm/track_state_collection.hpp"
1616
#include "traccc/fitting/status_codes.hpp"
17+
#include "traccc/utils/logging.hpp"
1718

1819
namespace traccc {
1920

@@ -62,6 +63,9 @@ struct gain_matrix_updater {
6263

6364
static constexpr unsigned int D = 2;
6465

66+
TRACCC_VERBOSE_HOST_DEVICE("In gain-matrix-updater...");
67+
TRACCC_VERBOSE_HOST_DEVICE("Measurement dim: %d", dim);
68+
6569
assert(dim == 1u || dim == 2u);
6670

6771
assert(!bound_params.is_invalid());
@@ -79,6 +83,8 @@ struct gain_matrix_updater {
7983

8084
assert((dim > 1) || (getter::element(meas_local, 1u, 0u) == 0.f));
8185

86+
TRACCC_DEBUG_HOST("Predicted param.: " << bound_params);
87+
8288
// Predicted vector of bound track parameters
8389
const bound_vector_type& predicted_vec = bound_params.vector();
8490

@@ -109,6 +115,11 @@ struct gain_matrix_updater {
109115
getter::element(V, 1u, 1u) = 1.f;
110116
}
111117

118+
TRACCC_DEBUG_HOST("Measurement position: " << meas_local);
119+
TRACCC_DEBUG_HOST("Measurement variance:\n" << V);
120+
TRACCC_DEBUG_HOST("Predicted residual: " << meas_local -
121+
H * predicted_vec);
122+
112123
const matrix_type<e_bound_size, D> projected_cov =
113124
algebra::matrix::transposed_product<false, true>(predicted_cov, H);
114125

@@ -118,22 +129,33 @@ struct gain_matrix_updater {
118129
assert(matrix::determinant(M) != 0.f);
119130
const matrix_type<6, D> K = projected_cov * matrix::inverse(M);
120131

132+
TRACCC_DEBUG_HOST("H:\n" << H);
133+
TRACCC_DEBUG_HOST("K:\n" << K);
134+
121135
// Calculate the filtered track parameters
122136
const matrix_type<6, 1> filtered_vec =
123137
predicted_vec + K * (meas_local - H * predicted_vec);
124138
const matrix_type<6, 6> filtered_cov = (I66 - K * H) * predicted_cov;
125139

140+
TRACCC_DEBUG_HOST("Filtered param:\n" << filtered_vec);
141+
TRACCC_DEBUG_HOST("Filtered cov:\n" << filtered_cov);
142+
126143
// Return false if track is parallel to z-axis or phi is not finite
127144
if (!std::isfinite(getter::element(filtered_vec, e_bound_theta, 0))) {
145+
TRACCC_ERROR_HOST_DEVICE(
146+
"Theta is infinite after filtering (Matrix inversion)");
128147
return kalman_fitter_status::ERROR_INVERSION;
129148
}
130149

131150
if (!std::isfinite(getter::element(filtered_vec, e_bound_phi, 0))) {
151+
TRACCC_ERROR_HOST_DEVICE(
152+
"Phi is infinite after filtering (Matrix inversion)");
132153
return kalman_fitter_status::ERROR_INVERSION;
133154
}
134155

135156
if (math::fabs(getter::element(filtered_vec, e_bound_qoverp, 0)) ==
136157
0.f) {
158+
TRACCC_ERROR_HOST_DEVICE("q/p is zero after filtering");
137159
return kalman_fitter_status::ERROR_QOP_ZERO;
138160
}
139161

@@ -149,11 +171,19 @@ struct gain_matrix_updater {
149171

150172
const scalar chi2_val{getter::element(chi2, 0, 0)};
151173

174+
TRACCC_VERBOSE_HOST("Filtered residual: " << residual);
175+
TRACCC_DEBUG_HOST("R:\n" << R);
176+
TRACCC_DEBUG_HOST_DEVICE("det(R): %f", matrix::determinant(R));
177+
TRACCC_DEBUG_HOST("R_inv:\n" << matrix::inverse(R));
178+
TRACCC_VERBOSE_HOST_DEVICE("Chi2: %f", chi2_val);
179+
152180
if (chi2_val < 0.f) {
181+
TRACCC_ERROR_HOST_DEVICE("Chi2 negative");
153182
return kalman_fitter_status::ERROR_UPDATER_CHI2_NEGATIVE;
154183
}
155184

156185
if (!std::isfinite(chi2_val)) {
186+
TRACCC_ERROR_HOST_DEVICE("Chi2 infinite");
157187
return kalman_fitter_status::ERROR_UPDATER_CHI2_NOT_FINITE;
158188
}
159189

@@ -167,6 +197,8 @@ struct gain_matrix_updater {
167197

168198
const scalar theta = trk_state.filtered_params().theta();
169199
if (theta <= 0.f || theta >= 2.f * constant<traccc::scalar>::pi) {
200+
TRACCC_ERROR_HOST_DEVICE("Hit theta pole after filtering : %f",
201+
theta);
170202
return kalman_fitter_status::ERROR_THETA_POLE;
171203
}
172204

0 commit comments

Comments
 (0)