Project
Loading...
Searching...
No Matches
GPUTPCNeighboursFinder.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#include "GPUTPCHit.h"
17#include "GPUTPCTracker.h"
18// #include "GPUCommonMath.h"
19#include "GPUDefMacros.h"
20using namespace o2::gpu;
21
22template <>
23GPUdii() void GPUTPCNeighboursFinder::Thread<0>(int32_t /*nBlocks*/, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& s, processorType& GPUrestrict() tracker)
24{
25 //* find neighbours
26
27#ifdef GPUCA_GPUCODE
28 for (uint32_t i = iThread; i < sizeof(GPUTPCRow) / sizeof(int32_t); i += nThreads) {
29 reinterpret_cast<GPUsharedref() int32_t*>(&s.mRow)[i] = reinterpret_cast<GPUglobalref() int32_t*>(&tracker.TrackingDataRows()[iBlock])[i];
30 if (iBlock >= 2 && iBlock < (int32_t)GPUTPCGeometry::NROWS - 2) {
31 reinterpret_cast<GPUsharedref() int32_t*>(&s.mRowUp)[i] = reinterpret_cast<GPUglobalref() int32_t*>(&tracker.TrackingDataRows()[iBlock + 2])[i];
32 reinterpret_cast<GPUsharedref() int32_t*>(&s.mRowDown)[i] = reinterpret_cast<GPUglobalref() int32_t*>(&tracker.TrackingDataRows()[iBlock - 2])[i];
33 }
34 }
35 GPUbarrier();
36 const GPUsharedref() GPUTPCRow& GPUrestrict() row = s.mRow;
37 const GPUsharedref() GPUTPCRow& GPUrestrict() rowUp = s.mRowUp;
38 const GPUsharedref() GPUTPCRow& GPUrestrict() rowDn = s.mRowDown;
39#else
40 const GPUglobalref() GPUTPCRow& GPUrestrict() row = tracker.mData.mRows[iBlock];
41 const GPUglobalref() GPUTPCRow& GPUrestrict() rowUp = tracker.mData.mRows[iBlock + 2];
42 const GPUglobalref() GPUTPCRow& GPUrestrict() rowDn = tracker.mData.mRows[iBlock - 2];
43#endif
44
45 if (iThread == 0) {
46 s.mIRow = iBlock;
47 s.mIRowUp = iBlock + 2;
48 s.mIRowDn = iBlock - 2;
49 s.mNHits = row.mNHits;
50 if ((s.mIRow >= 2) && (s.mIRow < GPUTPCGeometry::NROWS - 2)) {
51 // the axis perpendicular to the rows
52 const float xDn = rowDn.mX;
53 const float x = row.mX;
54 const float xUp = rowUp.mX;
55
56 // distance of the rows (absolute and relative)
57 s.mUpDx = xUp - x;
58 s.mDnDx = xDn - x;
59 s.mUpTx = xUp / x;
60 s.mDnTx = xDn / x;
61 }
62 }
63 GPUbarrier();
64
65 // local copies
66
67 if ((s.mIRow <= 1) || (s.mIRow >= GPUTPCGeometry::NROWS - 2) || (rowUp.mNHits <= 0) || (rowDn.mNHits <= 0)) {
68 const int32_t lHitNumberOffset = row.mHitNumberOffset;
69 for (int32_t ih = iThread; ih < s.mNHits; ih += nThreads) {
70 tracker.mData.mLinkUpData[lHitNumberOffset + ih] = CALINK_INVAL;
71 tracker.mData.mLinkDownData[lHitNumberOffset + ih] = CALINK_INVAL;
72 }
73 return;
74 }
75
76 constexpr uint32_t UNROLL_GLOBAL = GPUCA_PAR_NEIGHBOURS_FINDER_UNROLL_GLOBAL > 1 ? GPUCA_PAR_NEIGHBOURS_FINDER_UNROLL_GLOBAL : 1;
77 static_assert(constants::NEIGHBOURS_MAX_N % UNROLL_GLOBAL == 0);
78 constexpr uint32_t MAX_SHARED = GPUCA_PAR_NEIGHBOURS_FINDER_MAX_NNEIGHUP;
79 constexpr uint32_t MAX_GLOBAL = (MAX_SHARED < constants::NEIGHBOURS_MAX_N) ? (((constants::NEIGHBOURS_MAX_N - MAX_SHARED - 1) / UNROLL_GLOBAL + 1) * UNROLL_GLOBAL) : 0;
80 constexpr uint32_t MAX_TOTAL = MAX_SHARED + MAX_GLOBAL;
81
82 const float chi2Cut = 3.f * 3.f * 4 * (s.mUpDx * s.mUpDx + s.mDnDx * s.mDnDx);
83 // float chi2Cut = 3.f*3.f*(s.mUpDx*s.mUpDx + s.mDnDx*s.mDnDx ); //SG
84
85 const int32_t lHitNumberOffset = row.mHitNumberOffset;
86 const int32_t lHitNumberOffsetUp = rowUp.mHitNumberOffset;
87 const int32_t lHitNumberOffsetDn = rowDn.mHitNumberOffset;
88 const uint32_t lFirstHitInBinOffsetUp = rowUp.mFirstHitInBinOffset;
89 const uint32_t lFirstHitInBinOffsetDn = rowDn.mFirstHitInBinOffset;
90 const GPUglobalref() calink* GPUrestrict() lFirstHitInBin = tracker.mData.mFirstHitInBin;
91 const GPUglobalref() cahit2* GPUrestrict() pHitData = tracker.mData.mHitData;
92
93 const float y0 = row.mGrid.mYMin;
94 const float z0 = row.mGrid.mZMin;
95 const float stepY = row.mHstepY;
96 const float stepZ = row.mHstepZ;
97
98 const float y0Up = rowUp.mGrid.mYMin;
99 const float z0Up = rowUp.mGrid.mZMin;
100 const float stepYUp = rowUp.mHstepY;
101 const float stepZUp = rowUp.mHstepZ;
102
103 const float y0Dn = rowDn.mGrid.mYMin;
104 const float z0Dn = rowDn.mGrid.mZMin;
105 const float stepYDn = rowDn.mHstepY;
106 const float stepZDn = rowDn.mHstepZ;
107
108 const float kAngularMultiplier = tracker.mConstantMem->param.rec.tpc.searchWindowDZDR;
109 const float kAreaSizeY = tracker.mConstantMem->param.rec.tpc.neighboursSearchArea;
110 const float kAreaSizeZUp = kAngularMultiplier != 0.f ? (s.mUpDx * kAngularMultiplier) : kAreaSizeY;
111 const float kAreaSizeZDn = kAngularMultiplier != 0.f ? (-s.mDnDx * kAngularMultiplier) : kAreaSizeY;
112 const float kAreaSlopeZUp = kAngularMultiplier != 0.f ? 1.f : s.mUpTx;
113 const float kAreaSlopeZDn = kAngularMultiplier != 0.f ? 1.f : s.mDnTx;
114
115 calink neighUp[MAX_GLOBAL];
116 float yzUp[2 * MAX_GLOBAL];
117
118 for (int32_t ih = iThread; ih < s.mNHits; ih += nThreads) {
119
120 const GPUglobalref() cahit2& hitData = pHitData[lHitNumberOffset + ih];
121 const float y = y0 + hitData.x * stepY;
122 const float z = z0 + hitData.y * stepZ;
123
124 uint32_t nNeighUp = 0;
125 float minZ, maxZ, minY, maxY;
126 int32_t binYmin, binYmax, binZmin, binZmax;
127 int32_t nY;
128
129 { // area in the upper row
130 const float yy = y * s.mUpTx;
131 const float zz = z * kAreaSlopeZUp;
132 minZ = zz - kAreaSizeZUp;
133 maxZ = zz + kAreaSizeZUp;
134 minY = yy - kAreaSizeY;
135 maxY = yy + kAreaSizeY;
136 rowUp.Grid().GetBin(minY, minZ, &binYmin, &binZmin);
137 rowUp.Grid().GetBin(maxY, maxZ, &binYmax, &binZmax);
138 nY = rowUp.Grid().Ny();
139 }
140
141 for (int32_t k1 = binZmin; k1 <= binZmax && (nNeighUp < MAX_TOTAL); k1++) {
142 int32_t iMin = lFirstHitInBin[lFirstHitInBinOffsetUp + k1 * nY + binYmin];
143 int32_t iMax = lFirstHitInBin[lFirstHitInBinOffsetUp + k1 * nY + binYmax + 1];
144 GPUCA_UNROLL(U(4), U(2))
145 for (int32_t i = iMin; i < iMax && (nNeighUp < MAX_TOTAL); i++) {
146 const GPUglobalref() cahit2& hitDataUp = pHitData[lHitNumberOffsetUp + i];
147 GPUTPCHit h;
148 h.mY = y0Up + (hitDataUp.x) * stepYUp;
149 h.mZ = z0Up + (hitDataUp.y) * stepZUp;
150
151 if (h.mY < minY || h.mY > maxY || h.mZ < minZ || h.mZ > maxZ) {
152 continue;
153 }
154
155 const bool inGlobal = nNeighUp >= MAX_SHARED;
156 if constexpr (MAX_GLOBAL > 0) {
157 if (inGlobal) {
158 neighUp[nNeighUp - MAX_SHARED] = (calink)i;
159 yzUp[2 * (nNeighUp - MAX_SHARED)] = s.mDnDx * (h.Y() - y);
160 yzUp[2 * (nNeighUp - MAX_SHARED) + 1] = s.mDnDx * (h.Z() - z);
161 }
162 }
163 if constexpr (MAX_SHARED > 0) {
164 if (!inGlobal) {
165 s.mB[nNeighUp][iThread] = (calink)i;
166 s.mA1[nNeighUp][iThread] = s.mDnDx * (h.Y() - y);
167 s.mA2[nNeighUp][iThread] = s.mDnDx * (h.Z() - z);
168 }
169 }
170 nNeighUp++;
171 }
172 }
173
174 if constexpr (MAX_SHARED > 0 && GPUCA_PAR_NEIGHBOURS_FINDER_UNROLL_SHARED) { // init the rest of the shared array
175 for (uint32_t iUp = nNeighUp; iUp < MAX_SHARED; iUp++) {
176 s.mA1[iUp][iThread] = -1.e10f;
177 s.mA2[iUp][iThread] = -1.e10f;
178 s.mB[iUp][iThread] = (calink)-1;
179 }
180 }
181
182 const uint32_t nRest = nNeighUp - MAX_SHARED;
183 uint32_t nRestUnrolled = (nRest / UNROLL_GLOBAL) * UNROLL_GLOBAL;
184 if constexpr (MAX_GLOBAL > 1) { // init the rest of the UNROLL_GLOBAL chunk of the global array
185 if (nNeighUp > MAX_SHARED && nRestUnrolled < nRest) {
186 nRestUnrolled += UNROLL_GLOBAL;
187 GPUCA_UNROLL(U(std::max<int32_t>(UNROLL_GLOBAL - 1, 1)), U(std::max<int32_t>(UNROLL_GLOBAL - 1, 1)))
188 for (uint32_t k = 0; k + 1 < UNROLL_GLOBAL; k++) {
189 if (nRest + k < nRestUnrolled) {
190 yzUp[2 * (nRest + k)] = -1.e10f;
191 yzUp[2 * (nRest + k) + 1] = -1.e10f;
192 neighUp[nRest + k] = (calink)-1;
193 }
194 }
195 }
196 }
197
198 { // area in the lower row
199 const float yy = y * s.mDnTx;
200 const float zz = z * kAreaSlopeZDn;
201 minZ = zz - kAreaSizeZDn;
202 maxZ = zz + kAreaSizeZDn;
203 minY = yy - kAreaSizeY;
204 maxY = yy + kAreaSizeY;
205 }
206 rowDn.Grid().GetBin(minY, minZ, &binYmin, &binZmin);
207 rowDn.Grid().GetBin(maxY, maxZ, &binYmax, &binZmax);
208 nY = rowDn.Grid().Ny();
209
210 int32_t linkUp = -1; // CALINK_INVAL as integer
211 int32_t linkDn = -1; // CALINK_INVAL as integer
212 float bestD = chi2Cut;
213
214 for (int32_t k1 = binZmin; k1 <= binZmax; k1++) {
215 int32_t iMin = lFirstHitInBin[lFirstHitInBinOffsetDn + k1 * nY + binYmin];
216 int32_t iMax = lFirstHitInBin[lFirstHitInBinOffsetDn + k1 * nY + binYmax + 1];
217 for (int32_t i = iMin; i < iMax; i++) {
218 const GPUglobalref() cahit2& hitDataDn = pHitData[lHitNumberOffsetDn + i];
219 float yDn = y0Dn + (hitDataDn.x) * stepYDn;
220 float zDn = z0Dn + (hitDataDn.y) * stepZDn;
221
222 if (yDn < minY || yDn > maxY || zDn < minZ || zDn > maxZ) {
223 continue;
224 }
225
226 float yDnProjUp = s.mUpDx * (yDn - y);
227 float zDnProjUp = s.mUpDx * (zDn - z);
228
229 if constexpr (MAX_SHARED > 0) {
230 const uint32_t maxSharedUp = GPUCA_PAR_NEIGHBOURS_FINDER_UNROLL_SHARED ? MAX_SHARED : CAMath::Min(nNeighUp, MAX_SHARED);
231 GPUCA_UNROLL(U(MAX_SHARED), U(MAX_SHARED))
232 for (uint32_t iUp = 0; iUp < maxSharedUp; iUp++) {
233 const float dy = yDnProjUp - s.mA1[iUp][iThread];
234 const float dz = zDnProjUp - s.mA2[iUp][iThread];
235 const float d = dy * dy + dz * dz;
236 if (d < bestD) {
237 bestD = d;
238 linkDn = i;
239 linkUp = iUp;
240 }
241 }
242 }
243
244 if constexpr (MAX_GLOBAL > 0) {
245 if (nNeighUp > MAX_SHARED) {
246 for (uint32_t iUp = 0; iUp < nRestUnrolled; iUp += UNROLL_GLOBAL) {
247 GPUCA_UNROLL(U(UNROLL_GLOBAL), U(UNROLL_GLOBAL))
248 for (uint32_t k = 0; k < UNROLL_GLOBAL; k++) {
249 const uint32_t jUp = iUp + k;
250 const float dy = yDnProjUp - yzUp[2 * jUp];
251 const float dz = zDnProjUp - yzUp[2 * jUp + 1];
252 const float d = dy * dy + dz * dz;
253 if (d < bestD) {
254 bestD = d;
255 linkDn = i;
256 linkUp = MAX_SHARED + jUp;
257 }
258 }
259 }
260 }
261 }
262 }
263 }
264
265 if (linkUp >= 0) {
266 if constexpr (MAX_SHARED > 0 && MAX_GLOBAL > 0) {
267 linkUp = ((uint32_t)linkUp >= MAX_SHARED) ? neighUp[linkUp - MAX_SHARED] : s.mB[linkUp][iThread];
268 } else if constexpr (MAX_SHARED > 0) {
269 linkUp = s.mB[linkUp][iThread];
270 } else {
271 linkUp = neighUp[linkUp];
272 }
273 }
274
275 tracker.mData.mLinkUpData[lHitNumberOffset + ih] = linkUp;
276 tracker.mData.mLinkDownData[lHitNumberOffset + ih] = linkDn;
277 }
278}
int32_t i
#define GPUsharedref()
#define GPUbarrier()
#define GPUrestrict()
#define GPUglobalref()
#define GPUCA_UNROLL(optCu, optHi)
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
#define CALINK_INVAL
Definition GPUTPCDef.h:21
GPUdii() void GPUTPCNeighboursFinder
Class for time synchronization of RawReader instances.
GLint GLenum GLint x
Definition glcorearb.h:403
GLfloat GLfloat GLfloat GLfloat GLfloat maxY
Definition glcorearb.h:2910
GLfloat minY
Definition glcorearb.h:2910
GLint y
Definition glcorearb.h:270
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat maxZ
Definition glcorearb.h:2910
GLuint GLfloat GLfloat y0
Definition glcorearb.h:5034
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
GLfloat GLfloat minZ
Definition glcorearb.h:2910
uint32_t calink
Definition GPUTPCDef.h:26
std::vector< int > row