-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathccl_example.cpp
165 lines (129 loc) · 5.55 KB
/
ccl_example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2021-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
// Project include(s).
#include "traccc/clusterization/sparse_ccl_algorithm.hpp"
#include "traccc/edm/silicon_cell_collection.hpp"
#include "traccc/io/read_cells.hpp"
// VecMem include(s).
#include <vecmem/memory/host_memory_resource.hpp>
// System include(s).
#include <algorithm>
#include <chrono>
#include <iomanip>
#include <iostream>
namespace {
double delta_ms(std::chrono::high_resolution_clock::time_point s,
std::chrono::high_resolution_clock::time_point e) {
return static_cast<double>(
std::chrono::duration_cast<std::chrono::microseconds>(e - s)
.count()) /
1000.0;
}
} // namespace
void print_statistics(const traccc::edm::silicon_cell_collection::host& data) {
static std::vector<std::size_t> bins_edges = {
0, 1, 2, 3, 4, 6, 8, 11, 16,
23, 32, 45, 64, 91, 128, 181, 256, 362,
512, 724, 1024, 1448, 2048, 2896, 4096, 5793, 8192};
static std::size_t max_width = 50;
std::vector<std::size_t> bins(bins_edges.size());
unsigned int last = std::numeric_limits<unsigned int>::max();
std::size_t count = 0;
for (std::size_t i = 0; i < data.size(); ++i) {
if (last == data.module_index().at(i)) {
count++;
} else {
for (std::size_t j = 0; j < bins_edges.size(); ++j) {
if (count >= bins_edges[j] &&
(j + 1 >= bins_edges.size() || count < bins_edges[j + 1])) {
++bins[j];
break;
}
}
count = 1;
last = data.module_index().at(i);
}
}
std::size_t max = *std::max_element(bins.begin(), bins.end());
std::size_t per_pixel = std::max(static_cast<std::size_t>(1),
(max + (max % max_width)) / max_width);
std::cout << "\nNon-zero pixels per module" << std::endl;
std::cout << std::setw(5) << "Min"
<< " " << std::setw(5) << "Max"
<< " | " << std::setw(5) << "Count" << std::endl;
for (std::size_t i = 0; i < bins.size(); ++i) {
std::cout << std::setw(5) << bins_edges[i] << " - " << std::setw(5)
<< (i + 1 >= bins.size()
? "inf"
: std::to_string(bins_edges[i + 1] - 1))
<< " | " << std::setw(5) << bins[i] << " ";
for (std::size_t j = 0; j < bins[i]; j += per_pixel) {
std::cout << "*";
}
std::cout << std::endl;
}
}
void run_on_event(traccc::host::sparse_ccl_algorithm& cc,
traccc::edm::silicon_cell_collection::host& data) {
auto clusters = cc(vecmem::get_data(data));
}
int main(int argc, char* argv[]) {
std::unique_ptr<const traccc::Logger> ilogger = traccc::getDefaultLogger(
"TracccExampleCcl", traccc::Logging::Level::INFO);
TRACCC_LOCAL_LOGGER(std::move(ilogger));
if (argc < 2) {
TRACCC_FATAL("Not enough arguments, minimum requirement: "
<< argv[0] << " <event_file>");
return -1;
}
std::string event_file = std::string(argv[1]);
TRACCC_INFO("Running " << argv[0] << " on " << event_file);
vecmem::host_memory_resource mem;
traccc::host::sparse_ccl_algorithm cc(mem, logger().clone("SparseCclAlg"));
auto time_read_start = std::chrono::high_resolution_clock::now();
traccc::edm::silicon_cell_collection::host data(mem);
traccc::io::read_cells(data, event_file, logger().clone());
auto time_read_end = std::chrono::high_resolution_clock::now();
print_statistics(data);
auto time_process_p1 = std::chrono::high_resolution_clock::now();
run_on_event(cc, data);
auto time_process_p2 = std::chrono::high_resolution_clock::now();
for (std::size_t i = 0; i < 10; ++i) {
run_on_event(cc, data);
}
auto time_process_p3 = std::chrono::high_resolution_clock::now();
run_on_event(cc, data);
auto time_process_p4 = std::chrono::high_resolution_clock::now();
std::cout << "\nCPU budget allocation" << std::endl;
std::cout << std::fixed;
std::cout << std::setw(13) << "Component"
<< " | " << std::setw(13) << "Runtime" << std::endl;
std::cout << std::setw(13) << "Data loading"
<< " | " << std::setw(10) << std::setprecision(3)
<< delta_ms(time_read_start, time_read_end) << " ms" << std::endl;
std::cout << std::setw(13) << "Statistics"
<< " | " << std::setw(10) << std::setprecision(3)
<< delta_ms(time_read_end, time_process_p1) << " ms" << std::endl;
std::cout << std::setw(13) << "Cold run"
<< " | " << std::setw(10) << std::setprecision(3)
<< delta_ms(time_process_p1, time_process_p2) << " ms"
<< std::endl;
std::cout << std::setw(13) << "Heating"
<< " | " << std::setw(10) << std::setprecision(3)
<< delta_ms(time_process_p2, time_process_p3) << " ms"
<< std::endl;
std::cout << std::setw(13) << "Hot run"
<< " | " << std::setw(10) << std::setprecision(3)
<< delta_ms(time_process_p3, time_process_p4) << " ms"
<< std::endl;
std::cout << std::setw(13) << "Total"
<< " | " << std::setw(10) << std::setprecision(3)
<< delta_ms(time_read_start, time_process_p4) << " ms"
<< std::endl;
return 0;
}