Project
Loading...
Searching...
No Matches
GPUTPCCFNoiseSuppression.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
16#include "Array2D.h"
17#include "CfConsts.h"
18#include "CfUtils.h"
19#include "ChargePos.h"
20
21using namespace o2::gpu;
22using namespace o2::gpu::tpccf;
23
24template <>
25GPUdii() void GPUTPCCFNoiseSuppression::Thread<GPUTPCCFNoiseSuppression::noiseSuppression>(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUSharedMemory& smem, processorType& clusterer)
26{
27 Array2D<PackedCharge> chargeMap(reinterpret_cast<PackedCharge*>(clusterer.mPchargeMap));
28 Array2D<uint8_t> isPeakMap(clusterer.mPpeakMap);
29 noiseSuppressionImpl(get_num_groups(0), get_local_size(0), get_group_id(0), get_local_id(0), smem, clusterer.Param().rec, chargeMap, isPeakMap, clusterer.mPpeakPositions, clusterer.mPmemory->counters.nPeaks, clusterer.mPisPeak);
30}
31
32template <>
33GPUdii() void GPUTPCCFNoiseSuppression::Thread<GPUTPCCFNoiseSuppression::updatePeaks>(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUSharedMemory& smem, processorType& clusterer)
34{
35 Array2D<uint8_t> isPeakMap(clusterer.mPpeakMap);
36 updatePeaksImpl(get_num_groups(0), get_local_size(0), get_group_id(0), get_local_id(0), clusterer.mPpeakPositions, clusterer.mPisPeak, clusterer.mPmemory->counters.nPeaks, isPeakMap);
37}
38
39GPUdii() void GPUTPCCFNoiseSuppression::noiseSuppressionImpl(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUSharedMemory& smem,
40 const GPUSettingsRec& calibration,
41 const Array2D<PackedCharge>& chargeMap,
42 const Array2D<uint8_t>& peakMap,
43 const ChargePos* peakPositions,
44 const uint32_t peaknum,
45 uint8_t* isPeakPredicate)
46{
48
49 ChargePos pos = peakPositions[CAMath::Min(idx, (SizeT)(peaknum - 1))];
50 Charge charge = chargeMap[pos].unpack();
51
52 uint64_t minimas, bigger, peaksAround;
53 findMinimaAndPeaks(
54 chargeMap,
55 peakMap,
56 calibration,
57 charge,
58 pos,
59 smem.posBcast,
60 smem.buf,
61 &minimas,
62 &bigger,
63 &peaksAround);
64
65 peaksAround &= bigger;
66
67 bool keepMe = keepPeak(minimas, peaksAround);
68
69 bool iamDummy = (idx >= peaknum);
70 if (iamDummy) {
71 return;
72 }
73
74 isPeakPredicate[idx] = keepMe;
75}
76
77GPUd() void GPUTPCCFNoiseSuppression::updatePeaksImpl(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread,
78 const ChargePos* peakPositions,
79 const uint8_t* isPeak,
80 const uint32_t peakNum,
81 Array2D<uint8_t>& peakMap)
82{
83 SizeT idx = get_global_id(0);
84
85 if (idx >= peakNum) {
86 return;
87 }
88
89 ChargePos pos = peakPositions[idx];
90
91 uint8_t peak = isPeak[idx];
92
93 peakMap[pos] = 0b10 | peak; // if this positions was marked as peak at some point, then its charge must exceed the charge threshold.
94 // So we can just set the bit and avoid rereading the charge
95}
96
98 const float q,
99 const float epsilon,
100 const float epsilonRelative,
102 int32_t pos,
103 uint64_t* minimas,
104 uint64_t* bigger)
105{
106 float r = other.unpack();
107
108 uint64_t isMinima = (q - r > epsilon) && (float)CAMath::Abs(q - r) / (float)CAMath::Max(q, r) > epsilonRelative; // TODO: Can we assume q > r and get rid of Max/Abs?
109 *minimas |= (isMinima << pos);
110
111 uint64_t lq = (r > q);
112 *bigger |= (lq << pos);
113}
114
116 const PackedCharge* buf,
117 const uint16_t ll,
118 const int32_t N,
119 int32_t pos,
120 const float q,
121 const float epsilon,
122 const float epsilonRelative,
123 uint64_t* minimas,
124 uint64_t* bigger)
125{
126 GPUCA_UNROLL(U(), U())
127 for (int32_t i = 0; i < N; i++, pos++) {
128 PackedCharge other = buf[N * ll + i];
129
130 checkForMinima(q, epsilon, epsilonRelative, other, pos, minimas, bigger);
131 }
132}
133
135 const uint8_t* buf,
136 const uint16_t ll,
137 const int32_t N,
138 int32_t pos,
139 uint64_t* peaks)
140{
141 GPUCA_UNROLL(U(), U())
142 for (int32_t i = 0; i < N; i++, pos++) {
143 uint64_t p = CfUtils::isPeak(buf[N * ll + i]);
144
145 *peaks |= (p << pos);
146 }
147}
148
149GPUdi() bool GPUTPCCFNoiseSuppression::keepPeak(
150 uint64_t minima,
151 uint64_t peaks)
152{
153 bool keepMe = true;
154
155 GPUCA_UNROLL(U(), U())
156 for (int32_t i = 0; i < NOISE_SUPPRESSION_NEIGHBOR_NUM; i++) {
157 bool otherPeak = (peaks & (uint64_t(1) << i));
158 bool minimaBetween = (minima & cfconsts::NoiseSuppressionMinima[i]);
159
160 keepMe &= (!otherPeak || minimaBetween);
161 }
162
163 return keepMe;
164}
165
166GPUd() void GPUTPCCFNoiseSuppression::findMinimaAndPeaks(
167 const Array2D<PackedCharge>& chargeMap,
168 const Array2D<uint8_t>& peakMap,
169 const GPUSettingsRec& calibration,
170 float q,
171 const ChargePos& pos,
172 ChargePos* posBcast,
174 uint64_t* minimas,
175 uint64_t* bigger,
176 uint64_t* peaks)
177{
178 uint16_t ll = get_local_id(0);
179
180 posBcast[ll] = pos;
181 GPUbarrier();
182
183 uint16_t wgSizeHalf = (SCRATCH_PAD_WORK_GROUP_SIZE + 1) / 2;
184
185 bool inGroup1 = ll < wgSizeHalf;
186 uint16_t llhalf = (inGroup1) ? ll : (ll - wgSizeHalf);
187
188 *minimas = 0;
189 *bigger = 0;
190 *peaks = 0;
191
192 /**************************************
193 * Look for minima
194 **************************************/
195
196 CfUtils::blockLoad(
197 chargeMap,
198 SCRATCH_PAD_WORK_GROUP_SIZE,
199 SCRATCH_PAD_WORK_GROUP_SIZE,
200 ll,
201 16,
202 2,
203 cfconsts::NoiseSuppressionNeighbors,
204 posBcast,
205 buf);
206
207 findMinima(
208 buf,
209 ll,
210 2,
211 16,
212 q,
213 calibration.tpc.cfNoiseSuppressionEpsilon,
214 calibration.tpc.cfNoiseSuppressionEpsilonRelative / 255.f,
215 minimas,
216 bigger);
217
218 CfUtils::blockLoad(
219 chargeMap,
220 wgSizeHalf,
221 SCRATCH_PAD_WORK_GROUP_SIZE,
222 ll,
223 0,
224 16,
225 cfconsts::NoiseSuppressionNeighbors,
226 posBcast,
227 buf);
228
229 if (inGroup1) {
230 findMinima(
231 buf,
232 llhalf,
233 16,
234 0,
235 q,
236 calibration.tpc.cfNoiseSuppressionEpsilon,
237 calibration.tpc.cfNoiseSuppressionEpsilonRelative / 255.f,
238 minimas,
239 bigger);
240 }
241
242 CfUtils::blockLoad(
243 chargeMap,
244 wgSizeHalf,
245 SCRATCH_PAD_WORK_GROUP_SIZE,
246 ll,
247 18,
248 16,
249 cfconsts::NoiseSuppressionNeighbors,
250 posBcast,
251 buf);
252
253 if (inGroup1) {
254 findMinima(
255 buf,
256 llhalf,
257 16,
258 18,
259 q,
260 calibration.tpc.cfNoiseSuppressionEpsilon,
261 calibration.tpc.cfNoiseSuppressionEpsilonRelative / 255.f,
262 minimas,
263 bigger);
264 }
265
266#if defined(GPUCA_GPUCODE)
267 CfUtils::blockLoad(
268 chargeMap,
269 wgSizeHalf,
270 SCRATCH_PAD_WORK_GROUP_SIZE,
271 ll,
272 0,
273 16,
274 cfconsts::NoiseSuppressionNeighbors,
275 posBcast + wgSizeHalf,
276 buf);
277
278 if (!inGroup1) {
279 findMinima(
280 buf,
281 llhalf,
282 16,
283 0,
284 q,
285 calibration.tpc.cfNoiseSuppressionEpsilon,
286 calibration.tpc.cfNoiseSuppressionEpsilonRelative / 255.f,
287 minimas,
288 bigger);
289 }
290
291 CfUtils::blockLoad(
292 chargeMap,
293 wgSizeHalf,
294 SCRATCH_PAD_WORK_GROUP_SIZE,
295 ll,
296 18,
297 16,
298 cfconsts::NoiseSuppressionNeighbors,
299 posBcast + wgSizeHalf,
300 buf);
301
302 if (!inGroup1) {
303 findMinima(
304 buf,
305 llhalf,
306 16,
307 18,
308 q,
309 calibration.tpc.cfNoiseSuppressionEpsilon,
310 calibration.tpc.cfNoiseSuppressionEpsilonRelative / 255.f,
311 minimas,
312 bigger);
313 }
314#endif
315
316 uint8_t* bufp = (uint8_t*)buf;
317
318 /**************************************
319 * Look for peaks
320 **************************************/
321
322 CfUtils::blockLoad(
323 peakMap,
324 SCRATCH_PAD_WORK_GROUP_SIZE,
325 SCRATCH_PAD_WORK_GROUP_SIZE,
326 ll,
327 0,
328 16,
329 cfconsts::NoiseSuppressionNeighbors,
330 posBcast,
331 bufp);
332
333 findPeaks(
334 bufp,
335 ll,
336 16,
337 0,
338 peaks);
339
340 CfUtils::blockLoad(
341 peakMap,
342 SCRATCH_PAD_WORK_GROUP_SIZE,
343 SCRATCH_PAD_WORK_GROUP_SIZE,
344 ll,
345 18,
346 16,
347 cfconsts::NoiseSuppressionNeighbors,
348 posBcast,
349 bufp);
350
351 findPeaks(
352 bufp,
353 ll,
354 16,
355 18,
356 peaks);
357}
#define NOISE_SUPPRESSION_NEIGHBOR_NUM
Definition CfConsts.h:108
int16_t charge
Definition RawEventData.h:5
int32_t i
#define get_local_size(dim)
#define get_local_id(dim)
#define get_num_groups(dim)
#define GPUbarrier()
#define get_global_id(dim)
#define get_group_id(dim)
#define GPUCA_UNROLL(optCu, optHi)
GPUd() void GPUTPCCFNoiseSuppression
GPUdii() void GPUTPCCFNoiseSuppression
uint16_t pos
Definition RawData.h:3
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLboolean r
Definition glcorearb.h:1233
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition glcorearb.h:2514
uint8_t itsSharedClusterMap uint8_t
GPUdi() o2
Definition TrackTRD.h:38
VectorOfTObjectPtrs other
for(int irof=0;irof< 1000;irof++)