-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
155 lines (115 loc) · 4.47 KB
/
main.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
#include <iomanip>
#include <iostream>
#include <limits>
#include <fstream>
#include <vector>
#include "ITSReconstruction/CA/Definitions.h"
#include "ITSReconstruction/CA/IOUtils.h"
#include "ITSReconstruction/CA/Tracker.h"
#if defined HAVE_VALGRIND
# include <valgrind/callgrind.h>
#endif
#if TRACKINGITSU_GPU_MODE
# include "ITSReconstruction/CA/gpu/Utils.h"
#endif
using namespace o2::ITS::CA;
std::string getDirectory(const std::string& fname)
{
size_t pos = fname.find_last_of("\\/");
return (std::string::npos == pos) ? "" : fname.substr(0, pos + 1);
}
int main(int argc, char** argv)
{
if (argv[1] == NULL) {
std::cerr << "Please, provide a data file." << std::endl;
exit(EXIT_FAILURE);
}
std::string eventsFileName(argv[1]);
std::string benchmarkFolderName = getDirectory(eventsFileName);
std::vector<Event> events = IOUtils::loadEventData(eventsFileName);
const int eventsNum = events.size();
std::vector<std::unordered_map<int, Label>> labelsMap;
bool createBenchmarkData = false;
std::ofstream correctRoadsOutputStream;
std::ofstream duplicateRoadsOutputStream;
std::ofstream fakeRoadsOutputStream;
int verticesNum = 0;
for (int iEvent = 0; iEvent < eventsNum; ++iEvent) {
verticesNum += events[iEvent].getPrimaryVerticesNum();
}
if (argv[2] != NULL) {
std::string labelsFileName(argv[2]);
createBenchmarkData = true;
labelsMap = IOUtils::loadLabels(eventsNum, labelsFileName);
correctRoadsOutputStream.open(benchmarkFolderName + "CorrectRoads.txt");
duplicateRoadsOutputStream.open(benchmarkFolderName + "DuplicateRoads.txt");
fakeRoadsOutputStream.open(benchmarkFolderName + "FakeRoads.txt");
}
clock_t t1, t2;
float totalTime = 0.f, minTime = std::numeric_limits<float>::max(), maxTime = -1;
#if defined MEMORY_BENCHMARK
std::ofstream memoryBenchmarkOutputStream;
memoryBenchmarkOutputStream.open(benchmarkFolderName + "MemoryOccupancy.txt");
#elif defined TIME_BENCHMARK
std::ofstream timeBenchmarkOutputStream;
timeBenchmarkOutputStream.open(benchmarkFolderName + "TimeOccupancy.txt");
#endif
// Prevent cold cache benchmark noise
Tracker<TRACKINGITSU_GPU_MODE> tracker{};
tracker.clustersToTracks(events[0]);
#if defined GPU_PROFILING_MODE
o2::ITS::CA::GPU::Utils::Host::gpuStartProfiler();
#endif
for (size_t iEvent = 0; iEvent < events.size(); ++iEvent) {
Event& currentEvent = events[iEvent];
std::cout << "Processing event " << iEvent + 1 << std::endl;
t1 = clock();
#if defined HAVE_VALGRIND
// Run callgrind with --collect-atstart=no
CALLGRIND_TOGGLE_COLLECT;
#endif
try {
#if defined(MEMORY_BENCHMARK)
std::vector<std::vector<Road>> roads = tracker.clustersToTracksMemoryBenchmark(currentEvent, memoryBenchmarkOutputStream);
#elif defined(DEBUG)
std::vector<std::vector<Road>> roads = tracker.clustersToTracksVerbose(currentEvent);
#elif defined TIME_BENCHMARK
std::vector<std::vector<Road>> roads = tracker.clustersToTracksTimeBenchmark(currentEvent, timeBenchmarkOutputStream);
#else
std::vector<std::vector<Road>> roads = tracker.clustersToTracks(currentEvent);
#endif
#if defined HAVE_VALGRIND
CALLGRIND_TOGGLE_COLLECT;
#endif
t2 = clock();
const float diff = ((float) t2 - (float) t1) / (CLOCKS_PER_SEC / 1000);
totalTime += diff;
if (minTime > diff)
minTime = diff;
if (maxTime < diff)
maxTime = diff;
for(int iVertex = 0; iVertex < currentEvent.getPrimaryVerticesNum(); ++iVertex) {
std::cout << "Found " << roads[iVertex].size() << " roads for vertex " << iVertex + 1 << std::endl;
}
std::cout << "Event " << iEvent + 1 << " processed in: " << diff << "ms" << std::endl;
if(currentEvent.getPrimaryVerticesNum() > 1) {
std::cout << "Vertex processing mean time: " << diff / currentEvent.getPrimaryVerticesNum() << "ms" << std::endl;
}
std::cout << std::endl;
if (createBenchmarkData) {
IOUtils::writeRoadsReport(correctRoadsOutputStream, duplicateRoadsOutputStream, fakeRoadsOutputStream, roads,
labelsMap[iEvent]);
}
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
}
#if defined GPU_PROFILING_MODE
o2::ITS::CA::GPU::Utils::Host::gpuStopProfiler();
#endif
std::cout << std::endl;
std::cout << "Avg time: " << totalTime / verticesNum << "ms" << std::endl;
std::cout << "Min time: " << minTime << "ms" << std::endl;
std::cout << "Max time: " << maxTime << "ms" << std::endl;
return 0;
}