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

Verbose performance metrics #578

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ class greedy_ambiguity_resolution_algorithm
const typename track_state_container_types::host& track_states)
const override;

/// Run the algorithm
///
/// @param track_states the container of the fitted track parameters
/// @param selected_indexes output (if != nullptr) for the selected track
/// indexes
/// @return the container without ambiguous tracks
track_state_container_types::host operator()(
const typename track_state_container_types::host& track_states,
std::vector<std::size_t>* selected_indexes) const;

private:
/// Computes the initial state for the input data. This function accumulates
/// information that will later be used to accelerate the ambiguity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ struct logger {
/// @return the container without ambiguous tracks
track_state_container_types::host
greedy_ambiguity_resolution_algorithm::operator()(
const typename track_state_container_types::host& track_states) const {
const typename track_state_container_types::host& track_states,
std::vector<std::size_t>* selected_indexes) const {

state_t state;
compute_initial_state(track_states, state);
Expand Down Expand Up @@ -121,9 +122,25 @@ greedy_ambiguity_resolution_algorithm::operator()(

res.push_back(header, states);
}

// Outputs the indexes (in the original container) of the selected tracks
if (selected_indexes != nullptr) {
selected_indexes->resize(0);
selected_indexes->reserve(state.selected_tracks.size());
for (std::size_t track_index : state.selected_tracks) {
selected_indexes->push_back(track_index);
}
}
return res;
}

track_state_container_types::host
greedy_ambiguity_resolution_algorithm::operator()(
const typename track_state_container_types::host& track_states) const {

return operator()(track_states, nullptr);
}

