forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGPUTPCCFClusterizer.inc
More file actions
248 lines (215 loc) · 6.55 KB
/
GPUTPCCFClusterizer.inc
File metadata and controls
248 lines (215 loc) · 6.55 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
// 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 GPUTPCCFClusterizer.cxx
/// \author Felix Weiglhofer
#ifndef O2_GPU_CLUSTERIZER_INC_H
#define O2_GPU_CLUSTERIZER_INC_H
GPUdii() void GPUTPCCFClusterizer::computeClustersImpl(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread,
processorType& clusterer,
const CfFragment& fragment,
GPUSharedMemory& smem,
const Array2D<PackedCharge>& chargeMap,
const ChargePos* filteredPeakPositions,
const GPUSettingsRec& calib,
MCLabelAccumulator* labelAcc,
uint32_t clusternum,
uint32_t maxClusterPerRow,
uint32_t* clusterInRow,
tpc::ClusterNative* clusterByRow,
uint32_t* clusterPosInRow)
{
uint32_t idx = get_global_id(0);
// For certain configurations dummy work items are added, so the total
// number of work items is dividable by 64.
// These dummy items also compute the last cluster but discard the result.
ChargePos pos = filteredPeakPositions[CAMath::Min(idx, clusternum - 1)];
Charge charge = chargeMap[pos].unpack();
ClusterAccumulator pc;
CPU_ONLY(labelAcc->collect(pos, charge));
buildCluster(
calib,
chargeMap,
pos,
smem.posBcast,
smem.buf,
smem.innerAboveThreshold,
&pc,
labelAcc);
if (idx >= clusternum) {
return;
}
if (fragment.isOverlap(pos.time())) {
if (clusterPosInRow) {
clusterPosInRow[idx] = maxClusterPerRow;
}
return;
}
tpc::ClusterNative myCluster;
pc.finalize(pos, charge, fragment.start);
bool rejectCluster = !pc.toNative(pos, charge, myCluster, clusterer.Param(), chargeMap);
if (rejectCluster) {
if (clusterPosInRow) {
clusterPosInRow[idx] = maxClusterPerRow;
}
return;
}
uint32_t rowIndex = 0;
if (clusterByRow != nullptr) {
rowIndex = sortIntoBuckets(
clusterer,
myCluster,
pos.row(),
maxClusterPerRow,
clusterInRow,
clusterByRow);
if (clusterPosInRow != nullptr) {
clusterPosInRow[idx] = rowIndex;
}
} else if (clusterPosInRow) {
rowIndex = clusterPosInRow[idx];
}
CPU_ONLY(labelAcc->commit(pos.row(), rowIndex, maxClusterPerRow));
}
GPUdii() void GPUTPCCFClusterizer::updateClusterInner(
const GPUSettingsRec& calib,
uint16_t lid,
uint16_t N,
const PackedCharge* buf,
const ChargePos& pos,
ClusterAccumulator* cluster,
MCLabelAccumulator* labelAcc,
uint8_t* innerAboveThreshold)
{
uint8_t aboveThreshold = 0;
GPUCA_UNROLL(U(), U())
for (uint16_t i = 0; i < N; i++) {
Delta2 d = cfconsts::InnerNeighbors[i];
PackedCharge p = buf[N * lid + i];
Charge q = cluster->updateInner(p, d);
CPU_ONLY(labelAcc->collect(pos.delta(d), q));
aboveThreshold |= (uint8_t(q > calib.tpc.cfInnerThreshold) << i);
}
innerAboveThreshold[lid] = aboveThreshold;
GPUbarrier();
}
GPUdii() void GPUTPCCFClusterizer::updateClusterOuter(
uint16_t lid,
uint16_t N,
uint16_t M,
uint16_t offset,
const PackedCharge* buf,
const ChargePos& pos,
ClusterAccumulator* cluster,
MCLabelAccumulator* labelAcc)
{
GPUCA_UNROLL(U(), U())
for (uint16_t i = offset; i < M + offset; i++) {
PackedCharge p = buf[N * lid + i];
Delta2 d = cfconsts::OuterNeighbors[i];
Charge q = cluster->updateOuter(p, d);
static_cast<void>(q); // Avoid unused varible warning on GPU.
CPU_ONLY(labelAcc->collect(pos.delta(d), q));
}
}
GPUdii() void GPUTPCCFClusterizer::buildCluster(
const GPUSettingsRec& calib,
const Array2D<PackedCharge>& chargeMap,
ChargePos pos,
ChargePos* posBcast,
PackedCharge* buf,
uint8_t* innerAboveThreshold,
ClusterAccumulator* myCluster,
MCLabelAccumulator* labelAcc)
{
uint16_t ll = get_local_id(0);
posBcast[ll] = pos;
GPUbarrier();
CfUtils::blockLoad<PackedCharge>(
chargeMap,
SCRATCH_PAD_WORK_GROUP_SIZE,
SCRATCH_PAD_WORK_GROUP_SIZE,
ll,
0,
8,
cfconsts::InnerNeighbors,
posBcast,
buf);
updateClusterInner(
calib,
ll,
8,
buf,
pos,
myCluster,
labelAcc,
innerAboveThreshold);
uint16_t wgSizeHalf = (SCRATCH_PAD_WORK_GROUP_SIZE + 1) / 2;
bool inGroup1 = ll < wgSizeHalf;
uint16_t llhalf = (inGroup1) ? ll : (ll - wgSizeHalf);
CfUtils::condBlockLoad(
chargeMap,
wgSizeHalf,
SCRATCH_PAD_WORK_GROUP_SIZE,
ll,
0,
16,
cfconsts::OuterNeighbors,
posBcast,
innerAboveThreshold,
buf);
if (inGroup1) {
updateClusterOuter(
llhalf,
16,
16,
0,
buf,
pos,
myCluster,
labelAcc);
}
#if defined(GPUCA_GPUCODE)
CfUtils::condBlockLoad(
chargeMap,
wgSizeHalf,
SCRATCH_PAD_WORK_GROUP_SIZE,
ll,
0,
16,
cfconsts::OuterNeighbors,
posBcast + wgSizeHalf,
innerAboveThreshold + wgSizeHalf,
buf);
if (!inGroup1) {
updateClusterOuter(
llhalf,
16,
16,
0,
buf,
pos,
myCluster,
labelAcc);
}
#endif
}
GPUd() uint32_t GPUTPCCFClusterizer::sortIntoBuckets(processorType& clusterer, const tpc::ClusterNative& cluster, uint32_t row, uint32_t maxElemsPerBucket, uint32_t* elemsInBucket, tpc::ClusterNative* buckets)
{
uint32_t index = CAMath::AtomicAdd(&elemsInBucket[row], 1u);
if (index < maxElemsPerBucket) {
buckets[maxElemsPerBucket * row + index] = cluster;
} else {
clusterer.raiseError(GPUErrors::ERROR_CF_ROW_CLUSTER_OVERFLOW, clusterer.mISector * 1000 + row, index, maxElemsPerBucket);
CAMath::AtomicExch(&elemsInBucket[row], maxElemsPerBucket);
}
return index;
}
#endif // O2_GPU_CLUSTERIZER_INC_H