forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrackerTraitsGPU.cxx
More file actions
341 lines (314 loc) · 17.1 KB
/
TrackerTraitsGPU.cxx
File metadata and controls
341 lines (314 loc) · 17.1 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
#include <array>
#include <unistd.h>
#include "DataFormatsITS/TrackITS.h"
#include "ITStrackingGPU/TrackerTraitsGPU.h"
#include "ITStrackingGPU/TrackingKernels.h"
#include "ITStracking/TrackingConfigParam.h"
namespace o2::its
{
constexpr int UnusedIndex{-1};
template <int nLayers>
void TrackerTraitsGPU<nLayers>::initialiseTimeFrame(const int iteration)
{
mTimeFrameGPU->initialise(iteration, mTrkParams[iteration], nLayers);
mTimeFrameGPU->loadClustersDevice(iteration);
mTimeFrameGPU->loadUnsortedClustersDevice(iteration);
mTimeFrameGPU->loadClustersIndexTables(iteration);
mTimeFrameGPU->loadTrackingFrameInfoDevice(iteration);
mTimeFrameGPU->loadMultiplicityCutMask(iteration);
mTimeFrameGPU->loadVertices(iteration);
mTimeFrameGPU->loadROframeClustersDevice(iteration);
mTimeFrameGPU->createUsedClustersDevice(iteration);
mTimeFrameGPU->loadIndexTableUtils(iteration);
}
template <int nLayers>
void TrackerTraitsGPU<nLayers>::computeLayerTracklets(const int iteration, int iROFslice, int iVertex)
{
auto& conf = o2::its::ITSGpuTrackingParamConfig::Instance();
mTimeFrameGPU->createTrackletsLUTDevice(iteration);
const Vertex diamondVert({mTrkParams[iteration].Diamond[0], mTrkParams[iteration].Diamond[1], mTrkParams[iteration].Diamond[2]}, {25.e-6f, 0.f, 0.f, 25.e-6f, 0.f, 36.f}, 1, 1.f);
gsl::span<const Vertex> diamondSpan(&diamondVert, 1);
int startROF{mTrkParams[iteration].nROFsPerIterations > 0 ? iROFslice * mTrkParams[iteration].nROFsPerIterations : 0};
int endROF{o2::gpu::CAMath::Min(mTrkParams[iteration].nROFsPerIterations > 0 ? (iROFslice + 1) * mTrkParams[iteration].nROFsPerIterations + mTrkParams[iteration].DeltaROF : mTimeFrameGPU->getNrof(), mTimeFrameGPU->getNrof())};
countTrackletsInROFsHandler<nLayers>(mTimeFrameGPU->getDeviceIndexTableUtils(),
mTimeFrameGPU->getDeviceMultCutMask(),
startROF,
endROF,
mTimeFrameGPU->getNrof(),
mTrkParams[iteration].DeltaROF,
iVertex,
mTimeFrameGPU->getDeviceVertices(),
mTimeFrameGPU->getDeviceROFramesPV(),
mTimeFrameGPU->getPrimaryVerticesNum(),
mTimeFrameGPU->getDeviceArrayClusters(),
mTimeFrameGPU->getClusterSizes(),
mTimeFrameGPU->getDeviceROframeClusters(),
mTimeFrameGPU->getDeviceArrayUsedClusters(),
mTimeFrameGPU->getDeviceArrayClustersIndexTables(),
mTimeFrameGPU->getDeviceArrayTrackletsLUT(),
mTimeFrameGPU->getDeviceTrackletsLUTs(), // Required for the exclusive sums
iteration,
mTrkParams[iteration].NSigmaCut,
mTimeFrameGPU->getPhiCuts(),
mTrkParams[iteration].PVres,
mTimeFrameGPU->getMinRs(),
mTimeFrameGPU->getMaxRs(),
mTimeFrameGPU->getPositionResolutions(),
mTrkParams[iteration].LayerRadii,
mTimeFrameGPU->getMSangles(),
conf.nBlocks,
conf.nThreads);
mTimeFrameGPU->createTrackletsBuffers();
computeTrackletsInROFsHandler<nLayers>(mTimeFrameGPU->getDeviceIndexTableUtils(),
mTimeFrameGPU->getDeviceMultCutMask(),
startROF,
endROF,
mTimeFrameGPU->getNrof(),
mTrkParams[iteration].DeltaROF,
iVertex,
mTimeFrameGPU->getDeviceVertices(),
mTimeFrameGPU->getDeviceROFramesPV(),
mTimeFrameGPU->getPrimaryVerticesNum(),
mTimeFrameGPU->getDeviceArrayClusters(),
mTimeFrameGPU->getClusterSizes(),
mTimeFrameGPU->getDeviceROframeClusters(),
mTimeFrameGPU->getDeviceArrayUsedClusters(),
mTimeFrameGPU->getDeviceArrayClustersIndexTables(),
mTimeFrameGPU->getDeviceArrayTracklets(),
mTimeFrameGPU->getDeviceTracklet(),
mTimeFrameGPU->getNTracklets(),
mTimeFrameGPU->getDeviceArrayTrackletsLUT(),
mTimeFrameGPU->getDeviceTrackletsLUTs(),
iteration,
mTrkParams[iteration].NSigmaCut,
mTimeFrameGPU->getPhiCuts(),
mTrkParams[iteration].PVres,
mTimeFrameGPU->getMinRs(),
mTimeFrameGPU->getMaxRs(),
mTimeFrameGPU->getPositionResolutions(),
mTrkParams[iteration].LayerRadii,
mTimeFrameGPU->getMSangles(),
conf.nBlocks,
conf.nThreads);
}
template <int nLayers>
void TrackerTraitsGPU<nLayers>::computeLayerCells(const int iteration)
{
mTimeFrameGPU->createCellsLUTDevice();
auto& conf = o2::its::ITSGpuTrackingParamConfig::Instance();
for (int iLayer = 0; iLayer < mTrkParams[iteration].CellsPerRoad(); ++iLayer) {
if (!mTimeFrameGPU->getNTracklets()[iLayer + 1] || !mTimeFrameGPU->getNTracklets()[iLayer]) {
continue;
}
const int currentLayerTrackletsNum{static_cast<int>(mTimeFrameGPU->getNTracklets()[iLayer])};
countCellsHandler(mTimeFrameGPU->getDeviceArrayClusters(),
mTimeFrameGPU->getDeviceArrayUnsortedClusters(),
mTimeFrameGPU->getDeviceArrayTrackingFrameInfo(),
mTimeFrameGPU->getDeviceArrayTracklets(),
mTimeFrameGPU->getDeviceArrayTrackletsLUT(),
mTimeFrameGPU->getNTracklets()[iLayer],
iLayer,
nullptr,
mTimeFrameGPU->getDeviceArrayCellsLUT(),
mTimeFrameGPU->getDeviceCellLUTs()[iLayer],
mBz,
mTrkParams[iteration].MaxChi2ClusterAttachment,
mTrkParams[iteration].CellDeltaTanLambdaSigma,
mTrkParams[iteration].NSigmaCut,
conf.nBlocks,
conf.nThreads);
mTimeFrameGPU->createCellsBuffers(iLayer);
computeCellsHandler(mTimeFrameGPU->getDeviceArrayClusters(),
mTimeFrameGPU->getDeviceArrayUnsortedClusters(),
mTimeFrameGPU->getDeviceArrayTrackingFrameInfo(),
mTimeFrameGPU->getDeviceArrayTracklets(),
mTimeFrameGPU->getDeviceArrayTrackletsLUT(),
mTimeFrameGPU->getNTracklets()[iLayer],
iLayer,
mTimeFrameGPU->getDeviceCells()[iLayer],
mTimeFrameGPU->getDeviceArrayCellsLUT(),
mTimeFrameGPU->getDeviceCellLUTs()[iLayer],
mBz,
mTrkParams[iteration].MaxChi2ClusterAttachment,
mTrkParams[iteration].CellDeltaTanLambdaSigma,
mTrkParams[iteration].NSigmaCut,
conf.nBlocks,
conf.nThreads);
}
}
template <int nLayers>
void TrackerTraitsGPU<nLayers>::findCellsNeighbours(const int iteration)
{
mTimeFrameGPU->createNeighboursIndexTablesDevice();
auto& conf = o2::its::ITSGpuTrackingParamConfig::Instance();
for (int iLayer{0}; iLayer < mTrkParams[iteration].CellsPerRoad() - 1; ++iLayer) {
const int nextLayerCellsNum{static_cast<int>(mTimeFrameGPU->getNCells()[iLayer + 1])};
if (!nextLayerCellsNum) {
continue;
}
mTimeFrameGPU->createNeighboursLUTDevice(iLayer, nextLayerCellsNum);
unsigned int nNeigh = countCellNeighboursHandler(mTimeFrameGPU->getDeviceArrayCells(),
mTimeFrameGPU->getDeviceNeighboursLUT(iLayer), // LUT is initialised here.
mTimeFrameGPU->getDeviceArrayCellsLUT(),
mTimeFrameGPU->getDeviceNeighbourPairs(iLayer),
mTimeFrameGPU->getDeviceNeighboursIndexTables(iLayer),
mTrkParams[0].MaxChi2ClusterAttachment,
mBz,
iLayer,
mTimeFrameGPU->getNCells()[iLayer],
nextLayerCellsNum,
1e2,
conf.nBlocks,
conf.nThreads);
mTimeFrameGPU->createNeighboursDevice(iLayer, nNeigh);
computeCellNeighboursHandler(mTimeFrameGPU->getDeviceArrayCells(),
mTimeFrameGPU->getDeviceNeighboursLUT(iLayer),
mTimeFrameGPU->getDeviceArrayCellsLUT(),
mTimeFrameGPU->getDeviceNeighbourPairs(iLayer),
mTimeFrameGPU->getDeviceNeighboursIndexTables(iLayer),
mTrkParams[0].MaxChi2ClusterAttachment,
mBz,
iLayer,
mTimeFrameGPU->getNCells()[iLayer],
nextLayerCellsNum,
1e2,
conf.nBlocks,
conf.nThreads);
filterCellNeighboursHandler(mTimeFrameGPU->getDeviceNeighbourPairs(iLayer),
mTimeFrameGPU->getDeviceNeighbours(iLayer),
nNeigh);
}
mTimeFrameGPU->createNeighboursDeviceArray();
mTimeFrameGPU->unregisterRest();
};
template <int nLayers>
void TrackerTraitsGPU<nLayers>::findRoads(const int iteration)
{
auto& conf = o2::its::ITSGpuTrackingParamConfig::Instance();
for (int startLevel{mTrkParams[iteration].CellsPerRoad()}; startLevel >= mTrkParams[iteration].CellMinimumLevel(); --startLevel) {
const int minimumLayer{startLevel - 1};
std::vector<CellSeed> trackSeeds;
for (int startLayer{mTrkParams[iteration].CellsPerRoad() - 1}; startLayer >= minimumLayer; --startLayer) {
if ((mTrkParams[iteration].StartLayerMask & (1 << (startLayer + 2))) == 0) {
continue;
}
processNeighboursHandler<nLayers>(startLayer,
startLevel,
mTimeFrameGPU->getDeviceArrayCells(),
mTimeFrameGPU->getDeviceCells()[startLayer],
mTimeFrameGPU->getArrayNCells(),
mTimeFrameGPU->getDeviceArrayUsedClusters(),
mTimeFrameGPU->getDeviceNeighboursAll(),
mTimeFrameGPU->getDeviceNeighboursLUTs(),
mTimeFrameGPU->getDeviceArrayTrackingFrameInfo(),
trackSeeds,
mBz,
mTrkParams[0].MaxChi2ClusterAttachment,
mTrkParams[0].MaxChi2NDF,
mTimeFrameGPU->getDevicePropagator(),
mCorrType,
conf.nBlocks,
conf.nThreads);
}
// fixme: I don't want to move tracks back and forth, but I need a way to use a thrust::allocator that is aware of our managed memory.
if (!trackSeeds.size()) {
LOGP(info, "No track seeds found, skipping track finding");
continue;
}
mTimeFrameGPU->createTrackITSExtDevice(trackSeeds);
mTimeFrameGPU->loadTrackSeedsDevice(trackSeeds);
trackSeedHandler(mTimeFrameGPU->getDeviceTrackSeeds(), // CellSeed* trackSeeds
mTimeFrameGPU->getDeviceArrayTrackingFrameInfo(), // TrackingFrameInfo** foundTrackingFrameInfo
mTimeFrameGPU->getDeviceTrackITSExt(), // o2::its::TrackITSExt* tracks
mTrkParams[iteration].MinPt, // std::vector<float>& minPtsHost,
trackSeeds.size(), // const size_t nSeeds
mBz, // const float Bz
startLevel, // const int startLevel,
mTrkParams[0].MaxChi2ClusterAttachment, // float maxChi2ClusterAttachment
mTrkParams[0].MaxChi2NDF, // float maxChi2NDF
mTimeFrameGPU->getDevicePropagator(), // const o2::base::Propagator* propagator
mCorrType, // o2::base::PropagatorImpl<float>::MatCorrType
conf.nBlocks,
conf.nThreads);
mTimeFrameGPU->downloadTrackITSExtDevice(trackSeeds);
auto& tracks = mTimeFrameGPU->getTrackITSExt();
for (auto& track : tracks) {
if (!track.getChi2()) {
continue; // this is to skip the unset tracks that are put at the beginning of the vector by the sorting. To see if this can be optimised.
}
int nShared = 0;
bool isFirstShared{false};
for (int iLayer{0}; iLayer < mTrkParams[0].NLayers; ++iLayer) {
if (track.getClusterIndex(iLayer) == UnusedIndex) {
continue;
}
nShared += int(mTimeFrameGPU->isClusterUsed(iLayer, track.getClusterIndex(iLayer)));
isFirstShared |= !iLayer && mTimeFrameGPU->isClusterUsed(iLayer, track.getClusterIndex(iLayer));
}
if (nShared > mTrkParams[0].ClusterSharing) {
continue;
}
std::array<int, 3> rofs{INT_MAX, INT_MAX, INT_MAX};
for (int iLayer{0}; iLayer < mTrkParams[0].NLayers; ++iLayer) {
if (track.getClusterIndex(iLayer) == UnusedIndex) {
continue;
}
mTimeFrameGPU->markUsedCluster(iLayer, track.getClusterIndex(iLayer));
int currentROF = mTimeFrameGPU->getClusterROF(iLayer, track.getClusterIndex(iLayer));
for (int iR{0}; iR < 3; ++iR) {
if (rofs[iR] == INT_MAX) {
rofs[iR] = currentROF;
}
if (rofs[iR] == currentROF) {
break;
}
}
}
if (rofs[2] != INT_MAX) {
continue;
}
if (rofs[1] != INT_MAX) {
track.setNextROFbit();
}
mTimeFrameGPU->getTracks(std::min(rofs[0], rofs[1])).emplace_back(track);
}
mTimeFrameGPU->loadUsedClustersDevice();
}
if (iteration == mTrkParams.size() - 1) {
mTimeFrameGPU->unregisterHostMemory(0);
}
};
template <int nLayers>
int TrackerTraitsGPU<nLayers>::getTFNumberOfClusters() const
{
return mTimeFrameGPU->getNumberOfClusters();
}
template <int nLayers>
int TrackerTraitsGPU<nLayers>::getTFNumberOfTracklets() const
{
return std::accumulate(mTimeFrameGPU->getNTracklets().begin(), mTimeFrameGPU->getNTracklets().end(), 0);
}
template <int nLayers>
int TrackerTraitsGPU<nLayers>::getTFNumberOfCells() const
{
return mTimeFrameGPU->getNumberOfCells();
}
template <int nLayers>
void TrackerTraitsGPU<nLayers>::setBz(float bz)
{
mBz = bz;
mTimeFrameGPU->setBz(bz);
}
template class TrackerTraitsGPU<7>;
} // namespace o2::its