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
425 lines (396 loc) · 22.3 KB
/
TrackerTraitsGPU.cxx
File metadata and controls
425 lines (396 loc) · 22.3 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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
// 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 <vector>
#include <unistd.h>
#include "DataFormatsITS/TrackITS.h"
#include "ITStrackingGPU/TrackerTraitsGPU.h"
#include "ITStrackingGPU/TrackingKernels.h"
#include "ITStracking/TrackingConfigParam.h"
#include "ITStracking/Constants.h"
namespace o2::its
{
template <int nLayers>
void TrackerTraitsGPU<nLayers>::initialiseTimeFrame(const int iteration)
{
mTimeFrameGPU->initialise(iteration, this->mTrkParams[iteration], nLayers);
// on default stream
mTimeFrameGPU->loadVertices(iteration);
mTimeFrameGPU->loadIndexTableUtils(iteration);
mTimeFrameGPU->loadMultiplicityCutMask(iteration);
// pinned on host
mTimeFrameGPU->createUsedClustersDeviceArray(iteration);
mTimeFrameGPU->createClustersDeviceArray(iteration);
mTimeFrameGPU->createUnsortedClustersDeviceArray(iteration);
mTimeFrameGPU->createClustersIndexTablesArray(iteration);
mTimeFrameGPU->createTrackingFrameInfoDeviceArray(iteration);
mTimeFrameGPU->createROFrameClustersDeviceArray(iteration);
// device array
mTimeFrameGPU->createTrackletsLUTDeviceArray(iteration);
mTimeFrameGPU->createTrackletsBuffersArray(iteration);
mTimeFrameGPU->createCellsBuffersArray(iteration);
mTimeFrameGPU->createCellsLUTDeviceArray(iteration);
// push every create artefact on the stack
mTimeFrameGPU->pushMemoryStack(iteration);
}
template <int nLayers>
void TrackerTraitsGPU<nLayers>::adoptTimeFrame(TimeFrame<nLayers>* tf)
{
mTimeFrameGPU = static_cast<gpu::TimeFrameGPU<nLayers>*>(tf);
this->mTimeFrame = static_cast<TimeFrame<nLayers>*>(tf);
}
template <int nLayers>
void TrackerTraitsGPU<nLayers>::computeLayerTracklets(const int iteration, int iROFslice, int iVertex)
{
const auto& conf = o2::its::ITSGpuTrackingParamConfig::Instance();
int startROF{0};
int endROF{mTimeFrameGPU->getNrof()};
// start by queuing loading needed of two last layers
for (int iLayer{nLayers}; iLayer-- > nLayers - 2;) {
mTimeFrameGPU->createUsedClustersDevice(iteration, iLayer);
mTimeFrameGPU->loadClustersDevice(iteration, iLayer);
mTimeFrameGPU->loadClustersIndexTables(iteration, iLayer);
mTimeFrameGPU->loadROFrameClustersDevice(iteration, iLayer);
mTimeFrameGPU->recordEvent(iLayer);
}
for (int iLayer{this->mTrkParams[iteration].TrackletsPerRoad()}; iLayer--;) {
if (iLayer) { // queue loading data of next layer in parallel, this the copies are overlapping with computation kernels
mTimeFrameGPU->createUsedClustersDevice(iteration, iLayer - 1);
mTimeFrameGPU->loadClustersDevice(iteration, iLayer - 1);
mTimeFrameGPU->loadClustersIndexTables(iteration, iLayer - 1);
mTimeFrameGPU->loadROFrameClustersDevice(iteration, iLayer - 1);
mTimeFrameGPU->recordEvent(iLayer - 1);
}
mTimeFrameGPU->createTrackletsLUTDevice(iteration, iLayer);
mTimeFrameGPU->waitEvent(iLayer, iLayer + 1); // wait stream until all data is available
countTrackletsInROFsHandler<nLayers>(mTimeFrameGPU->getDeviceIndexTableUtils(),
mTimeFrameGPU->getDeviceMultCutMask(),
iLayer,
startROF,
endROF,
mTimeFrameGPU->getNrof(),
this->mTrkParams[iteration].DeltaROF,
iVertex,
mTimeFrameGPU->getDeviceVertices(),
mTimeFrameGPU->getDeviceROFramesPV(),
mTimeFrameGPU->getPrimaryVerticesNum(),
mTimeFrameGPU->getDeviceArrayClusters(),
mTimeFrameGPU->getClusterSizes(),
mTimeFrameGPU->getDeviceROFrameClusters(),
(const uint8_t**)mTimeFrameGPU->getDeviceArrayUsedClusters(),
mTimeFrameGPU->getDeviceArrayClustersIndexTables(),
mTimeFrameGPU->getDeviceArrayTrackletsLUT(),
mTimeFrameGPU->getDeviceTrackletsLUTs(),
iteration,
this->mTrkParams[iteration].NSigmaCut,
mTimeFrameGPU->getPhiCuts(),
this->mTrkParams[iteration].PVres,
mTimeFrameGPU->getMinRs(),
mTimeFrameGPU->getMaxRs(),
mTimeFrameGPU->getPositionResolutions(),
this->mTrkParams[iteration].LayerRadii,
mTimeFrameGPU->getMSangles(),
mTimeFrameGPU->getFrameworkAllocator(),
conf.nBlocksLayerTracklets[iteration],
conf.nThreadsLayerTracklets[iteration],
mTimeFrameGPU->getStreams());
mTimeFrameGPU->createTrackletsBuffers(iLayer);
if (mTimeFrameGPU->getNTracklets()[iLayer] == 0) {
continue;
}
computeTrackletsInROFsHandler<nLayers>(mTimeFrameGPU->getDeviceIndexTableUtils(),
mTimeFrameGPU->getDeviceMultCutMask(),
iLayer,
startROF,
endROF,
mTimeFrameGPU->getNrof(),
this->mTrkParams[iteration].DeltaROF,
iVertex,
mTimeFrameGPU->getDeviceVertices(),
mTimeFrameGPU->getDeviceROFramesPV(),
mTimeFrameGPU->getPrimaryVerticesNum(),
mTimeFrameGPU->getDeviceArrayClusters(),
mTimeFrameGPU->getClusterSizes(),
mTimeFrameGPU->getDeviceROFrameClusters(),
(const uint8_t**)mTimeFrameGPU->getDeviceArrayUsedClusters(),
mTimeFrameGPU->getDeviceArrayClustersIndexTables(),
mTimeFrameGPU->getDeviceArrayTracklets(),
mTimeFrameGPU->getDeviceTracklets(),
mTimeFrameGPU->getNTracklets(),
mTimeFrameGPU->getDeviceArrayTrackletsLUT(),
mTimeFrameGPU->getDeviceTrackletsLUTs(),
iteration,
this->mTrkParams[iteration].NSigmaCut,
mTimeFrameGPU->getPhiCuts(),
this->mTrkParams[iteration].PVres,
mTimeFrameGPU->getMinRs(),
mTimeFrameGPU->getMaxRs(),
mTimeFrameGPU->getPositionResolutions(),
this->mTrkParams[iteration].LayerRadii,
mTimeFrameGPU->getMSangles(),
mTimeFrameGPU->getFrameworkAllocator(),
conf.nBlocksLayerTracklets[iteration],
conf.nThreadsLayerTracklets[iteration],
mTimeFrameGPU->getStreams());
}
}
template <int nLayers>
void TrackerTraitsGPU<nLayers>::computeLayerCells(const int iteration)
{
auto& conf = o2::its::ITSGpuTrackingParamConfig::Instance();
// start by queuing loading needed of three last layers
for (int iLayer{nLayers}; iLayer-- > nLayers - 3;) {
mTimeFrameGPU->loadUnsortedClustersDevice(iteration, iLayer);
mTimeFrameGPU->loadTrackingFrameInfoDevice(iteration, iLayer);
mTimeFrameGPU->recordEvent(iLayer);
}
for (int iLayer{this->mTrkParams[iteration].CellsPerRoad()}; iLayer--;) {
if (iLayer) {
mTimeFrameGPU->loadUnsortedClustersDevice(iteration, iLayer - 1);
mTimeFrameGPU->loadTrackingFrameInfoDevice(iteration, iLayer - 1);
mTimeFrameGPU->recordEvent(iLayer - 1);
}
// if there are no tracklets skip entirely
const int currentLayerTrackletsNum{static_cast<int>(mTimeFrameGPU->getNTracklets()[iLayer])};
if (!currentLayerTrackletsNum || !mTimeFrameGPU->getNTracklets()[iLayer + 1]) {
mTimeFrameGPU->getNCells()[iLayer] = 0;
continue;
}
mTimeFrameGPU->createCellsLUTDevice(iLayer);
mTimeFrameGPU->waitEvent(iLayer, iLayer + 1); // wait stream until all data is available
mTimeFrameGPU->waitEvent(iLayer, iLayer + 2); // wait stream until all data is available
countCellsHandler<nLayers>(mTimeFrameGPU->getDeviceArrayClusters(),
mTimeFrameGPU->getDeviceArrayUnsortedClusters(),
mTimeFrameGPU->getDeviceArrayTrackingFrameInfo(),
mTimeFrameGPU->getDeviceArrayTracklets(),
mTimeFrameGPU->getDeviceArrayTrackletsLUT(),
currentLayerTrackletsNum,
iLayer,
nullptr,
mTimeFrameGPU->getDeviceArrayCellsLUT(),
mTimeFrameGPU->getDeviceCellLUTs()[iLayer],
this->mTrkParams[iteration].DeltaROF,
this->mBz,
this->mTrkParams[iteration].MaxChi2ClusterAttachment,
this->mTrkParams[iteration].CellDeltaTanLambdaSigma,
this->mTrkParams[iteration].NSigmaCut,
mTimeFrameGPU->getFrameworkAllocator(),
conf.nBlocksLayerCells[iteration],
conf.nThreadsLayerCells[iteration],
mTimeFrameGPU->getStreams());
mTimeFrameGPU->createCellsBuffers(iLayer);
if (mTimeFrameGPU->getNCells()[iLayer] == 0) {
continue;
}
computeCellsHandler<nLayers>(mTimeFrameGPU->getDeviceArrayClusters(),
mTimeFrameGPU->getDeviceArrayUnsortedClusters(),
mTimeFrameGPU->getDeviceArrayTrackingFrameInfo(),
mTimeFrameGPU->getDeviceArrayTracklets(),
mTimeFrameGPU->getDeviceArrayTrackletsLUT(),
currentLayerTrackletsNum,
iLayer,
mTimeFrameGPU->getDeviceCells()[iLayer],
mTimeFrameGPU->getDeviceArrayCellsLUT(),
mTimeFrameGPU->getDeviceCellLUTs()[iLayer],
this->mTrkParams[iteration].DeltaROF,
this->mBz,
this->mTrkParams[iteration].MaxChi2ClusterAttachment,
this->mTrkParams[iteration].CellDeltaTanLambdaSigma,
this->mTrkParams[iteration].NSigmaCut,
conf.nBlocksLayerCells[iteration],
conf.nThreadsLayerCells[iteration],
mTimeFrameGPU->getStreams());
}
}
template <int nLayers>
void TrackerTraitsGPU<nLayers>::findCellsNeighbours(const int iteration)
{
const auto& conf = o2::its::ITSGpuTrackingParamConfig::Instance();
for (int iLayer{0}; iLayer < this->mTrkParams[iteration].NeighboursPerRoad(); ++iLayer) {
const int currentLayerCellsNum{static_cast<int>(mTimeFrameGPU->getNCells()[iLayer])};
const int nextLayerCellsNum{static_cast<int>(mTimeFrameGPU->getNCells()[iLayer + 1])};
if (!nextLayerCellsNum || !currentLayerCellsNum) {
mTimeFrameGPU->getNNeighbours()[iLayer] = 0;
continue;
}
mTimeFrameGPU->createNeighboursIndexTablesDevice(iLayer);
mTimeFrameGPU->createNeighboursLUTDevice(iLayer, nextLayerCellsNum);
countCellNeighboursHandler<nLayers>(mTimeFrameGPU->getDeviceArrayCells(),
mTimeFrameGPU->getDeviceNeighboursLUT(iLayer), // LUT is initialised here.
mTimeFrameGPU->getDeviceArrayCellsLUT(),
mTimeFrameGPU->getDeviceNeighbourPairs(iLayer),
mTimeFrameGPU->getDeviceNeighboursIndexTables(iLayer),
(const Tracklet**)mTimeFrameGPU->getDeviceArrayTracklets(),
this->mTrkParams[0].DeltaROF,
this->mTrkParams[0].MaxChi2ClusterAttachment,
this->mBz,
iLayer,
currentLayerCellsNum,
nextLayerCellsNum,
1e2,
mTimeFrameGPU->getFrameworkAllocator(),
conf.nBlocksFindNeighbours[iteration],
conf.nThreadsFindNeighbours[iteration],
mTimeFrameGPU->getStream(iLayer));
mTimeFrameGPU->createNeighboursDevice(iLayer);
if (mTimeFrameGPU->getNNeighbours()[iLayer] == 0) {
continue;
}
computeCellNeighboursHandler<nLayers>(mTimeFrameGPU->getDeviceArrayCells(),
mTimeFrameGPU->getDeviceNeighboursLUT(iLayer),
mTimeFrameGPU->getDeviceArrayCellsLUT(),
mTimeFrameGPU->getDeviceNeighbourPairs(iLayer),
mTimeFrameGPU->getDeviceNeighboursIndexTables(iLayer),
(const Tracklet**)mTimeFrameGPU->getDeviceArrayTracklets(),
this->mTrkParams[0].DeltaROF,
this->mTrkParams[0].MaxChi2ClusterAttachment,
this->mBz,
iLayer,
currentLayerCellsNum,
nextLayerCellsNum,
1e2,
conf.nBlocksFindNeighbours[iteration],
conf.nThreadsFindNeighbours[iteration],
mTimeFrameGPU->getStream(iLayer));
mTimeFrameGPU->getArrayNNeighbours()[iLayer] = filterCellNeighboursHandler(mTimeFrameGPU->getDeviceNeighbourPairs(iLayer),
mTimeFrameGPU->getDeviceNeighbours(iLayer),
mTimeFrameGPU->getArrayNNeighbours()[iLayer],
mTimeFrameGPU->getStream(iLayer),
mTimeFrameGPU->getFrameworkAllocator());
}
mTimeFrameGPU->syncStreams(false);
}
template <int nLayers>
void TrackerTraitsGPU<nLayers>::findRoads(const int iteration)
{
auto& conf = o2::its::ITSGpuTrackingParamConfig::Instance();
for (int startLevel{this->mTrkParams[iteration].CellsPerRoad()}; startLevel >= this->mTrkParams[iteration].CellMinimumLevel(); --startLevel) {
const int minimumLayer{startLevel - 1};
bounded_vector<CellSeed<nLayers>> trackSeeds(this->getMemoryPool().get());
for (int startLayer{this->mTrkParams[iteration].CellsPerRoad() - 1}; startLayer >= minimumLayer; --startLayer) {
if ((this->mTrkParams[iteration].StartLayerMask & (1 << (startLayer + 2))) == 0) {
continue;
}
processNeighboursHandler<nLayers>(startLayer,
startLevel,
mTimeFrameGPU->getDeviceArrayCells(),
mTimeFrameGPU->getDeviceCells()[startLayer],
mTimeFrameGPU->getArrayNCells(),
(const uint8_t**)mTimeFrameGPU->getDeviceArrayUsedClusters(),
mTimeFrameGPU->getDeviceNeighboursAll(),
mTimeFrameGPU->getDeviceNeighboursLUTs(),
mTimeFrameGPU->getDeviceArrayTrackingFrameInfo(),
trackSeeds,
this->mBz,
this->mTrkParams[0].MaxChi2ClusterAttachment,
this->mTrkParams[0].MaxChi2NDF,
mTimeFrameGPU->getDevicePropagator(),
this->mTrkParams[0].CorrType,
mTimeFrameGPU->getFrameworkAllocator(),
conf.nBlocksProcessNeighbours[iteration],
conf.nThreadsProcessNeighbours[iteration]);
}
// 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.empty()) {
LOGP(debug, "No track seeds found, skipping track finding");
continue;
}
mTimeFrameGPU->createTrackITSExtDevice(trackSeeds);
mTimeFrameGPU->loadTrackSeedsDevice(trackSeeds);
trackSeedHandler(mTimeFrameGPU->getDeviceTrackSeeds(), // CellSeed*
mTimeFrameGPU->getDeviceArrayTrackingFrameInfo(), // TrackingFrameInfo**
mTimeFrameGPU->getDeviceArrayUnsortedClusters(), // Cluster**
mTimeFrameGPU->getDeviceTrackITSExt(), // o2::its::TrackITSExt*
this->mTrkParams[iteration].LayerRadii, // const std::vector<float>&
this->mTrkParams[iteration].MinPt, // const std::vector<float>&
trackSeeds.size(), // const size_t nSeeds
this->mBz, // const float Bz
startLevel, // const int startLevel,
this->mTrkParams[0].MaxChi2ClusterAttachment, // float maxChi2ClusterAttachment
this->mTrkParams[0].MaxChi2NDF, // float maxChi2NDF
this->mTrkParams[0].RepeatRefitOut,
this->mTrkParams[0].ReseedIfShorter,
this->mTrkParams[0].ShiftRefToCluster,
mTimeFrameGPU->getDevicePropagator(), // const o2::base::Propagator* propagator
this->mTrkParams[0].CorrType, // o2::base::PropagatorImpl<float>::MatCorrType
conf.nBlocksTracksSeeds[iteration],
conf.nThreadsTracksSeeds[iteration]);
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 < this->mTrkParams[0].NLayers; ++iLayer) {
if (track.getClusterIndex(iLayer) == constants::UnusedIndex) {
continue;
}
nShared += int(mTimeFrameGPU->isClusterUsed(iLayer, track.getClusterIndex(iLayer)));
isFirstShared |= !iLayer && mTimeFrameGPU->isClusterUsed(iLayer, track.getClusterIndex(iLayer));
}
if (nShared > this->mTrkParams[0].ClusterSharing) {
continue;
}
std::array<int, 3> rofs{INT_MAX, INT_MAX, INT_MAX};
for (int iLayer{0}; iLayer < this->mTrkParams[0].NLayers; ++iLayer) {
if (track.getClusterIndex(iLayer) == constants::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();
}
// wipe the artefact memory
mTimeFrameGPU->popMemoryStack(iteration);
};
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)
{
this->mBz = bz;
mTimeFrameGPU->setBz(bz);
}
template class TrackerTraitsGPU<7>;
} // namespace o2::its