Project
Loading...
Searching...
No Matches
GPUChainTracking.h
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#ifndef GPUCHAINTRACKING_H
16#define GPUCHAINTRACKING_H
17
18#include "GPUChain.h"
19#include "GPUDataTypesIO.h"
20#include "GPUDataTypesConfig.h"
22#include <atomic>
23#include <mutex>
24#include <functional>
25#include <array>
26#include <vector>
27#include <utility>
28
29namespace o2::dataformats
30{
31template <typename TruthElement>
32class ConstMCTruthContainer;
33} // namespace o2::dataformats
34
35namespace o2::trd
36{
37class GeometryFlat;
38} // namespace o2::trd
39
40namespace o2::tpc
41{
42struct ClusterNativeAccess;
43struct ClusterNative;
44class CalibdEdxContainer;
45} // namespace o2::tpc
46
47namespace o2::base
48{
49class MatLayerCylSet;
50template <typename>
51class PropagatorImpl;
52using Propagator = PropagatorImpl<float>;
53} // namespace o2::base
54
55namespace o2::gpu
56{
57// class GPUTRDTrackerGPU;
58class GPUTPCGPUTracker;
59class GPUDisplayInterface;
60class GPUQA;
61class GPUTPCClusterStatistics;
62class GPUTRDGeometry;
63class GPUTRDRecoParam;
64class TPCFastTransformPOD;
65class GPUTrackingInputProvider;
66struct GPUChainTrackingFinalContext;
67struct GPUTPCCFChainContext;
68struct GPUNewCalibValues;
69struct GPUTriggerOutputs;
70struct CfFragment;
71class GPUTPCClusterFinder;
72struct GPUSettingsProcessing;
73struct GPUSettingsRec;
74
76{
77 friend class GPUReconstruction;
78
79 public:
82 void RegisterGPUProcessors() override;
83 int32_t Init() override;
84 int32_t PrepareEvent() override;
85 int32_t Finalize() override;
86 int32_t RunChain() override;
87 void MemorySize(size_t& gpuMem, size_t& pageLockedHostMem) override;
88 int32_t CheckErrorCodes(bool cpuOnly = false, bool forceShowErrors = false, std::vector<std::array<uint32_t, 4>>* fillErrors = nullptr) override;
89 bool SupportsDoublePipeline() override { return true; }
90 int32_t FinalizePipelinedProcessing() override;
91 void ClearErrorCodes(bool cpuOnly = false);
92 int32_t DoQueuedUpdates(int32_t stream, bool updateSlave = true); // Forces doing queue calib updates, don't call when you are not sure you are allowed to do so!
93 bool QARanForTF() const { return mFractionalQAEnabled; }
94 static void ApplySyncSettings(GPUSettingsProcessing& proc, GPUSettingsRec& rec, gpudatatypes::RecoStepField& steps, bool syncMode, int32_t dEdxMode = -2);
95
96 // Structures for input and output data
98
99 struct InOutMemory {
104
105 std::unique_ptr<uint64_t[]> tpcZSpages;
106 std::unique_ptr<char[]> tpcZSpagesChar; // Same as above, but as char (needed for reading dumps, but deprecated, since alignment can be wrong) // TODO: Fix alignment
107 std::unique_ptr<char[]> tpcCompressedClusters; // TODO: Fix alignment
108 std::unique_ptr<GPUTrackingInOutZS> tpcZSmeta;
109 std::unique_ptr<GPUTrackingInOutZS::GPUTrackingInOutZSMeta> tpcZSmeta2;
110 std::unique_ptr<o2::tpc::Digit[]> tpcDigits[NSECTORS];
111 std::unique_ptr<GPUTrackingInOutDigits> digitMap;
112 std::unique_ptr<GPUTPCClusterData[]> clusterData[NSECTORS];
113 std::unique_ptr<AliHLTTPCRawCluster[]> rawClusters[NSECTORS];
114 std::unique_ptr<o2::tpc::ClusterNative[]> clustersNative;
115 std::unique_ptr<o2::tpc::ClusterNativeAccess> clusterNativeAccess;
116 std::unique_ptr<GPUTPCTrack[]> sectorTracks[NSECTORS];
117 std::unique_ptr<GPUTPCHitId[]> sectorClusters[NSECTORS];
118 std::unique_ptr<AliHLTTPCClusterMCLabel[]> mcLabelsTPC;
119 std::unique_ptr<GPUTPCMCInfo[]> mcInfosTPC;
120 std::unique_ptr<GPUTPCMCInfoCol[]> mcInfosTPCCol;
121 std::unique_ptr<GPUTPCGMMergedTrack[]> mergedTracks;
122 std::unique_ptr<GPUTPCGMMergedTrackHit[]> mergedTrackHits;
123 std::unique_ptr<GPUTRDTrackletWord[]> trdTracklets;
124 std::unique_ptr<GPUTRDSpacePoint[]> trdSpacePoints;
125 std::unique_ptr<float[]> trdTriggerTimes;
126 std::unique_ptr<int32_t[]> trdTrackletIdxFirst;
127 std::unique_ptr<uint8_t[]> trdTrigRecMask;
128 std::unique_ptr<GPUTRDTrackGPU[]> trdTracks;
129 std::unique_ptr<char[]> clusterNativeMC;
130 std::unique_ptr<o2::dataformats::ConstMCTruthContainerView<o2::MCCompLabel>> clusterNativeMCView;
131 std::unique_ptr<char[]> tpcDigitsMC[NSECTORS];
132 std::unique_ptr<o2::dataformats::ConstMCTruthContainerView<o2::MCCompLabel>[]> tpcDigitMCView;
133 std::unique_ptr<GPUTPCDigitsMCInput> tpcDigitMCMap;
134 std::unique_ptr<o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>> clusterNativeMCBuffer;
135 std::unique_ptr<GPUSettingsTF[]> settingsTF;
137
138 // Read / Dump / Clear Data
139 void ClearIOPointers();
140 void AllocateIOMemory();
141 using GPUChain::DumpData;
142 void DumpData(const char* filename, const GPUTrackingInOutPointers* ioPtrs = nullptr);
143 using GPUChain::ReadData;
144 int32_t ReadData(const char* filename);
145 void DumpSettings(const char* dir = "") override;
146 void ReadSettings(const char* dir = "") override;
147
148 // Converter / loader functions
152 void ConvertZSEncoder(int32_t version);
153 void ConvertZSFilter(bool zs12bit);
154
155 // Getters for external usage of tracker classes
157 const GPUQA* GetQA() const { return mQAFromForeignChain ? mQAFromForeignChain->mQA.get() : mQA.get(); }
159 int32_t ForceInitQA();
161 const GPUSettingsDisplay* GetEventDisplayConfig() const { return mConfigDisplay; }
162 const GPUSettingsQA* GetQAConfig() const { return mConfigQA; }
163
164 // Processing functions
165 int32_t RunTPCClusterizer(bool synchronizeOutput = true);
166 int32_t ForwardTPCDigits();
167 int32_t RunTPCTrackingSectors();
168 int32_t RunTPCTrackingMerger(bool synchronizeOutput = true);
169 int32_t RunTRDTracking();
170 template <int32_t I, class T = GPUTRDTracker>
171 int32_t DoTRDGPUTracking(T* externalInstance = nullptr);
172 int32_t RunTPCCompression();
173 int32_t RunTPCDecompression();
174 int32_t RunRefit();
175
176 // Getters / setters for parameters
187 void SetMatLUT(std::unique_ptr<o2::base::MatLayerCylSet>&& lut);
188 void SetTRDGeometry(std::unique_ptr<o2::trd::GeometryFlat>&& geo);
189 void SetTRDRecoParam(std::unique_ptr<GPUTRDRecoParam>&& par);
193 void SetO2Propagator(const o2::base::Propagator* prop);
198 void SetFinalInputCallback(std::function<void()> v) { mWaitForFinalInputs = v; }
199
200 const GPUSettingsDisplay* mConfigDisplay = nullptr; // Abstract pointer to Standalone Display Configuration Structure
201 const GPUSettingsQA* mConfigQA = nullptr; // Abstract pointer to Standalone QA Configuration Structure
203
204 protected:
214 void UpdateGPUCalibObjects(int32_t stream, const GPUCalibObjectsConst* ptrMask = nullptr);
215 void UpdateGPUCalibObjectsPtrs(int32_t stream);
216
217 struct eventStruct // Must consist only of void* ptr that will hold the GPU event ptrs!
218 {
220 deviceEvent stream[constants::GPU_MAX_STREAMS];
223 };
224
226 void* dst;
227 void* src;
228 size_t size;
230 };
231
232 GPUChainTracking(GPUReconstruction* rec, uint32_t maxTPCHits = constants::GPU_MEM_MAX_TPC_CLUSTERS, uint32_t maxTRDTracklets = constants::GPU_MEM_MAX_TRD_TRACKLETS);
233
234 int32_t ExtrapolationTracking(uint32_t iSector, bool blocking);
235
236 int32_t PrepareProfile();
237 int32_t DoProfile();
239 void PrintMemoryStatistics() override;
242 void PrintOutputStat();
243 static void DumpClusters(std::ostream& out, const o2::tpc::ClusterNativeAccess* clusters);
245 void DoDebugRawDump();
246
247 bool ValidateSteps();
248 bool ValidateSettings();
249
250 // Pointers to tracker classes
251 GPUTrackingFlatObjects mFlatObjectsShadow; // Host copy of flat objects that will be used on the GPU
252 GPUTrackingFlatObjects mFlatObjectsDevice; // flat objects that will be used on the GPU
253 std::unique_ptr<GPUTrackingInputProvider> mInputsHost;
254 std::unique_ptr<GPUTrackingInputProvider> mInputsShadow;
255
256 // Display / QA
257 bool mDisplayRunning = false;
258 std::unique_ptr<GPUDisplayInterface> mEventDisplay;
260 std::unique_ptr<GPUQA> mQA;
261 std::unique_ptr<GPUTPCClusterStatistics> mCompressionStatistics;
262
263 // Ptr to detector / calibration objects
265 std::unique_ptr<TPCPadGainCalib> mTPCPadGainCalibU; // TPC gain calibration and cluster finder parameters
266 std::unique_ptr<TPCZSLinkMapping> mTPCZSLinkMappingU; // TPC Mapping data required by ZS Link decoder
267 std::unique_ptr<o2::tpc::CalibdEdxContainer> mdEdxCalibContainerU; // TPC dEdx calibration container
268 std::unique_ptr<o2::base::MatLayerCylSet> mMatLUTU; // Material Lookup Table
269 std::unique_ptr<o2::trd::GeometryFlat> mTRDGeometryU; // TRD Geometry
270 std::unique_ptr<GPUTRDRecoParam> mTRDRecoParamU; // TRD RecoParam
271
272 // Ptrs to internal buffers
273 std::unique_ptr<o2::tpc::ClusterNativeAccess> mClusterNativeAccess, mClusterNativeAccessReduced;
275 std::unique_ptr<GPUTriggerOutputs> mTriggerBuffer;
276
277 // (Ptrs to) configuration objects
278 std::unique_ptr<GPUTPCCFChainContext> mCFContext;
280 std::unique_ptr<GPUCalibObjectsConst> mNewCalibObjects;
282 std::unique_ptr<GPUNewCalibValues> mNewCalibValues;
283
284 // Upper bounds for memory allocation
285 uint32_t mMaxTPCHits = 0;
286 uint32_t mMaxTRDTracklets = 0;
287
288 // Debug
289 std::unique_ptr<std::ofstream> mDebugFile;
290
291 // Synchronization and Locks
293 std::array<int8_t, NSECTORS> mExtrapolationTrackingDone;
294
295 std::vector<outputQueueEntry> mOutputQueue;
296
297 private:
298 int32_t RunChainFinalize();
299 void OutputSanityCheck();
300 int32_t RunTPCTrackingSectors_internal();
301 int32_t RunTPCClusterizer_prepare(bool restorePointers);
302#ifndef GPUCA_RUN2
303 std::pair<uint32_t, uint32_t> RunTPCClusterizer_transferZS(int32_t iSector, const CfFragment& fragment, int32_t lane);
304 void RunTPCClusterizer_compactPeaks(GPUTPCClusterFinder& clusterer, GPUTPCClusterFinder& clustererShadow, int32_t stage, bool doGPU, int32_t lane);
305 std::pair<uint32_t, uint32_t> TPCClusterizerDecodeZSCount(uint32_t iSector, const CfFragment& fragment);
306 std::pair<uint32_t, uint32_t> TPCClusterizerDecodeZSCountUpdate(uint32_t iSector, const CfFragment& fragment);
307 void TPCClusterizerEnsureZSOffsets(uint32_t iSector, const CfFragment& fragment);
308#endif
309 void RunTPCTrackingMerger_MergeBorderTracks(uint8_t mergeMode, GPUReconstruction::krnlDeviceType deviceType);
310 void RunTPCTrackingMerger_Resolve(int8_t useOrigTrackParam, int8_t mergeAll, GPUReconstruction::krnlDeviceType deviceType);
311 void RunTPCClusterFilter(o2::tpc::ClusterNativeAccess* clusters, std::function<o2::tpc::ClusterNative*(size_t)> allocator, bool applyClusterCuts);
312 bool NeedTPCClustersOnGPU();
313 void WriteReducedClusters();
314 void SortClusters(bool buildNativeGPU, bool propagateMCLabels, o2::tpc::ClusterNativeAccess* clusterAccess, o2::tpc::ClusterNative* clusters);
315 template <int32_t I>
316 int32_t RunTRDTrackingInternal();
317 uint32_t StreamForSector(uint32_t sector) const;
318
319 std::mutex mMutexUpdateCalib;
320 std::unique_ptr<GPUChainTrackingFinalContext> mPipelineFinalizationCtx;
321 GPUChainTrackingFinalContext* mPipelineNotifyCtx = nullptr;
322 std::function<void()> mWaitForFinalInputs;
323
324 int32_t OutputStream() const { return mRec->NStreams() - 2; }
325};
326} // namespace o2::gpu
327
328#endif
int32_t i
uint32_t iSector
GPUChain * chain
uint32_t version
Definition RawData.h:8
void SetMatLUT(std::unique_ptr< o2::base::MatLayerCylSet > &&lut)
static void ApplySyncSettings(GPUSettingsProcessing &proc, GPUSettingsRec &rec, gpudatatypes::RecoStepField &steps, bool syncMode, int32_t dEdxMode=-2)
void SetQAFromForeignChain(GPUChainTracking *chain)
std::unique_ptr< o2::base::MatLayerCylSet > mMatLUTU
static void DebugSortCompressedClusters(o2::tpc::CompressedClustersFlat *cls)
const o2::base::Propagator * GetDeviceO2Propagator()
std::unique_ptr< o2::tpc::ClusterNativeAccess > mClusterNativeAccess
std::unique_ptr< GPUTRDRecoParam > mTRDRecoParamU
void SetCalibObjects(const GPUCalibObjects &obj)
void SetTRDGeometry(std::unique_ptr< o2::trd::GeometryFlat > &&geo)
void SetCalibObjects(const GPUCalibObjectsConst &obj)
const o2::base::Propagator * GetO2Propagator() const
GPUChainTracking * mQAFromForeignChain
void SetO2Propagator(const o2::base::Propagator *prop)
std::unique_ptr< GPUQA > mQA
void ReadSettings(const char *dir="") override
GPUTrackingFlatObjects mFlatObjectsDevice
int32_t RunTPCClusterizer(bool synchronizeOutput=true)
void SetTRDGeometry(const o2::trd::GeometryFlat *geo)
std::array< int8_t, NSECTORS > mExtrapolationTrackingDone
const GPUTRDGeometry * GetTRDGeometry() const
static void DumpClusters(std::ostream &out, const o2::tpc::ClusterNativeAccess *clusters)
void UpdateGPUCalibObjectsPtrs(int32_t stream)
int32_t RunTPCTrackingMerger(bool synchronizeOutput=true)
std::unique_ptr< GPUTrackingInputProvider > mInputsHost
const TPCFastTransformPOD * GetTPCTransform() const
void SetMatLUT(const o2::base::MatLayerCylSet *lut)
std::unique_ptr< GPUTPCClusterStatistics > mCompressionStatistics
const o2::base::MatLayerCylSet * GetMatLUT() const
void SetTRDRecoParam(std::unique_ptr< GPUTRDRecoParam > &&par)
std::array< GPUOutputControl *, GPUTrackingOutputs::count()> mSubOutputControls
std::unique_ptr< std::ofstream > mDebugFile
std::unique_ptr< GPUTriggerOutputs > mTriggerBuffer
std::vector< outputQueueEntry > mOutputQueue
void SetTPCFastTransform(aligned_unique_buffer_ptr< TPCFastTransformPOD > &&tpcFastTransform)
void SetUpdateCalibObjects(const GPUCalibObjectsConst &obj, const GPUNewCalibValues &vals)
bool SupportsDoublePipeline() override
void SetFinalInputCallback(std::function< void()> v)
const GPUSettingsDisplay * GetEventDisplayConfig() const
std::unique_ptr< GPUCalibObjectsConst > mNewCalibObjects
const TPCPadGainCalib * GetTPCPadGainCalib() const
std::unique_ptr< TPCPadGainCalib > mTPCPadGainCalibU
std::unique_ptr< o2::tpc::CalibdEdxContainer > mdEdxCalibContainerU
std::unique_ptr< o2::trd::GeometryFlat > mTRDGeometryU
std::unique_ptr< TPCZSLinkMapping > mTPCZSLinkMappingU
const GPUTRDRecoParam * GetTRDRecoParam() const
int32_t DoTRDGPUTracking(T *externalInstance=nullptr)
GPUTrackingFlatObjects mFlatObjectsShadow
const GPUSettingsDisplay * mConfigDisplay
void RegisterPermanentMemoryAndProcessors() override
void RegisterGPUProcessors() override
const GPUSettingsQA * GetQAConfig() const
void DumpData(const char *filename, const GPUTrackingInOutPointers *ioPtrs=nullptr)
void SetTRDRecoParam(const GPUTRDRecoParam *par)
void ClearErrorCodes(bool cpuOnly=false)
const GPUQA * GetQA() const
void MemorySize(size_t &gpuMem, size_t &pageLockedHostMem) override
std::unique_ptr< GPUTPCCFChainContext > mCFContext
void SetSubOutputControl(int32_t i, GPUOutputControl *v)
int32_t DoQueuedUpdates(int32_t stream, bool updateSlave=true)
std::unique_ptr< GPUNewCalibValues > mNewCalibValues
int32_t CheckErrorCodes(bool cpuOnly=false, bool forceShowErrors=false, std::vector< std::array< uint32_t, 4 > > *fillErrors=nullptr) override
GPUDisplayInterface * GetEventDisplay()
int32_t PrepareEvent() override
void UpdateGPUCalibObjects(int32_t stream, const GPUCalibObjectsConst *ptrMask=nullptr)
GPUTrackingInOutPointers & mIOPtrs
struct o2::gpu::GPUChainTracking::InOutMemory mIOMem
int32_t ReadData(const char *filename)
const o2::tpc::CalibdEdxContainer * GetdEdxCalibContainer() const
std::unique_ptr< GPUTrackingInputProvider > mInputsShadow
const GPUSettingsQA * mConfigQA
int32_t FinalizePipelinedProcessing() override
std::unique_ptr< GPUDisplayInterface > mEventDisplay
const TPCZSLinkMapping * GetTPCZSLinkMapping() const
void DumpSettings(const char *dir="") override
int32_t ExtrapolationTracking(uint32_t iSector, bool blocking)
std::unique_ptr< o2::tpc::ClusterNativeAccess > mClusterNativeAccessReduced
aligned_unique_buffer_ptr< TPCFastTransformPOD > mTPCFastTransformU
uint32_t DumpData(FILE *fp, const T *const *entries, const S *num, InOutPointerType type)
Definition GPUChain.h:145
GPUReconstructionCPU * mRec
Definition GPUChain.h:79
static constexpr int32_t NSECTORS
Definition GPUChain.h:58
size_t ReadData(FILE *fp, const T **entries, S *num, std::unique_ptr< T[]> *mem, InOutPointerType type, T **nonConstPtrs=nullptr)
Definition GPUChain.h:150
GPUReconstruction * rec()
Definition GPUChain.h:66
const GLdouble * v
Definition glcorearb.h:832
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLuint stream
Definition glcorearb.h:1806
PropagatorF Propagator
Definition Propagator.h:223
Definition of a container to keep/associate and arbitrary number of labels associated to an index wit...
Global TPC definitions and constants.
Definition SimTraits.h:168
std::string filename()
std::unique_ptr< o2::tpc::Digit[]> tpcDigits[NSECTORS]
std::unique_ptr< char[]> tpcCompressedClusters
std::unique_ptr< GPUTPCMCInfo[]> mcInfosTPC
std::unique_ptr< char[]> tpcDigitsMC[NSECTORS]
std::unique_ptr< GPUTRDTrackletWord[]> trdTracklets
std::unique_ptr< o2::dataformats::ConstMCTruthContainerView< o2::MCCompLabel >[]> tpcDigitMCView
std::unique_ptr< GPUTPCMCInfoCol[]> mcInfosTPCCol
std::unique_ptr< GPUTPCGMMergedTrackHit[]> mergedTrackHits
std::unique_ptr< int32_t[]> trdTrackletIdxFirst
std::unique_ptr< GPUTPCGMMergedTrack[]> mergedTracks
std::unique_ptr< AliHLTTPCClusterMCLabel[]> mcLabelsTPC
std::unique_ptr< o2::dataformats::ConstMCTruthContainerView< o2::MCCompLabel > > clusterNativeMCView
std::unique_ptr< GPUTrackingInOutDigits > digitMap
std::unique_ptr< GPUTPCClusterData[]> clusterData[NSECTORS]
std::unique_ptr< o2::tpc::ClusterNative[]> clustersNative
std::unique_ptr< GPUTPCDigitsMCInput > tpcDigitMCMap
InOutMemory & operator=(InOutMemory &&)
std::unique_ptr< float[]> trdTriggerTimes
std::unique_ptr< uint64_t[]> tpcZSpages
std::unique_ptr< GPUTPCTrack[]> sectorTracks[NSECTORS]
std::unique_ptr< GPUTRDSpacePoint[]> trdSpacePoints
std::unique_ptr< GPUTrackingInOutZS > tpcZSmeta
std::unique_ptr< o2::dataformats::ConstMCTruthContainer< o2::MCCompLabel > > clusterNativeMCBuffer
std::unique_ptr< uint8_t[]> trdTrigRecMask
std::unique_ptr< o2::tpc::ClusterNativeAccess > clusterNativeAccess
std::unique_ptr< AliHLTTPCRawCluster[]> rawClusters[NSECTORS]
std::unique_ptr< GPUTPCHitId[]> sectorClusters[NSECTORS]
std::unique_ptr< GPUSettingsTF[]> settingsTF
std::unique_ptr< GPUTRDTrackGPU[]> trdTracks
std::unique_ptr< GPUTrackingInOutZS::GPUTrackingInOutZSMeta > tpcZSmeta2
static constexpr size_t count()
std::vector< Cluster > clusters