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"
21#include <atomic>
22#include <mutex>
23#include <functional>
24#include <array>
25#include <vector>
26#include <utility>
27
28namespace o2::dataformats
29{
30template <typename TruthElement>
31class ConstMCTruthContainer;
32} // namespace o2::dataformats
33
34namespace o2::trd
35{
36class GeometryFlat;
37} // namespace o2::trd
38
39namespace o2::tpc
40{
41struct ClusterNativeAccess;
42struct ClusterNative;
43class CalibdEdxContainer;
44} // namespace o2::tpc
45
46namespace o2::base
47{
48class MatLayerCylSet;
49template <typename>
50class PropagatorImpl;
51using Propagator = PropagatorImpl<float>;
52} // namespace o2::base
53
54namespace o2::gpu
55{
56// class GPUTRDTrackerGPU;
57class GPUTPCGPUTracker;
58class GPUDisplayInterface;
59class GPUQA;
60class GPUTPCClusterStatistics;
61class GPUTRDGeometry;
62class TPCFastTransform;
63class GPUTrackingInputProvider;
64struct GPUChainTrackingFinalContext;
65struct GPUTPCCFChainContext;
66struct GPUNewCalibValues;
67struct GPUTriggerOutputs;
68struct CfFragment;
69class GPUTPCClusterFinder;
70struct GPUSettingsProcessing;
71struct GPUSettingsRec;
72
74{
75 friend class GPUReconstruction;
76
77 public:
80 void RegisterGPUProcessors() override;
81 int32_t Init() override;
82 int32_t PrepareEvent() override;
83 int32_t Finalize() override;
84 int32_t RunChain() override;
85 void MemorySize(size_t& gpuMem, size_t& pageLockedHostMem) override;
86 int32_t CheckErrorCodes(bool cpuOnly = false, bool forceShowErrors = false, std::vector<std::array<uint32_t, 4>>* fillErrors = nullptr) override;
87 bool SupportsDoublePipeline() override { return true; }
88 int32_t FinalizePipelinedProcessing() override;
89 void ClearErrorCodes(bool cpuOnly = false);
90 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!
91 bool QARanForTF() const { return mFractionalQAEnabled; }
92 static void ApplySyncSettings(GPUSettingsProcessing& proc, GPUSettingsRec& rec, gpudatatypes::RecoStepField& steps, bool syncMode, int32_t dEdxMode = -2);
93
94 // Structures for input and output data
96
97 struct InOutMemory {
102
103 std::unique_ptr<uint64_t[]> tpcZSpages;
104 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
105 std::unique_ptr<char[]> tpcCompressedClusters; // TODO: Fix alignment
106 std::unique_ptr<GPUTrackingInOutZS> tpcZSmeta;
107 std::unique_ptr<GPUTrackingInOutZS::GPUTrackingInOutZSMeta> tpcZSmeta2;
108 std::unique_ptr<o2::tpc::Digit[]> tpcDigits[NSECTORS];
109 std::unique_ptr<GPUTrackingInOutDigits> digitMap;
110 std::unique_ptr<GPUTPCClusterData[]> clusterData[NSECTORS];
111 std::unique_ptr<AliHLTTPCRawCluster[]> rawClusters[NSECTORS];
112 std::unique_ptr<o2::tpc::ClusterNative[]> clustersNative;
113 std::unique_ptr<o2::tpc::ClusterNativeAccess> clusterNativeAccess;
114 std::unique_ptr<GPUTPCTrack[]> sectorTracks[NSECTORS];
115 std::unique_ptr<GPUTPCHitId[]> sectorClusters[NSECTORS];
116 std::unique_ptr<AliHLTTPCClusterMCLabel[]> mcLabelsTPC;
117 std::unique_ptr<GPUTPCMCInfo[]> mcInfosTPC;
118 std::unique_ptr<GPUTPCMCInfoCol[]> mcInfosTPCCol;
119 std::unique_ptr<GPUTPCGMMergedTrack[]> mergedTracks;
120 std::unique_ptr<GPUTPCGMMergedTrackHit[]> mergedTrackHits;
121 std::unique_ptr<GPUTRDTrackletWord[]> trdTracklets;
122 std::unique_ptr<GPUTRDSpacePoint[]> trdSpacePoints;
123 std::unique_ptr<float[]> trdTriggerTimes;
124 std::unique_ptr<int32_t[]> trdTrackletIdxFirst;
125 std::unique_ptr<uint8_t[]> trdTrigRecMask;
126 std::unique_ptr<GPUTRDTrackGPU[]> trdTracks;
127 std::unique_ptr<char[]> clusterNativeMC;
128 std::unique_ptr<o2::dataformats::ConstMCTruthContainerView<o2::MCCompLabel>> clusterNativeMCView;
129 std::unique_ptr<char[]> tpcDigitsMC[NSECTORS];
130 std::unique_ptr<o2::dataformats::ConstMCTruthContainerView<o2::MCCompLabel>[]> tpcDigitMCView;
131 std::unique_ptr<GPUTPCDigitsMCInput> tpcDigitMCMap;
132 std::unique_ptr<o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>> clusterNativeMCBuffer;
133 std::unique_ptr<GPUSettingsTF[]> settingsTF;
135
136 // Read / Dump / Clear Data
137 void ClearIOPointers();
138 void AllocateIOMemory();
139 using GPUChain::DumpData;
140 void DumpData(const char* filename, const GPUTrackingInOutPointers* ioPtrs = nullptr);
141 using GPUChain::ReadData;
142 int32_t ReadData(const char* filename);
143 void DumpSettings(const char* dir = "") override;
144 void ReadSettings(const char* dir = "") override;
145
146 // Converter / loader functions
150 void ConvertZSEncoder(int32_t version);
151 void ConvertZSFilter(bool zs12bit);
152
153 // Getters for external usage of tracker classes
155 const GPUQA* GetQA() const { return mQAFromForeignChain ? mQAFromForeignChain->mQA.get() : mQA.get(); }
157 int32_t ForceInitQA();
159 const GPUSettingsDisplay* GetEventDisplayConfig() const { return mConfigDisplay; }
160 const GPUSettingsQA* GetQAConfig() const { return mConfigQA; }
161
162 // Processing functions
163 int32_t RunTPCClusterizer(bool synchronizeOutput = true);
164 int32_t ForwardTPCDigits();
165 int32_t RunTPCTrackingSectors();
166 int32_t RunTPCTrackingMerger(bool synchronizeOutput = true);
167 int32_t RunTRDTracking();
168 template <int32_t I, class T = GPUTRDTracker>
169 int32_t DoTRDGPUTracking(T* externalInstance = nullptr);
170 int32_t RunTPCCompression();
171 int32_t RunTPCDecompression();
172 int32_t RunRefit();
173
174 // Getters / setters for parameters
183 void SetTPCFastTransform(std::unique_ptr<TPCFastTransform>&& tpcFastTransform, std::unique_ptr<CorrectionMapsHelper>&& tpcTransformHelper);
184 void SetMatLUT(std::unique_ptr<o2::base::MatLayerCylSet>&& lut);
185 void SetTRDGeometry(std::unique_ptr<o2::trd::GeometryFlat>&& geo);
188 void SetO2Propagator(const o2::base::Propagator* prop);
193 void SetFinalInputCallback(std::function<void()> v) { mWaitForFinalInputs = v; }
194
195 const GPUSettingsDisplay* mConfigDisplay = nullptr; // Abstract pointer to Standalone Display Configuration Structure
196 const GPUSettingsQA* mConfigQA = nullptr; // Abstract pointer to Standalone QA Configuration Structure
198
199 protected:
211 void UpdateGPUCalibObjects(int32_t stream, const GPUCalibObjectsConst* ptrMask = nullptr);
212 void UpdateGPUCalibObjectsPtrs(int32_t stream);
213
214 struct eventStruct // Must consist only of void* ptr that will hold the GPU event ptrs!
215 {
220 };
221
223 void* dst;
224 void* src;
225 size_t size;
227 };
228
229 GPUChainTracking(GPUReconstruction* rec, uint32_t maxTPCHits = GPUCA_MAX_CLUSTERS, uint32_t maxTRDTracklets = GPUCA_MAX_TRD_TRACKLETS);
230
231 int32_t ExtrapolationTracking(uint32_t iSector, bool blocking);
232
233 int32_t PrepareProfile();
234 int32_t DoProfile();
236 void PrintMemoryStatistics() override;
239 void PrintOutputStat();
240 static void DumpClusters(std::ostream& out, const o2::tpc::ClusterNativeAccess* clusters);
242 void DoDebugRawDump();
243
244 bool ValidateSteps();
245 bool ValidateSettings();
246
247 // Pointers to tracker classes
248 GPUTrackingFlatObjects mFlatObjectsShadow; // Host copy of flat objects that will be used on the GPU
249 GPUTrackingFlatObjects mFlatObjectsDevice; // flat objects that will be used on the GPU
250 std::unique_ptr<GPUTrackingInputProvider> mInputsHost;
251 std::unique_ptr<GPUTrackingInputProvider> mInputsShadow;
252
253 // Display / QA
254 bool mDisplayRunning = false;
255 std::unique_ptr<GPUDisplayInterface> mEventDisplay;
257 std::unique_ptr<GPUQA> mQA;
258 std::unique_ptr<GPUTPCClusterStatistics> mCompressionStatistics;
259
260 // Ptr to detector / calibration objects
261 std::unique_ptr<TPCFastTransform> mTPCFastTransformU; // Global TPC fast transformation object
262 std::unique_ptr<TPCFastTransform> mTPCFastTransformRefU; // Global TPC fast transformation ref object
263 std::unique_ptr<TPCFastTransform> mTPCFastTransformMShapeU; // Global TPC fast transformation for M-shape object
264 std::unique_ptr<CorrectionMapsHelper> mTPCFastTransformHelperU; // Global TPC fast transformation helper object
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
271 // Ptrs to internal buffers
272 std::unique_ptr<o2::tpc::ClusterNativeAccess> mClusterNativeAccess, mClusterNativeAccessReduced;
274 std::unique_ptr<GPUTriggerOutputs> mTriggerBuffer;
275
276 // (Ptrs to) configuration objects
277 std::unique_ptr<GPUTPCCFChainContext> mCFContext;
279 std::unique_ptr<GPUCalibObjectsConst> mNewCalibObjects;
281 std::unique_ptr<GPUNewCalibValues> mNewCalibValues;
282
283 // Upper bounds for memory allocation
284 uint32_t mMaxTPCHits = 0;
285 uint32_t mMaxTRDTracklets = 0;
286
287 // Debug
288 std::unique_ptr<std::ofstream> mDebugFile;
289
290 // Synchronization and Locks
292 std::array<int8_t, NSECTORS> mExtrapolationTrackingDone;
293
294 std::vector<outputQueueEntry> mOutputQueue;
295
296 private:
297 int32_t RunChainFinalize();
298 void OutputSanityCheck();
299 int32_t RunTPCTrackingSectors_internal();
300 int32_t RunTPCClusterizer_prepare(bool restorePointers);
301#ifdef GPUCA_TPC_GEOMETRY_O2
302 std::pair<uint32_t, uint32_t> RunTPCClusterizer_transferZS(int32_t iSector, const CfFragment& fragment, int32_t lane);
303 void RunTPCClusterizer_compactPeaks(GPUTPCClusterFinder& clusterer, GPUTPCClusterFinder& clustererShadow, int32_t stage, bool doGPU, int32_t lane);
304 std::pair<uint32_t, uint32_t> TPCClusterizerDecodeZSCount(uint32_t iSector, const CfFragment& fragment);
305 std::pair<uint32_t, uint32_t> TPCClusterizerDecodeZSCountUpdate(uint32_t iSector, const CfFragment& fragment);
306 void TPCClusterizerEnsureZSOffsets(uint32_t iSector, const CfFragment& fragment);
307#endif
308 void RunTPCTrackingMerger_MergeBorderTracks(int8_t withinSector, int8_t mergeMode, GPUReconstruction::krnlDeviceType deviceType);
309 void RunTPCTrackingMerger_Resolve(int8_t useOrigTrackParam, int8_t mergeAll, GPUReconstruction::krnlDeviceType deviceType);
310 void RunTPCClusterFilter(o2::tpc::ClusterNativeAccess* clusters, std::function<o2::tpc::ClusterNative*(size_t)> allocator, bool applyClusterCuts);
311 bool NeedTPCClustersOnGPU();
312 void WriteReducedClusters();
313 void SortClusters(bool buildNativeGPU, bool propagateMCLabels, o2::tpc::ClusterNativeAccess* clusterAccess, o2::tpc::ClusterNative* clusters);
314 template <int32_t I>
315 int32_t RunTRDTrackingInternal();
316 uint32_t StreamForSector(uint32_t sector) const;
317
318 std::mutex mMutexUpdateCalib;
319 std::unique_ptr<GPUChainTrackingFinalContext> mPipelineFinalizationCtx;
320 GPUChainTrackingFinalContext* mPipelineNotifyCtx = nullptr;
321 std::function<void()> mWaitForFinalInputs;
322
323 int32_t OutputStream() const { return mRec->NStreams() - 2; }
324};
325} // namespace o2::gpu
326
327#endif
int32_t i
#define GPUCA_MAX_TRD_TRACKLETS
#define GPUCA_MAX_CLUSTERS
#define GPUCA_MAX_STREAMS
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
const CorrectionMapsHelper * GetTPCTransformHelper() const
static void DebugSortCompressedClusters(o2::tpc::CompressedClustersFlat *cls)
const o2::base::Propagator * GetDeviceO2Propagator()
std::unique_ptr< o2::tpc::ClusterNativeAccess > mClusterNativeAccess
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
std::unique_ptr< TPCFastTransform > mTPCFastTransformMShapeU
GPUChainTracking * mQAFromForeignChain
void SetO2Propagator(const o2::base::Propagator *prop)
std::unique_ptr< GPUQA > mQA
void ReadSettings(const char *dir="") override
std::unique_ptr< CorrectionMapsHelper > mTPCFastTransformHelperU
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
std::unique_ptr< TPCFastTransform > mTPCFastTransformRefU
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
void SetMatLUT(const o2::base::MatLayerCylSet *lut)
std::unique_ptr< GPUTPCClusterStatistics > mCompressionStatistics
const o2::base::MatLayerCylSet * GetMatLUT() const
std::array< GPUOutputControl *, GPUTrackingOutputs::count()> mSubOutputControls
std::unique_ptr< std::ofstream > mDebugFile
std::unique_ptr< GPUTriggerOutputs > mTriggerBuffer
std::vector< outputQueueEntry > mOutputQueue
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
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 ClearErrorCodes(bool cpuOnly=false)
const GPUQA * GetQA() const
void MemorySize(size_t &gpuMem, size_t &pageLockedHostMem) override
std::unique_ptr< GPUTPCCFChainContext > mCFContext
void SetTPCFastTransform(std::unique_ptr< TPCFastTransform > &&tpcFastTransform, std::unique_ptr< CorrectionMapsHelper > &&tpcTransformHelper)
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
std::unique_ptr< TPCFastTransform > mTPCFastTransformU
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
uint32_t DumpData(FILE *fp, const T *const *entries, const S *num, InOutPointerType type)
Definition GPUChain.h:144
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:149
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