forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGPUTPCClusterFinder.cxx
More file actions
181 lines (159 loc) · 8.21 KB
/
GPUTPCClusterFinder.cxx
File metadata and controls
181 lines (159 loc) · 8.21 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
// 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 GPUTPCClusterFinder.cxx
/// \author David Rohr
#include "GPUTPCClusterFinder.h"
#include "GPUReconstruction.h"
#include "GPUMemorySizeScalers.h"
#include "GPUHostDataTypes.h"
#include "GPUSettings.h"
#include "GPUDefParametersRuntime.h"
#include "DataFormatsTPC/ClusterNative.h"
#include "DataFormatsTPC/ZeroSuppression.h"
#include "DataFormatsTPC/Digit.h"
#include "CfChargePos.h"
#include "CfArray2D.h"
using namespace o2::gpu;
using namespace o2::tpc;
void GPUTPCClusterFinder::InitializeProcessor()
{
mMinMaxCN = new MinMaxCN[GPUTrackingInOutZS::NENDPOINTS];
}
GPUTPCClusterFinder::~GPUTPCClusterFinder()
{
delete[] mMinMaxCN;
clearMCMemory();
}
void* GPUTPCClusterFinder::SetPointersMemory(void* mem)
{
computePointerWithAlignment(mem, mPmemory, 1);
return mem;
}
void* GPUTPCClusterFinder::SetPointersInput(void* mem)
{
if (mNMaxPages == 0 && (mRec->GetRecoStepsGPU() & GPUDataTypes::RecoStep::TPCClusterFinding)) {
computePointerWithAlignment(mem, mPdigits, mNMaxDigits);
}
return mem;
}
void* GPUTPCClusterFinder::SetPointersZSOffset(void* mem)
{
const int32_t n = (mRec->GetRecoStepsGPU() & GPUDataTypes::RecoStep::TPCClusterFinding) ? mNMaxPages : GPUTrackingInOutZS::NENDPOINTS;
if (n) {
computePointerWithAlignment(mem, mPzsOffsets, n);
}
return mem;
}
void* GPUTPCClusterFinder::SetPointersZS(void* mem)
{
if (mNMaxPages && (mRec->GetRecoStepsGPU() & GPUDataTypes::RecoStep::TPCClusterFinding)) {
computePointerWithAlignment(mem, mPzs, mNMaxPages * TPCZSHDR::TPC_ZS_PAGE_SIZE);
}
return mem;
}
void* GPUTPCClusterFinder::SetPointersOutput(void* mem)
{
computePointerWithAlignment(mem, mPclusterInRow, GPUCA_ROW_COUNT);
return mem;
}
void* GPUTPCClusterFinder::SetPointersScratch(void* mem)
{
computePointerWithAlignment(mem, mPpadIsNoisy, TPC_PADS_IN_SECTOR);
computePointerWithAlignment(mem, mPpositions, mNMaxDigitsFragment);
computePointerWithAlignment(mem, mPpeakPositions, mNMaxPeaks);
computePointerWithAlignment(mem, mPfilteredPeakPositions, mNMaxClusters);
if (mRec->GetProcessingSettings().runMC) {
computePointerWithAlignment(mem, mPclusterPosInRow, mNMaxClusters);
} else {
mPclusterPosInRow = nullptr;
}
computePointerWithAlignment(mem, mPisPeak, mNMaxDigitsFragment);
computePointerWithAlignment(mem, mPchargeMap, TPCMapMemoryLayout<decltype(*mPchargeMap)>::items(mRec->GetProcessingSettings().overrideClusterizerFragmentLen));
computePointerWithAlignment(mem, mPpeakMap, TPCMapMemoryLayout<decltype(*mPpeakMap)>::items(mRec->GetProcessingSettings().overrideClusterizerFragmentLen));
computePointerWithAlignment(mem, mPclusterByRow, GPUCA_ROW_COUNT * mNMaxClusterPerRow);
if ((mRec->GetRecoStepsGPU() & GPUDataTypes::RecoStep::TPCClusterFinding)) {
computePointerWithAlignment(mem, mPscanBuf, mBufSize * mNBufs);
}
return mem;
}
void GPUTPCClusterFinder::RegisterMemoryAllocation()
{
AllocateAndInitializeLate();
mRec->RegisterMemoryAllocation(this, &GPUTPCClusterFinder::SetPointersInput, GPUMemoryResource::MEMORY_INPUT | GPUMemoryResource::MEMORY_GPU | GPUMemoryResource::MEMORY_STACK, "TPCClustererInput");
int32_t scratchType = GPUMemoryResource::MEMORY_SCRATCH | GPUMemoryResource::MEMORY_STACK;
if (mRec->GetProcessingSettings().runMC) {
scratchType |= GPUMemoryResource::MEMORY_HOST | GPUMemoryResource::MEMORY_GPU;
}
mScratchId = mRec->RegisterMemoryAllocation(this, &GPUTPCClusterFinder::SetPointersScratch, scratchType, "TPCClustererScratch", GPUMemoryReuse{GPUMemoryReuse::REUSE_1TO1, GPUMemoryReuse::ClustererScratch, (uint16_t)(mISector % mRec->GetProcessingSettings().nTPCClustererLanes)});
mMemoryId = mRec->RegisterMemoryAllocation(this, &GPUTPCClusterFinder::SetPointersMemory, GPUMemoryResource::MEMORY_PERMANENT, "TPCClustererMemory");
mRec->RegisterMemoryAllocation(this, &GPUTPCClusterFinder::SetPointersOutput, GPUMemoryResource::MEMORY_OUTPUT | GPUMemoryResource::MEMORY_STACK, "TPCClustererOutput");
mZSId = mRec->RegisterMemoryAllocation(this, &GPUTPCClusterFinder::SetPointersZS, GPUMemoryResource::MEMORY_CUSTOM | GPUMemoryResource::MEMORY_CUSTOM_TRANSFER | GPUMemoryResource::MEMORY_GPU | GPUMemoryResource::MEMORY_STACK, "TPCClustererZSData", GPUMemoryReuse{GPUMemoryReuse::REUSE_1TO1, GPUMemoryReuse::ClustererZS, (uint16_t)(mISector % mRec->GetProcessingSettings().nTPCClustererLanes)});
mZSOffsetId = mRec->RegisterMemoryAllocation(this, &GPUTPCClusterFinder::SetPointersZSOffset, GPUMemoryResource::MEMORY_CUSTOM | GPUMemoryResource::MEMORY_CUSTOM_TRANSFER | GPUMemoryResource::MEMORY_INPUT | GPUMemoryResource::MEMORY_STACK, "TPCClustererZSOffsets");
}
void GPUTPCClusterFinder::SetMaxData(const GPUTrackingInOutPointers& io)
{
mNMaxPeaks = mRec->MemoryScalers()->NTPCPeaks(mNMaxDigitsFragment);
mNMaxClusters = mRec->MemoryScalers()->NTPCClusters(mNMaxDigitsFragment, true);
mNMaxClusterPerRow = 0.01f * mRec->MemoryScalers()->NTPCClusters(mNMaxDigits, true); // TODO: Can save some memory hery by using mNMaxClusters, and copying the computed clusters out after every fragment
if (io.settingsTF && io.settingsTF->hasNHBFPerTF) {
uint32_t threshold = 300000 * io.settingsTF->nHBFPerTF / 128; // TODO: Probably one would need to do this on a row-basis for a better estimate, but currently not supported
mNMaxClusterPerRow = std::max<uint32_t>(mNMaxClusterPerRow, std::min<uint32_t>(threshold, mNMaxClusterPerRow * 10)); // Relative increased value up until a threshold, for noisy pads
mNMaxClusterPerRow = std::max<uint32_t>(mNMaxClusterPerRow, io.settingsTF->nHBFPerTF * 20000 / 256); // Absolute increased value, to have a minimum for noisy pads
}
if (mNMaxDigitsEndpoint) {
mNMaxClusterPerRow = std::max<uint32_t>(mNMaxClusterPerRow, 0.0085f * mRec->MemoryScalers()->NTPCClusters(mNMaxDigitsEndpoint * GPUTrackingInOutZS::NENDPOINTS, true));
}
if (mRec->GetProcessingSettings().tpcIncreasedMinClustersPerRow) {
mNMaxClusterPerRow = std::max<uint32_t>(mNMaxClusterPerRow, mRec->GetProcessingSettings().tpcIncreasedMinClustersPerRow);
}
if ((mRec->GetRecoStepsGPU() & GPUDataTypes::RecoStep::TPCClusterFinding)) {
mBufSize = nextMultipleOf(mNMaxDigitsFragment, std::max<int32_t>(GPUCA_MEMALIGN, mRec->getGPUParameters(mRec->GetRecoStepsGPU() & GPUDataTypes::RecoStep::TPCClusterFinding).par_CF_SCAN_WORKGROUP_SIZE));
mNBufs = getNSteps(mBufSize);
}
}
void GPUTPCClusterFinder::SetNMaxDigits(size_t nDigits, size_t nPages, size_t nDigitsFragment, size_t nDigitsEndpointMax)
{
mNMaxDigits = nextMultipleOf(nDigits, std::max<int32_t>(GPUCA_MEMALIGN, mRec->getGPUParameters(mRec->GetRecoStepsGPU() & GPUDataTypes::RecoStep::TPCClusterFinding).par_CF_SCAN_WORKGROUP_SIZE));
mNMaxPages = nPages;
mNMaxDigitsFragment = nDigitsFragment;
mNMaxDigitsEndpoint = nDigitsEndpointMax;
}
uint32_t GPUTPCClusterFinder::getNSteps(size_t items) const
{
if (items == 0) {
return 0;
}
uint32_t c = 1;
const size_t scanWorkgroupSize = mRec->getGPUParameters(mRec->GetRecoStepsGPU() & GPUDataTypes::RecoStep::TPCClusterFinding).par_CF_SCAN_WORKGROUP_SIZE;
size_t capacity = scanWorkgroupSize;
while (items > capacity) {
capacity *= scanWorkgroupSize;
c++;
}
return c;
}
void GPUTPCClusterFinder::PrepareMC()
{
assert(mNMaxClusterPerRow > 0);
clearMCMemory();
mPindexMap = new uint32_t[TPCMapMemoryLayout<decltype(*mPindexMap)>::items(mRec->GetProcessingSettings().overrideClusterizerFragmentLen)];
mPlabelsByRow = new GPUTPCClusterMCInterimArray[GPUCA_ROW_COUNT];
mPlabelsInRow = new uint32_t[GPUCA_ROW_COUNT];
}
void GPUTPCClusterFinder::clearMCMemory()
{
delete[] mPindexMap;
mPindexMap = nullptr;
delete[] mPlabelsByRow;
mPlabelsByRow = nullptr;
delete[] mPlabelsInRow;
mPlabelsInRow = nullptr;
}