forked from mcoquet642/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPUTPCGMMerger.h
More file actions
283 lines (253 loc) · 13.3 KB
/
GPUTPCGMMerger.h
File metadata and controls
283 lines (253 loc) · 13.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
// 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.
/// \file GPUTPCGMMerger.h
/// \author Sergey Gorbunov, David Rohr
#ifndef GPUTPCGMMERGER_H
#define GPUTPCGMMERGER_H
#include "GPUParam.h"
#include "GPUTPCDef.h"
#include "GPUTPCGMBorderTrack.h"
#include "GPUTPCGMMergedTrack.h"
#include "GPUTPCGMSliceTrack.h"
#include "GPUCommonDef.h"
#include "GPUProcessor.h"
#include "GPUTPCGMMergerTypes.h"
#include "GPUGeneralKernels.h"
#if !defined(GPUCA_GPUCODE)
#include <cmath>
#include <iostream>
#endif // GPUCA_GPUCODE
namespace o2
{
namespace base
{
class MatLayerCylSet;
}
} // namespace o2
namespace GPUCA_NAMESPACE
{
namespace gpu
{
class GPUTPCSliceTrack;
class GPUTPCSliceOutput;
class GPUTPCGMTrackParam;
class GPUTPCTracker;
class GPUChainTracking;
class GPUTPCGMPolynomialField;
struct GPUTPCGMLoopData;
struct MergeLooperParam;
/**
* @class GPUTPCGMMerger
*
*/
class GPUTPCGMMerger : public GPUProcessor
{
public:
GPUTPCGMMerger();
~GPUTPCGMMerger() CON_DEFAULT;
GPUTPCGMMerger(const GPUTPCGMMerger&) CON_DELETE;
const GPUTPCGMMerger& operator=(const GPUTPCGMMerger&) const CON_DELETE;
static CONSTEXPR int NSLICES = GPUCA_NSLICES; //* N slices
struct memory {
GPUAtomic(unsigned int) nRetryRefit;
GPUAtomic(unsigned int) nLoopData;
GPUAtomic(unsigned int) nUnpackedTracks;
GPUAtomic(unsigned int) nOutputTracks;
GPUAtomic(unsigned int) nOutputTrackClusters;
GPUAtomic(unsigned int) nO2Tracks;
GPUAtomic(unsigned int) nO2ClusRefs;
const GPUTPCTrack* firstGlobalTracks[NSLICES];
GPUAtomic(unsigned int) tmpCounter[2 * NSLICES];
GPUAtomic(unsigned int) nLooperMatchCandidates;
};
struct trackCluster {
unsigned int id;
unsigned char row;
unsigned char slice;
unsigned char leg;
};
struct tmpSort {
unsigned int x;
float y;
};
void InitializeProcessor();
void RegisterMemoryAllocation();
void SetMaxData(const GPUTrackingInOutPointers& io);
void* SetPointersMerger(void* mem);
void* SetPointersRefitScratch(void* mem);
void* SetPointersRefitScratch2(void* mem);
void* SetPointersOutput(void* mem);
void* SetPointersOutputO2(void* mem);
void* SetPointersOutputO2Clus(void* mem);
void* SetPointersOutputO2MC(void* mem);
void* SetPointersOutputO2Scratch(void* mem);
void* SetPointersOutputState(void* mem);
void* SetPointersMemory(void* mem);
void SetSliceData(int index, const GPUTPCSliceOutput* sliceData) { mkSlices[index] = sliceData; }
GPUhdi() int NOutputTracks() const { return mMemory->nOutputTracks; }
GPUhdi() const GPUTPCGMMergedTrack* OutputTracks() const { return mOutputTracks; }
GPUhdi() GPUTPCGMMergedTrack* OutputTracks() { return mOutputTracks; }
GPUhdi() const GPUdEdxInfo* OutputTracksdEdx() const { return mOutputTracksdEdx; }
GPUhdi() GPUdEdxInfo* OutputTracksdEdx() { return mOutputTracksdEdx; }
GPUhdi() unsigned int NClusters() const { return mNClusters; }
GPUhdi() unsigned int NMaxClusters() const { return mNMaxClusters; }
GPUhdi() unsigned int NMaxTracks() const { return mNMaxTracks; }
GPUhdi() unsigned int NMaxOutputTrackClusters() const { return mNMaxOutputTrackClusters; }
GPUhdi() unsigned int NOutputTrackClusters() const { return mMemory->nOutputTrackClusters; }
GPUhdi() const GPUTPCGMMergedTrackHit* Clusters() const { return mClusters; }
GPUhdi() GPUTPCGMMergedTrackHit* Clusters() { return (mClusters); }
GPUhdi() const GPUTPCGMMergedTrackHitXYZ* ClustersXYZ() const { return mClustersXYZ; }
GPUhdi() GPUTPCGMMergedTrackHitXYZ* ClustersXYZ() { return (mClustersXYZ); }
GPUhdi() GPUAtomic(unsigned int) * ClusterAttachment() const { return mClusterAttachment; }
GPUhdi() unsigned int* TrackOrderAttach() const { return mTrackOrderAttach; }
GPUhdi() unsigned int* TrackOrderProcess() const { return mTrackOrderProcess; }
GPUhdi() unsigned int* RetryRefitIds() const { return mRetryRefitIds; }
GPUhdi() unsigned char* ClusterStateExt() const { return mClusterStateExt; }
GPUhdi() GPUTPCGMLoopData* LoopData() const { return mLoopData; }
GPUhdi() memory* Memory() const { return mMemory; }
GPUhdi() GPUAtomic(unsigned int) * TmpCounter() { return mMemory->tmpCounter; }
GPUhdi() uint2* ClusRefTmp() { return mClusRefTmp; }
GPUhdi() unsigned int* TrackSort() { return mTrackSort; }
GPUhdi() tmpSort* TrackSortO2() { return mTrackSortO2; }
GPUhdi() MergeLooperParam* LooperCandidates() { return mLooperCandidates; }
GPUhdi() GPUAtomic(unsigned int) * SharedCount() { return mSharedCount; }
GPUhdi() gputpcgmmergertypes::GPUTPCGMBorderRange* BorderRange(int i) { return mBorderRange[i]; }
GPUhdi() o2::tpc::TrackTPC* OutputTracksTPCO2() { return mOutputTracksTPCO2; }
GPUhdi() unsigned int* OutputClusRefsTPCO2() { return mOutputClusRefsTPCO2; }
GPUhdi() o2::MCCompLabel* OutputTracksTPCO2MC() { return mOutputTracksTPCO2MC; }
GPUhdi() unsigned int NOutputTracksTPCO2() const { return mMemory->nO2Tracks; }
GPUhdi() unsigned int NOutputClusRefsTPCO2() const { return mMemory->nO2ClusRefs; }
GPUd() unsigned short MemoryResMemory() { return mMemoryResMemory; }
GPUd() unsigned short MemoryResOutput() const { return mMemoryResOutput; }
GPUd() unsigned short MemoryResOutputState() const { return mMemoryResOutputState; }
GPUd() unsigned short MemoryResOutputO2() const { return mMemoryResOutputO2; }
GPUd() unsigned short MemoryResOutputO2Clus() const { return mMemoryResOutputO2Clus; }
GPUd() unsigned short MemoryResOutputO2MC() const { return mMemoryResOutputO2MC; }
GPUd() unsigned short MemoryResOutputO2Scratch() const { return mMemoryResOutputO2Scratch; }
GPUd() int RefitSliceTrack(GPUTPCGMSliceTrack& sliceTrack, const GPUTPCTrack* inTrack, float alpha, int slice);
GPUd() void SetTrackClusterZT(GPUTPCGMSliceTrack& track, int iSlice, const GPUTPCTrack* sliceTr);
int CheckSlices();
GPUd() void RefitSliceTracks(int nBlocks, int nThreads, int iBlock, int iThread, int iSlice);
GPUd() void UnpackSliceGlobal(int nBlocks, int nThreads, int iBlock, int iThread, int iSlice);
GPUd() void UnpackSaveNumber(int id);
GPUd() void UnpackResetIds(int nBlocks, int nThreads, int iBlock, int iThread, int iSlice);
GPUd() void MergeCE(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void ClearTrackLinks(int nBlocks, int nThreads, int iBlock, int iThread, bool nOutput);
GPUd() void MergeWithinSlicesPrepare(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void MergeSlicesPrepare(int nBlocks, int nThreads, int iBlock, int iThread, int border0, int border1, char useOrigTrackParam);
template <int I>
GPUd() void MergeBorderTracks(int nBlocks, int nThreads, int iBlock, int iThread, int iSlice, char withinSlice, char mergeMode);
GPUd() void MergeBorderTracksSetup(int& n1, int& n2, GPUTPCGMBorderTrack*& b1, GPUTPCGMBorderTrack*& b2, int& jSlice, int iSlice, char withinSlice, char mergeMode);
template <int I>
GPUd() void MergeBorderTracks(int nBlocks, int nThreads, int iBlock, int iThread, gputpcgmmergertypes::GPUTPCGMBorderRange* range, int N, int cmpMax);
GPUd() void SortTracks(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void SortTracksQPt(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void SortTracksPrepare(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void PrepareClustersForFit0(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void PrepareClustersForFit1(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void PrepareClustersForFit2(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void LinkGlobalTracks(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void CollectMergedTracks(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void Finalize0(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void Finalize1(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void Finalize2(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void ResolveFindConnectedComponentsSetup(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void ResolveFindConnectedComponentsHookNeighbors(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void ResolveFindConnectedComponentsHookLinks(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void ResolveFindConnectedComponentsMultiJump(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void ResolveMergeSlices(gputpcgmmergertypes::GPUResolveSharedMemory& smem, int nBlocks, int nThreads, int iBlock, int iThread, char useOrigTrackParam, char mergeAll);
GPUd() void MergeLoopersInit(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void MergeLoopersSort(int nBlocks, int nThreads, int iBlock, int iThread);
GPUd() void MergeLoopersMain(int nBlocks, int nThreads, int iBlock, int iThread);
#ifndef GPUCA_GPUCODE
void DumpSliceTracks(std::ostream& out);
void DumpMergedWithinSlices(std::ostream& out);
void DumpMergedBetweenSlices(std::ostream& out);
void DumpCollected(std::ostream& out);
void DumpMergeCE(std::ostream& out);
void DumpFitPrepare(std::ostream& out);
void DumpRefit(std::ostream& out);
void DumpFinal(std::ostream& out);
#endif
private:
GPUd() void MakeBorderTracks(int nBlocks, int nThreads, int iBlock, int iThread, int iBorder, GPUTPCGMBorderTrack** B, GPUAtomic(unsigned int) * nB, bool useOrigTrackParam = false);
template <int I>
GPUd() void MergeBorderTracks(int nBlocks, int nThreads, int iBlock, int iThread, int iSlice1, GPUTPCGMBorderTrack* B1, int N1, int iSlice2, GPUTPCGMBorderTrack* B2, int N2, int mergeMode = 0);
GPUd() void MergeCEFill(const GPUTPCGMSliceTrack* track, const GPUTPCGMMergedTrackHit& cls, const GPUTPCGMMergedTrackHitXYZ* clsXYZ, int itr);
void CheckMergedTracks();
#ifndef GPUCA_GPUCODE
void PrintMergeGraph(const GPUTPCGMSliceTrack* trk, std::ostream& out);
template <class T, class S>
long int GetTrackLabelA(const S& trk);
template <class S>
long int GetTrackLabel(const S& trk);
#endif
GPUdi() int SliceTrackInfoFirst(int iSlice)
{
return mSliceTrackInfoIndex[iSlice];
}
GPUdi() int SliceTrackInfoLast(int iSlice) { return mSliceTrackInfoIndex[iSlice + 1]; }
GPUdi() int SliceTrackInfoGlobalFirst(int iSlice) { return mSliceTrackInfoIndex[NSLICES + iSlice]; }
GPUdi() int SliceTrackInfoGlobalLast(int iSlice) { return mSliceTrackInfoIndex[NSLICES + iSlice + 1]; }
GPUdi() int SliceTrackInfoLocalTotal() { return mSliceTrackInfoIndex[NSLICES]; }
GPUdi() int SliceTrackInfoTotal() { return mSliceTrackInfoIndex[2 * NSLICES]; }
GPUdi() void setBlockRange(int elems, int nBlocks, int iBlock, int& start, int& end);
GPUdi() void hookEdge(int u, int v);
int mNextSliceInd[NSLICES];
int mPrevSliceInd[NSLICES];
const GPUTPCSliceOutput* mkSlices[NSLICES]; //* array of input slice tracks
int* mTrackLinks;
int* mTrackCCRoots; // root of the connected component of this track
unsigned int mNMaxSliceTracks; // maximum number of incoming slice tracks
unsigned int mNMaxTracks; // maximum number of output tracks
unsigned int mNMaxSingleSliceTracks; // max N tracks in one slice
unsigned int mNMaxOutputTrackClusters; // max number of clusters in output tracks (double-counting shared clusters)
unsigned int mNMaxClusters; // max total unique clusters (in event)
unsigned int mNMaxLooperMatches; // Maximum number of candidate pairs for looper matching
unsigned short mMemoryResMemory;
unsigned short mMemoryResOutput;
unsigned short mMemoryResOutputState;
unsigned short mMemoryResOutputO2;
unsigned short mMemoryResOutputO2Clus;
unsigned short mMemoryResOutputO2MC;
unsigned short mMemoryResOutputO2Scratch;
int mNClusters; // Total number of incoming clusters (from slice tracks)
GPUTPCGMMergedTrack* mOutputTracks; //* array of output merged tracks
GPUdEdxInfo* mOutputTracksdEdx; //* dEdx information
GPUTPCGMSliceTrack* mSliceTrackInfos; //* additional information for slice tracks
int* mSliceTrackInfoIndex;
GPUTPCGMMergedTrackHit* mClusters;
GPUTPCGMMergedTrackHitXYZ* mClustersXYZ;
int* mGlobalClusterIDs;
GPUAtomic(unsigned int) * mClusterAttachment;
o2::tpc::TrackTPC* mOutputTracksTPCO2;
unsigned int* mOutputClusRefsTPCO2;
o2::MCCompLabel* mOutputTracksTPCO2MC;
MergeLooperParam* mLooperCandidates;
unsigned int* mTrackOrderAttach;
unsigned int* mTrackOrderProcess;
unsigned char* mClusterStateExt;
uint2* mClusRefTmp;
int* mTrackIDs;
unsigned int* mTrackSort;
tmpSort* mTrackSortO2;
GPUAtomic(unsigned int) * mSharedCount; // Must be unsigned int unfortunately for atomic support
GPUTPCGMBorderTrack* mBorderMemory; // memory for border tracks
GPUTPCGMBorderTrack* mBorder[2 * NSLICES];
gputpcgmmergertypes::GPUTPCGMBorderRange* mBorderRangeMemory; // memory for border tracks
gputpcgmmergertypes::GPUTPCGMBorderRange* mBorderRange[NSLICES]; // memory for border tracks
memory* mMemory;
unsigned int* mRetryRefitIds;
GPUTPCGMLoopData* mLoopData;
};
} // namespace gpu
} // namespace GPUCA_NAMESPACE
#endif // GPUTPCGMMERGER_H