forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPUTPCCFDeconvolution.cxx
More file actions
154 lines (127 loc) · 4.43 KB
/
GPUTPCCFDeconvolution.cxx
File metadata and controls
154 lines (127 loc) · 4.43 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
// 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 GPUTPCCFDeconvolution.cxx
/// \author Felix Weiglhofer
#include "GPUTPCCFDeconvolution.h"
#include "CfConsts.h"
#include "CfUtils.h"
#include "CfChargePos.h"
#include "GPUDefMacros.h"
using namespace o2::gpu;
using namespace o2::gpu::tpccf;
template <>
GPUdii() void GPUTPCCFDeconvolution::Thread<0>(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUSharedMemory& smem, processorType& clusterer, bool overwriteCharge)
{
CfArray2D<PackedCharge> chargeMap(reinterpret_cast<PackedCharge*>(clusterer.mPchargeMap));
CfArray2D<uint8_t> isPeakMap(clusterer.mPpeakMap);
GPUTPCCFDeconvolution::deconvolutionImpl(get_num_groups(0), get_local_size(0), get_group_id(0), get_local_id(0), smem, isPeakMap, chargeMap, clusterer.mPpositions, clusterer.mPmemory->counters.nPositions, overwriteCharge);
}
GPUdii() void GPUTPCCFDeconvolution::deconvolutionImpl(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUSharedMemory& smem,
const CfArray2D<uint8_t>& peakMap,
CfArray2D<PackedCharge>& chargeMap,
const CfChargePos* positions,
const uint32_t digitnum,
bool overwriteCharge)
{
SizeT idx = get_global_id(0);
bool iamDummy = (idx >= digitnum);
idx = iamDummy ? digitnum - 1 : idx;
CfChargePos pos = positions[idx];
bool iamPeak = CfUtils::isPeak(peakMap[pos]);
int8_t peakCount = (iamPeak) ? 1 : 0;
uint16_t ll = get_local_id(0);
uint16_t partId = ll;
uint16_t in3x3 = 0;
bool exclude3x3 = iamPeak || !pos.valid();
partId = CfUtils::partition<SCRATCH_PAD_WORK_GROUP_SIZE>(smem, ll, exclude3x3, SCRATCH_PAD_WORK_GROUP_SIZE, &in3x3);
if (partId < in3x3) {
smem.posBcast1[partId] = pos;
}
GPUbarrier();
CfUtils::blockLoad(
peakMap,
in3x3,
SCRATCH_PAD_WORK_GROUP_SIZE,
ll,
0,
8,
cfconsts::InnerNeighbors,
smem.posBcast1,
smem.buf);
uint8_t aboveThreshold = 0;
if (partId < in3x3) {
peakCount = countPeaksInner(partId, smem.buf, &aboveThreshold);
}
uint16_t in5x5 = 0;
partId = CfUtils::partition<SCRATCH_PAD_WORK_GROUP_SIZE>(smem, partId, peakCount > 0 && !exclude3x3, in3x3, &in5x5);
if (partId < in5x5) {
smem.posBcast1[partId] = pos;
smem.aboveThresholdBcast[partId] = aboveThreshold;
}
GPUbarrier();
CfUtils::condBlockLoad<uint8_t, true>(
peakMap,
in5x5,
SCRATCH_PAD_WORK_GROUP_SIZE,
ll,
0,
16,
cfconsts::OuterNeighbors,
smem.posBcast1,
smem.aboveThresholdBcast,
smem.buf);
if (partId < in5x5) {
peakCount = countPeaksOuter(partId, aboveThreshold, smem.buf);
peakCount *= -1;
}
if (iamDummy || !pos.valid()) {
return;
}
bool has3x3 = (peakCount > 0);
peakCount = CAMath::Abs(int32_t(peakCount));
bool split = (peakCount > 1);
peakCount = (peakCount == 0) ? 1 : peakCount;
PackedCharge charge = chargeMap[pos];
if (overwriteCharge) {
PackedCharge p(charge.unpack() / peakCount, has3x3, split);
chargeMap[pos] = p;
} else {
PackedCharge p(charge.unpack(), has3x3, split);
chargeMap[pos] = p;
}
}
GPUdi() uint8_t GPUTPCCFDeconvolution::countPeaksInner(
uint16_t ll,
const uint8_t* isPeak,
uint8_t* aboveThreshold)
{
uint8_t peaks = 0;
GPUCA_UNROLL(U(), U())
for (uint8_t i = 0; i < 8; i++) {
uint8_t p = isPeak[ll * 8 + i];
peaks += CfUtils::isPeak(p);
*aboveThreshold |= uint8_t(CfUtils::isAboveThreshold(p)) << i;
}
return peaks;
}
GPUdi() uint8_t GPUTPCCFDeconvolution::countPeaksOuter(
uint16_t ll,
uint8_t aboveThreshold,
const uint8_t* isPeak)
{
uint8_t peaks = 0;
GPUCA_UNROLL(U(), U())
for (uint8_t i = 0; i < 16; i++) {
uint8_t p = isPeak[ll * 16 + i];
peaks += CfUtils::isPeak(p);
}
return peaks;
}