void greedy_ambiguity_resolution_algorithm::compute_initial_state(
const typename track_state_container_types::host& track_states,
state_t& state) const {
Expand Down
4 changes: 4 additions & 0 deletions examples/options/include/traccc/options/performance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class performance : public interface {
/// Whether to run performance checks
bool run = false;

/// Whether to run verbose performance checks (ROOT is not needed) and print
/// valid/duplicate/false tracks metrics on the terminal.
bool print_performance = false;

/// @}

/// Constructor
Expand Down
8 changes: 8 additions & 0 deletions examples/options/src/performance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ performance::performance() : interface("Performance Measurement Options") {
m_desc.add_options()("check-performance",
boost::program_options::bool_switch(&run),
"Run performance checks");

m_desc.add_options()(
"print-performance",
boost::program_options::bool_switch(&print_performance),
"Print small performance metrics on the terminal "
"(valid/duplicate/fake tracks statistics)");
}

std::ostream& performance::print_impl(std::ostream& out) const {

out << " Run performance checks: " << (run ? "yes" : "no");
out << " Print performance metrics: "
<< (print_performance ? "yes" : "no");
return out;
}

Expand Down
81 changes: 65 additions & 16 deletions examples/run/cpu/seeding_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// performance
#include "traccc/efficiency/finding_performance_writer.hpp"
#include "traccc/efficiency/seeding_performance_writer.hpp"
#include "traccc/efficiency/verbose_performance_metrics.hpp"
#include "traccc/resolution/fitting_performance_writer.hpp"

// options
Expand Down Expand Up @@ -91,6 +92,13 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
ar_writer_cfg.algorithm_name = "ambiguity_resolution";
traccc::finding_performance_writer ar_performance_writer(ar_writer_cfg);

// Verbose performance metrics
traccc::details::verbose_performance_metrics find_metrics(false, "finding");
traccc::details::verbose_performance_metrics fit_metrics(false, "fitting");
traccc::details::verbose_performance_metrics ar_metrics(true);
traccc::details::verbose_performance_metrics ar_metrics_chk(
false, "ambiguity resolution (check v2)");

// Output stats
uint64_t n_spacepoints = 0;
uint64_t n_measurements = 0;
Expand Down Expand Up @@ -157,6 +165,7 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
traccc::fitting_algorithm<host_fitter_type> host_fitting(fit_cfg);

traccc::greedy_ambiguity_resolution_algorithm host_ambiguity_resolution{};
std::vector<std::size_t> host_ambiguity_resolution_si; // selected indexes

// Loop over events
for (std::size_t event = input_opts.skip;
Expand Down Expand Up @@ -215,7 +224,14 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
-----------------------------------------*/

if (resolution_opts.run) {
track_states_ar = host_ambiguity_resolution(track_states);
if (performance_opts.run) {
// Also gets the selected_track_indexes if we should run the
// performance analysis
track_states_ar = host_ambiguity_resolution(
track_states, &host_ambiguity_resolution_si);
} else {
track_states_ar = host_ambiguity_resolution(track_states);
}
n_ambiguity_free_tracks += track_states_ar.size();
}

Expand All @@ -230,30 +246,44 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
Writer
------------*/

if (performance_opts.run) {
if (performance_opts.run || performance_opts.print_performance) {

traccc::event_map2 evt_map(event, input_opts.directory,
input_opts.directory,
input_opts.directory);
sd_performance_writer.write(vecmem::get_data(seeds),
vecmem::get_data(spacepoints_per_event),
evt_map);

find_performance_writer.write(traccc::get_data(track_candidates),
evt_map);
// Performance writers
if (performance_opts.run) {
sd_performance_writer.write(
vecmem::get_data(seeds),
vecmem::get_data(spacepoints_per_event), evt_map);

if (resolution_opts.run) {
ar_performance_writer.write(traccc::get_data(track_states_ar),
evt_map);
}
find_performance_writer.write(
traccc::get_data(track_candidates), evt_map);

if (resolution_opts.run) {
ar_performance_writer.write(
traccc::get_data(track_states_ar), evt_map);
}

for (unsigned int i = 0; i < track_states.size(); i++) {
const auto& trk_states_per_track = track_states.at(i).items;

for (unsigned int i = 0; i < track_states.size(); i++) {
const auto& trk_states_per_track = track_states.at(i).items;
const auto& fit_res = track_states[i].header;

const auto& fit_res = track_states[i].header;
fit_performance_writer.write(trk_states_per_track, fit_res,
host_det, evt_map);
}
}

fit_performance_writer.write(trk_states_per_track, fit_res,
host_det, evt_map);
if (performance_opts.print_performance) {
if (resolution_opts.run) {
ar_metrics.ambiguity_resolution(
track_states, host_ambiguity_resolution_si, evt_map);
}
ar_metrics_chk.generic(track_states_ar, evt_map);
find_metrics.generic(track_candidates, evt_map);
fit_metrics.generic(track_states, evt_map);
}
}
}
Expand Down Expand Up @@ -283,6 +313,25 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
std::cout << "- ambiguity resolution: deactivated" << std::endl;
}

if (performance_opts.print_performance) {
std::cout << "\nPerformance metrics:\n\n";
// Finding
find_metrics.print(std::cout);
std::cout << "\n";
// Fitting
fit_metrics.print(std::cout);
std::cout << "\n";
// Ambiguity resolution
if (resolution_opts.run) {
ar_metrics.print(std::cout);
std::cout << "\n";
}
// Check for ambiguity resolution (should have the same results compared
// to the "selected tracks" of ar_metrics)
ar_metrics_chk.print(std::cout);
std::cout << "\n";
}

return EXIT_SUCCESS;
}

Expand Down
2 changes: 2 additions & 0 deletions performance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ traccc_add_library( traccc_performance performance TYPE SHARED
"src/efficiency/seeding_performance_writer.cpp"
"include/traccc/efficiency/finding_performance_writer.hpp"
"src/efficiency/finding_performance_writer.cpp"
"include/traccc/efficiency/verbose_performance_metrics.hpp"
"src/efficiency/verbose_performance_metrics.cpp"
"src/efficiency/track_classification.hpp"
"include/traccc/efficiency/nseed_performance_writer.hpp"
"src/efficiency/nseed_performance_writer.cpp"
Expand Down
108 changes: 108 additions & 0 deletions performance/include/traccc/efficiency/verbose_performance_metrics.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2023 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Local include(s).
#include "traccc/utils/helpers.hpp"

// Project include(s).
#include "traccc/edm/track_candidate.hpp"
#include "traccc/edm/track_state.hpp"
#include "traccc/io/event_map2.hpp"

// System include(s).
#include <cmath>
#include <memory>
#include <sstream>

// All in the header file, then will be split.

namespace traccc {
namespace details {

struct verbose_performance_metrics {

verbose_performance_metrics(bool is_ambiguity_resolution_,
const std::string& algorithm_name_ = "")
: algorithm_name(algorithm_name_),
is_ambiguity_resolution(is_ambiguity_resolution_) {}

/**
* @brief
*
* @param all_tracks Measurements for each track
* @param selected_tracks Indexes of the tracks selected by the ambiguity
* resolution algorithm
*/
void ambiguity_resolution(
std::vector<std::vector<measurement>> const& all_tracks,
const std::vector<std::size_t>& selected_tracks,
const event_map2& evt_map);

void ambiguity_resolution(
const track_state_container_types::host& all_tracks,
const std::vector<std::size_t>& selected_tracks,
const event_map2& evt_map);

void generic(const track_candidate_container_types::host& all_tracks,
const event_map2& evt_map);

void generic(const track_state_container_types::host& all_tracks,
const event_map2& evt_map);

void generic(const std::vector<std::vector<measurement>>& all_tracks,
const event_map2& evt_map);

std::ostream& print(std::ostream& os);

// For seeding, finding, and fitting algorithms
struct item_t {
std::size_t valid = 0, duplicate = 0, fake = 0;

// Values computed by compute_percentages
std::size_t valid_p = 0, duplicate_p = 0, fake_p = 0;

void compute_percentages() {
double total = valid + duplicate + fake;
if (total > 0) {
valid_p = std::round(100 * valid / total);
duplicate_p = std::round(100 * duplicate / total);
fake_p = std::round(100 * fake / total);
} else {
valid_p = 0;
duplicate_p = 0;
fake_p = 0;
}
}
};

// Only for ambiguity resolution algorithm
struct ar_t {
// Among selected tracks
item_t selected;

// std::size_t sel_valid = 0, sel_duplicate = 0, sel_fake = 0;
// Among evicted tracks
item_t evicted;
// std::size_t del_valid = 0, del_duplicate = 0, del_fake = 0;

// The number of times the ambiguity_resolution function was called
std::size_t call_count = 0;
// The sum of the results quality for valid tracks
double valid_quality_sum = 0;
};

private:
ar_t ar_metrics;
item_t gen_metrics;
std::string algorithm_name;
bool is_ambiguity_resolution;
// std::size_t call_count = 0;
};
} // namespace details
} // namespace traccc
Loading
Loading