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 "utils/HashStreamBuf.h"
23#include <atomic>
24#include <mutex>
25#include <functional>
26#include <array>
27#include <vector>
28#include <utility>
29
30namespace o2::dataformats
31{
32template <typename TruthElement>
33class ConstMCTruthContainer;
34} // namespace o2::dataformats
35
36namespace o2::trd
37{
38class GeometryFlat;
39} // namespace o2::trd
40
41namespace o2::tpc
42{
43struct ClusterNativeAccess;
44struct ClusterNative;
45class CalibdEdxContainer;
46} // namespace o2::tpc
47
48namespace o2::base
49{
50class MatLayerCylSet;
51template <typename>
52class PropagatorImpl;
53using Propagator = PropagatorImpl<float>;
54} // namespace o2::base
55
56namespace o2::gpu
57{
58// class GPUTRDTrackerGPU;
59class GPUTPCGPUTracker;
60class GPUDisplayInterface;
61class GPUQA;
62class GPUTPCClusterStatistics;
63class GPUTRDGeometry;
64class GPUTRDRecoParam;
65class TPCFastTransformPOD;
66class GPUTrackingInputProvider;
67struct GPUChainTrackingFinalContext;
68struct GPUTPCCFChainContext;
69struct GPUNewCalibValues;
70struct GPUTriggerOutputs;
71struct CfFragment;
72class GPUTPCClusterFinder;
73struct GPUSettingsProcessing;
74struct GPUSettingsRec;
75struct GPUTPCExtraADC;
76
78{
79 friend class GPUReconstruction;
80
81 public:
82 ~GPUChainTracking() override;
84 void RegisterGPUProcessors() override;
85 int32_t Init() override;
86 int32_t PrepareEvent() override;
87 int32_t Finalize() override;
88 int32_t RunChain() override;
89 void MemorySize(size_t& gpuMem, size_t& pageLockedHostMem) override;
90 int32_t CheckErrorCodes(bool cpuOnly = false, bool forceShowErrors = false, std::vector<std::array<uint32_t, 4>>* fillErrors = nullptr) override;
91 bool SupportsDoublePipeline() override { return true; }
92 int32_t FinalizePipelinedProcessing() override;
93 void ClearErrorCodes(bool cpuOnly = false);
94 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!
95 bool QARanForTF() const { return mFractionalQAEnabled; }
96 static void ApplySyncSettings(GPUSettingsProcessing& proc, GPUSettingsRec& rec, gpudatatypes::RecoStepField& steps, bool syncMode, int32_t dEdxMode = -2);
97
98 // Structures for input and output data
100
101 struct InOutMemory {
106
107 std::unique_ptr<uint64_t[]> tpcZSpages;
108 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
109 std::unique_ptr<char[]> tpcCompressedClusters; // TODO: Fix alignment
110 std::unique_ptr<GPUTrackingInOutZS> tpcZSmeta;
111 std::unique_ptr<GPUTrackingInOutZS::GPUTrackingInOutZSMeta> tpcZSmeta2;
112 std::unique_ptr<o2::tpc::Digit[]> tpcDigits[NSECTORS];
113 std::unique_ptr<GPUTrackingInOutDigits> digitMap;
114 std::unique_ptr<GPUTPCClusterData[]> clusterData[NSECTORS];
115 std::unique_ptr<AliHLTTPCRawCluster[]> rawClusters[NSECTORS];
116 std::unique_ptr<o2::tpc::ClusterNative[]> clustersNative;
117 std::unique_ptr<o2::tpc::ClusterNativeAccess> clusterNativeAccess;
118 std::unique_ptr<GPUTPCTrack[]> sectorTracks[NSECTORS];
119 std::unique_ptr<GPUTPCHitId[]> sectorClusters[NSECTORS];
120 std::unique_ptr<AliHLTTPCClusterMCLabel[]> mcLabelsTPC;
121 std::unique_ptr<GPUTPCMCInfo[]> mcInfosTPC;
122 std::unique_ptr<GPUTPCMCInfoCol[]> mcInfosTPCCol;
123 std::unique_ptr<GPUTPCGMMergedTrack[]> mergedTracks;
124 std::unique_ptr<GPUTPCGMMergedTrackHit[]> mergedTrackHits;
125 std::unique_ptr<GPUTRDTrackletWord[]> trdTracklets;
126 std::unique_ptr<GPUTRDSpacePoint[]> trdSpacePoints;
127 std::unique_ptr<float[]> trdTriggerTimes;
128 std::unique_ptr<int32_t[]> trdTrackletIdxFirst;
129 std::unique_ptr<uint8_t[]> trdTrigRecMask;
130 std::unique_ptr<GPUTRDTrackGPU[]> trdTracks;
131 std::unique_ptr<char[]> clusterNativeMC;
132 std::unique_ptr<o2::dataformats::ConstMCTruthContainerView<o2::MCCompLabel>> clusterNativeMCView;
133 std::unique_ptr<char[]> tpcDigitsMC[NSECTORS];
134 std::unique_ptr<o2::dataformats::ConstMCTruthContainerView<o2::MCCompLabel>[]> tpcDigitMCView;
135 std::unique_ptr<GPUTPCDigitsMCInput> tpcDigitMCMap;
136 std::unique_ptr<o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>> clusterNativeMCBuffer;
137 std::unique_ptr<GPUSettingsTF[]> settingsTF;
139
140 // Read / Dump / Clear Data
141 void ClearIOPointers();
142 void AllocateIOMemory();
143 using GPUChain::DumpData;
144 void DumpData(const char* filename, const GPUTrackingInOutPointers* ioPtrs = nullptr);
145 using GPUChain::ReadData;
146 int32_t ReadData(const char* filename);
147 void DumpSettings(const char* dir = "") override;
148 void ReadSettings(const char* dir = "") override;
149
150 // Converter / loader functions
153 void ConvertZSEncoder(int32_t version);
154 void ConvertZSFilter(bool zs12bit);
155
156 // Getters for external usage of tracker classes
158 const GPUQA* GetQA() const { return mQAFromForeignChain ? mQAFromForeignChain->mQA.get() : mQA.get(); }
160 int32_t ForceInitQA();
162 const GPUSettingsDisplay* GetEventDisplayConfig() const { return mConfigDisplay; }
163 const GPUSettingsQA* GetQAConfig() const { return mConfigQA; }
164
165 // Processing functions
166 int32_t RunTPCClusterizer(bool synchronizeOutput = true);
167 int32_t ForwardTPCDigits();
168 int32_t RunTPCTrackingSectors();
169 int32_t RunTPCTrackingMerger(bool synchronizeOutput = true);
170 int32_t RunTRDTracking();
171 template <int32_t I, class T = GPUTRDTracker>
172 int32_t DoTRDGPUTracking(T* externalInstance = nullptr);
173 int32_t RunTPCCompression();
174 int32_t RunTPCDecompression();
175 int32_t RunRefit();
176
177 // Getters / setters for parameters
188 void SetMatLUT(std::unique_ptr<o2::base::MatLayerCylSet>&& lut);
189 void SetTRDGeometry(std::unique_ptr<o2::trd::GeometryFlat>&& geo);
190 void SetTRDRecoParam(std::unique_ptr<GPUTRDRecoParam>&& par);
194 void SetO2Propagator(const o2::base::Propagator* prop);
199 void SetFinalInputCallback(std::function<int32_t()> v) { mWaitForFinalInputs = v; }
200
201 const GPUSettingsDisplay* mConfigDisplay = nullptr; // Abstract pointer to Standalone Display Configuration Structure
202 const GPUSettingsQA* mConfigQA = nullptr; // Abstract pointer to Standalone QA Configuration Structure
204
205 protected:
215 void UpdateGPUCalibObjects(int32_t stream, const GPUCalibObjectsConst* ptrMask = nullptr);
216 void UpdateGPUCalibObjectsPtrs(int32_t stream);
217
218 struct eventStruct // Must consist only of void* ptr that will hold the GPU event ptrs!
219 {
221 deviceEvent stream[constants::GPU_MAX_STREAMS];
224 };
225
227 void* dst;
228 void* src;
229 size_t size;
231 };
232
233 GPUChainTracking(GPUReconstruction* rec, uint32_t maxTPCHits = constants::GPU_MEM_MAX_TPC_CLUSTERS, uint32_t maxTRDTracklets = constants::GPU_MEM_MAX_TRD_TRACKLETS);
234
235 int32_t ExtrapolationTracking(uint32_t iSector, bool blocking);
236
237 int32_t PrepareProfile();
238 int32_t DoProfile();
240 void PrintMemoryStatistics() override;
243 void PrintOutputStat();
244 static void DumpClusters(std::ostream& out, const o2::tpc::ClusterNativeAccess* clusters);
246 void DoDebugRawDump();
247
248 bool ValidateSteps();
249 bool ValidateSettings();
250
251 // Pointers to tracker classes
252 GPUTrackingFlatObjects mFlatObjectsShadow; // Host copy of flat objects that will be used on the GPU
253 GPUTrackingFlatObjects mFlatObjectsDevice; // flat objects that will be used on the GPU
254 std::unique_ptr<GPUTrackingInputProvider> mInputsHost;
255 std::unique_ptr<GPUTrackingInputProvider> mInputsShadow;
256
257 // Display / QA
258 bool mDisplayRunning = false;
259 std::unique_ptr<GPUDisplayInterface> mEventDisplay;
261 std::unique_ptr<GPUQA> mQA;
262 std::unique_ptr<GPUTPCClusterStatistics> mCompressionStatistics;
263
264 // Ptr to detector / calibration objects
266 std::unique_ptr<TPCPadGainCalib> mTPCPadGainCalibU; // TPC gain calibration and cluster finder parameters
267 std::unique_ptr<TPCZSLinkMapping> mTPCZSLinkMappingU; // TPC Mapping data required by ZS Link decoder
268 std::unique_ptr<o2::tpc::CalibdEdxContainer> mdEdxCalibContainerU; // TPC dEdx calibration container
269 std::unique_ptr<o2::base::MatLayerCylSet> mMatLUTU; // Material Lookup Table
270 std::unique_ptr<o2::trd::GeometryFlat> mTRDGeometryU; // TRD Geometry
271 std::unique_ptr<GPUTRDRecoParam> mTRDRecoParamU; // TRD RecoParam
272
273 // Ptrs to internal buffers
274 std::unique_ptr<o2::tpc::ClusterNativeAccess> mClusterNativeAccess, mClusterNativeAccessReduced;
276 std::unique_ptr<GPUTriggerOutputs> mTriggerBuffer;
277
278 // (Ptrs to) configuration objects
279 std::unique_ptr<GPUTPCCFChainContext> mCFContext;
281 std::unique_ptr<GPUCalibObjectsConst> mNewCalibObjects;
283 std::unique_ptr<GPUNewCalibValues> mNewCalibValues;
284
285 // Upper bounds for memory allocation
286 uint32_t mMaxTPCHits = 0;
287 uint32_t mMaxTRDTracklets = 0;
288
289 // Debug
290 std::filebuf mDebugFileBuffer;
292 std::unique_ptr<std::ostream> mDebugFile;
293
294 // Synchronization and Locks
296 std::array<int8_t, NSECTORS> mExtrapolationTrackingDone;
297
298 std::vector<outputQueueEntry> mOutputQueue;
299
300 private:
301 int32_t RunChainFinalize();
302 void OutputSanityCheck();
303 int32_t RunTPCTrackingSectors_internal();
304 int32_t RunTPCClusterizer_prepare(bool restorePointers, const GPUTPCExtraADC& extraADCs);
305#ifndef GPUCA_RUN2
306 std::pair<uint32_t, uint32_t> RunTPCClusterizer_transferZS(int32_t iSector, const CfFragment& frag, int32_t lane, const GPUTPCExtraADC& extraADCs);
307 void RunTPCClusterizer_compactPeaks(GPUTPCClusterFinder& clusterer, GPUTPCClusterFinder& clustererShadow, int32_t stage, bool doGPU, int32_t lane);
308 std::pair<uint32_t, uint32_t> TPCClusterizerDecodeZSCount(uint32_t iSector, const CfFragment& frag);
309 std::pair<uint32_t, uint32_t> TPCClusterizerDecodeZSCountUpdate(uint32_t iSector, const CfFragment& frag);
310 void TPCClusterizerEnsureZSOffsets(uint32_t iSector, const CfFragment& frag);
311 void TPCClusterizerTransferExtraADC(GPUTPCClusterFinder& clusterer, GPUTPCClusterFinder& clustererShadow, int lane, const GPUTPCExtraADC& extraADCs);
312 void TPCClusterizerCheckExtraADCZeros(GPUTPCClusterFinder& clusterer, GPUTPCClusterFinder& clustererShadow, int lane, const GPUTPCExtraADC& extraADCs);
313#endif
314 void RunTPCTrackingMerger_MergeBorderTracks(uint8_t mergeMode, GPUReconstruction::krnlDeviceType deviceType);
315 void RunTPCTrackingMerger_Resolve(int8_t useOrigTrackParam, int8_t mergeAll, GPUReconstruction::krnlDeviceType deviceType);
316 void RunTPCClusterFilter(o2::tpc::ClusterNativeAccess* clusters, std::function<o2::tpc::ClusterNative*(size_t)> allocator, bool applyClusterCuts);
317 bool NeedTPCClustersOnGPU();
318 void WriteReducedClusters();
319 void SortClusters(bool buildNativeGPU, bool propagateMCLabels, o2::tpc::ClusterNativeAccess* clusterAccess, o2::tpc::ClusterNative* clusters);
320 template <int32_t I>
321 int32_t RunTRDTrackingInternal();
322 uint32_t StreamForSector(uint32_t sector) const;
323
324 std::mutex mMutexUpdateCalib;
325 std::unique_ptr<GPUChainTrackingFinalContext> mPipelineFinalizationCtx;
326 GPUChainTrackingFinalContext* mPipelineNotifyCtx = nullptr;
327 std::function<int32_t()> mWaitForFinalInputs;
328
329 int32_t OutputStream() const { return mRec->NStreams() - 2; }
330};
331} // namespace o2::gpu
332
333#endif
int32_t i
uint32_t iSector
GPUChain * chain
Stream buffer that supports on the fly hashing with an optional backing file buffer,...
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::unique_ptr< std::ostream > mDebugFile
std::array< GPUOutputControl *, GPUTrackingOutputs::count()> mSubOutputControls
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
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
void SetFinalInputCallback(std::function< int32_t()> v)
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
GLuint GLuint stream
Definition glcorearb.h:1806
PropagatorF Propagator
Definition Propagator.h:225
Definition of a container to keep/associate and arbitrary number of labels associated to an index wit...
Global TPC definitions and constants.
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