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 "GPUDataTypes.h"
20#include <atomic>
21#include <mutex>
22#include <functional>
23#include <array>
24#include <vector>
25#include <utility>
26
27namespace o2::dataformats
28{
29template <typename TruthElement>
30class ConstMCTruthContainer;
31} // namespace o2::dataformats
32
33namespace o2::trd
34{
35class GeometryFlat;
36} // namespace o2::trd
37
38namespace o2::tpc
39{
40struct ClusterNativeAccess;
41struct ClusterNative;
42class CalibdEdxContainer;
43} // namespace o2::tpc
44
45namespace o2::base
46{
47class MatLayerCylSet;
48template <typename>
49class PropagatorImpl;
50using Propagator = PropagatorImpl<float>;
51} // namespace o2::base
52
53namespace o2::gpu
54{
55// class GPUTRDTrackerGPU;
56class GPUTPCGPUTracker;
57class GPUDisplayInterface;
58class GPUQA;
59class GPUTPCClusterStatistics;
60class GPUTRDGeometry;
61class TPCFastTransform;
62class GPUTrackingInputProvider;
63struct GPUChainTrackingFinalContext;
64struct GPUTPCCFChainContext;
65struct GPUNewCalibValues;
66struct GPUTriggerOutputs;
67struct CfFragment;
68class GPUTPCClusterFinder;
69
71{
72 friend class GPUReconstruction;
73
74 public:
77 void RegisterGPUProcessors() override;
78 int32_t Init() override;
79 int32_t PrepareEvent() override;
80 int32_t Finalize() override;
81 int32_t RunChain() override;
82 void MemorySize(size_t& gpuMem, size_t& pageLockedHostMem) override;
83 int32_t CheckErrorCodes(bool cpuOnly = false, bool forceShowErrors = false, std::vector<std::array<uint32_t, 4>>* fillErrors = nullptr) override;
84 bool SupportsDoublePipeline() override { return true; }
85 int32_t FinalizePipelinedProcessing() override;
86 void ClearErrorCodes(bool cpuOnly = false);
87 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!
88 bool QARanForTF() const { return mFractionalQAEnabled; }
89
90 // Structures for input and output data
92
93 struct InOutMemory {
98
99 std::unique_ptr<uint64_t[]> tpcZSpages;
100 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
101 std::unique_ptr<char[]> tpcCompressedClusters; // TODO: Fix alignment
102 std::unique_ptr<GPUTrackingInOutZS> tpcZSmeta;
103 std::unique_ptr<GPUTrackingInOutZS::GPUTrackingInOutZSMeta> tpcZSmeta2;
104 std::unique_ptr<o2::tpc::Digit[]> tpcDigits[NSECTORS];
105 std::unique_ptr<GPUTrackingInOutDigits> digitMap;
106 std::unique_ptr<GPUTPCClusterData[]> clusterData[NSECTORS];
107 std::unique_ptr<AliHLTTPCRawCluster[]> rawClusters[NSECTORS];
108 std::unique_ptr<o2::tpc::ClusterNative[]> clustersNative;
109 std::unique_ptr<o2::tpc::ClusterNativeAccess> clusterNativeAccess;
110 std::unique_ptr<GPUTPCTrack[]> sectorTracks[NSECTORS];
111 std::unique_ptr<GPUTPCHitId[]> sectorClusters[NSECTORS];
112 std::unique_ptr<AliHLTTPCClusterMCLabel[]> mcLabelsTPC;
113 std::unique_ptr<GPUTPCMCInfo[]> mcInfosTPC;
114 std::unique_ptr<GPUTPCMCInfoCol[]> mcInfosTPCCol;
115 std::unique_ptr<GPUTPCGMMergedTrack[]> mergedTracks;
116 std::unique_ptr<GPUTPCGMMergedTrackHit[]> mergedTrackHits;
117 std::unique_ptr<GPUTPCGMMergedTrackHitXYZ[]> mergedTrackHitsXYZ;
118 std::unique_ptr<GPUTRDTrackletWord[]> trdTracklets;
119 std::unique_ptr<GPUTRDSpacePoint[]> trdSpacePoints;
120 std::unique_ptr<float[]> trdTriggerTimes;
121 std::unique_ptr<int32_t[]> trdTrackletIdxFirst;
122 std::unique_ptr<uint8_t[]> trdTrigRecMask;
123 std::unique_ptr<GPUTRDTrackGPU[]> trdTracks;
124 std::unique_ptr<char[]> clusterNativeMC;
125 std::unique_ptr<o2::dataformats::ConstMCTruthContainerView<o2::MCCompLabel>> clusterNativeMCView;
126 std::unique_ptr<char[]> tpcDigitsMC[NSECTORS];
127 std::unique_ptr<o2::dataformats::ConstMCTruthContainerView<o2::MCCompLabel>[]> tpcDigitMCView;
128 std::unique_ptr<GPUTPCDigitsMCInput> tpcDigitMCMap;
129 std::unique_ptr<o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>> clusterNativeMCBuffer;
130 std::unique_ptr<GPUSettingsTF[]> settingsTF;
132
133 // Read / Dump / Clear Data
134 void ClearIOPointers();
135 void AllocateIOMemory();
136 using GPUChain::DumpData;
137 void DumpData(const char* filename);
138 using GPUChain::ReadData;
139 int32_t ReadData(const char* filename);
140 void DumpSettings(const char* dir = "") override;
141 void ReadSettings(const char* dir = "") override;
142
143 // Converter / loader functions
147 void ConvertZSEncoder(int32_t version);
148 void ConvertZSFilter(bool zs12bit);
149
150 // Getters for external usage of tracker classes
152 const GPUQA* GetQA() const { return mQAFromForeignChain ? mQAFromForeignChain->mQA.get() : mQA.get(); }
154 int32_t ForceInitQA();
156 const GPUSettingsDisplay* GetEventDisplayConfig() const { return mConfigDisplay; }
157 const GPUSettingsQA* GetQAConfig() const { return mConfigQA; }
158
159 // Processing functions
160 int32_t RunTPCClusterizer(bool synchronizeOutput = true);
161 int32_t ForwardTPCDigits();
162 int32_t RunTPCTrackingSectors();
163 int32_t RunTPCTrackingMerger(bool synchronizeOutput = true);
164 int32_t RunTRDTracking();
165 template <int32_t I, class T = GPUTRDTracker>
166 int32_t DoTRDGPUTracking(T* externalInstance = nullptr);
167 int32_t RunTPCCompression();
168 int32_t RunTPCDecompression();
169 int32_t RunRefit();
170
171 // Getters / setters for parameters
180 void SetTPCFastTransform(std::unique_ptr<TPCFastTransform>&& tpcFastTransform, std::unique_ptr<CorrectionMapsHelper>&& tpcTransformHelper);
181 void SetMatLUT(std::unique_ptr<o2::base::MatLayerCylSet>&& lut);
182 void SetTRDGeometry(std::unique_ptr<o2::trd::GeometryFlat>&& geo);
185 void SetO2Propagator(const o2::base::Propagator* prop);
190 void SetFinalInputCallback(std::function<void()> v) { mWaitForFinalInputs = v; }
191
192 const GPUSettingsDisplay* mConfigDisplay = nullptr; // Abstract pointer to Standalone Display Configuration Structure
193 const GPUSettingsQA* mConfigQA = nullptr; // Abstract pointer to Standalone QA Configuration Structure
195
196 protected:
208 void UpdateGPUCalibObjects(int32_t stream, const GPUCalibObjectsConst* ptrMask = nullptr);
209 void UpdateGPUCalibObjectsPtrs(int32_t stream);
210
211 struct eventStruct // Must consist only of void* ptr that will hold the GPU event ptrs!
212 {
217 };
218
220 void* dst;
221 void* src;
222 size_t size;
224 };
225
226 GPUChainTracking(GPUReconstruction* rec, uint32_t maxTPCHits = GPUCA_MAX_CLUSTERS, uint32_t maxTRDTracklets = GPUCA_MAX_TRD_TRACKLETS);
227
228 int32_t ExtrapolationTracking(uint32_t iSector, bool blocking);
229
230 int32_t PrepareProfile();
231 int32_t DoProfile();
233 void PrintMemoryStatistics() override;
234 void PrepareDebugOutput();
235 void PrintDebugOutput();
236 void PrintOutputStat();
237
238 bool ValidateSteps();
239 bool ValidateSettings();
240
241 // Pointers to tracker classes
242 GPUTrackingFlatObjects mFlatObjectsShadow; // Host copy of flat objects that will be used on the GPU
243 GPUTrackingFlatObjects mFlatObjectsDevice; // flat objects that will be used on the GPU
244 std::unique_ptr<GPUTrackingInputProvider> mInputsHost;
245 std::unique_ptr<GPUTrackingInputProvider> mInputsShadow;
246
247 // Display / QA
248 bool mDisplayRunning = false;
249 std::unique_ptr<GPUDisplayInterface> mEventDisplay;
251 std::unique_ptr<GPUQA> mQA;
252 std::unique_ptr<GPUTPCClusterStatistics> mCompressionStatistics;
253
254 // Ptr to detector / calibration objects
255 std::unique_ptr<TPCFastTransform> mTPCFastTransformU; // Global TPC fast transformation object
256 std::unique_ptr<TPCFastTransform> mTPCFastTransformRefU; // Global TPC fast transformation ref object
257 std::unique_ptr<TPCFastTransform> mTPCFastTransformMShapeU; // Global TPC fast transformation for M-shape object
258 std::unique_ptr<CorrectionMapsHelper> mTPCFastTransformHelperU; // Global TPC fast transformation helper object
259 std::unique_ptr<TPCPadGainCalib> mTPCPadGainCalibU; // TPC gain calibration and cluster finder parameters
260 std::unique_ptr<TPCZSLinkMapping> mTPCZSLinkMappingU; // TPC Mapping data required by ZS Link decoder
261 std::unique_ptr<o2::tpc::CalibdEdxContainer> mdEdxCalibContainerU; // TPC dEdx calibration container
262 std::unique_ptr<o2::base::MatLayerCylSet> mMatLUTU; // Material Lookup Table
263 std::unique_ptr<o2::trd::GeometryFlat> mTRDGeometryU; // TRD Geometry
264
265 // Ptrs to internal buffers
266 std::unique_ptr<o2::tpc::ClusterNativeAccess> mClusterNativeAccess;
268 std::unique_ptr<GPUTriggerOutputs> mTriggerBuffer;
269
270 // (Ptrs to) configuration objects
271 std::unique_ptr<GPUTPCCFChainContext> mCFContext;
273 std::unique_ptr<GPUCalibObjectsConst> mNewCalibObjects;
275 std::unique_ptr<GPUNewCalibValues> mNewCalibValues;
276
277 // Upper bounds for memory allocation
278 uint32_t mMaxTPCHits = 0;
279 uint32_t mMaxTRDTracklets = 0;
280
281 // Debug
282 std::unique_ptr<std::ofstream> mDebugFile;
283
284 // Synchronization and Locks
286 std::array<int8_t, NSECTORS> mExtrapolationTrackingDone;
287
288 std::vector<outputQueueEntry> mOutputQueue;
289
290 private:
291 int32_t RunChainFinalize();
292 void SanityCheck();
293 int32_t RunTPCTrackingSectors_internal();
294 int32_t RunTPCClusterizer_prepare(bool restorePointers);
295#ifdef GPUCA_TPC_GEOMETRY_O2
296 std::pair<uint32_t, uint32_t> RunTPCClusterizer_transferZS(int32_t iSector, const CfFragment& fragment, int32_t lane);
297 void RunTPCClusterizer_compactPeaks(GPUTPCClusterFinder& clusterer, GPUTPCClusterFinder& clustererShadow, int32_t stage, bool doGPU, int32_t lane);
298 std::pair<uint32_t, uint32_t> TPCClusterizerDecodeZSCount(uint32_t iSector, const CfFragment& fragment);
299 std::pair<uint32_t, uint32_t> TPCClusterizerDecodeZSCountUpdate(uint32_t iSector, const CfFragment& fragment);
300 void TPCClusterizerEnsureZSOffsets(uint32_t iSector, const CfFragment& fragment);
301#endif
302 void RunTPCTrackingMerger_MergeBorderTracks(int8_t withinSector, int8_t mergeMode, GPUReconstruction::krnlDeviceType deviceType);
303 void RunTPCTrackingMerger_Resolve(int8_t useOrigTrackParam, int8_t mergeAll, GPUReconstruction::krnlDeviceType deviceType);
304 void RunTPCClusterFilter(o2::tpc::ClusterNativeAccess* clusters, std::function<o2::tpc::ClusterNative*(size_t)> allocator, bool applyClusterCuts);
305 bool NeedTPCClustersOnGPU();
306 template <int32_t I>
307 int32_t RunTRDTrackingInternal();
308 uint32_t StreamForSector(uint32_t sector) const;
309
310 std::mutex mMutexUpdateCalib;
311 std::unique_ptr<GPUChainTrackingFinalContext> mPipelineFinalizationCtx;
312 GPUChainTrackingFinalContext* mPipelineNotifyCtx = nullptr;
313 std::function<void()> mWaitForFinalInputs;
314
315 int32_t OutputStream() const { return mRec->NStreams() - 2; }
316};
317} // namespace o2::gpu
318
319#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)
void SetQAFromForeignChain(GPUChainTracking *chain)
std::unique_ptr< o2::base::MatLayerCylSet > mMatLUTU
const CorrectionMapsHelper * GetTPCTransformHelper() const
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
void UpdateGPUCalibObjectsPtrs(int32_t stream)
void DumpData(const char *filename)
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 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)
uint32_t DumpData(FILE *fp, const T *const *entries, const S *num, InOutPointerType type)
Definition GPUChain.h:143
GPUReconstructionCPU * mRec
Definition GPUChain.h:78
static constexpr int32_t NSECTORS
Definition GPUChain.h:57
size_t ReadData(FILE *fp, const T **entries, S *num, std::unique_ptr< T[]> *mem, InOutPointerType type, T **nonConstPtrs=nullptr)
Definition GPUChain.h:148
GPUReconstruction * rec()
Definition GPUChain.h:65
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:182
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:167
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< GPUTPCGMMergedTrackHitXYZ[]> mergedTrackHitsXYZ
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