Project
Loading...
Searching...
No Matches
GPUO2Interface.cxx
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#include "GPUO2Interface.h"
16#include "GPUReconstruction.h"
17#include "GPUChainTracking.h"
18#include "GPUChainTrackingGetters.inc"
19#include "GPUChainITS.h"
21#include "GPUOutputControl.h"
24#include "GPUParam.inc"
25#include "GPUQA.h"
26#include "GPUOutputControl.h"
28#include <iostream>
29#include <fstream>
30#include <thread>
31#include <optional>
32#include <mutex>
33
34using namespace o2::gpu;
35
37
38namespace o2::gpu
39{
41 std::unique_ptr<GPUReconstruction> mRec;
43 std::unique_ptr<GPUTrackingOutputs> mOutputRegions;
44};
45
47 std::unique_ptr<std::thread> pipelineThread;
48};
49} // namespace o2::gpu
50
52
54
56{
57 if (mNContexts) {
58 return (1);
59 }
60 mConfig.reset(new GPUO2InterfaceConfiguration(config));
61 mNContexts = mConfig->configProcessing.doublePipeline ? 2 : 1;
62 mCtx.reset(new GPUO2Interface_processingContext[mNContexts]);
63 if (mConfig->configWorkflow.inputs.isSet(gpudatatypes::InOutType::TPCRaw)) {
64 mConfig->configGRP.needsClusterer = 1;
65 }
66 if (mConfig->configWorkflow.inputs.isSet(gpudatatypes::InOutType::TPCCompressedClusters)) {
67 mConfig->configGRP.doCompClusterDecode = 1;
68 }
69 for (uint32_t i = 0; i < mNContexts; i++) {
70 if (i) {
71 mConfig->configDeviceBackend.master = mCtx[0].mRec.get();
72 }
73 mCtx[i].mRec.reset(GPUReconstruction::CreateInstance(mConfig->configDeviceBackend));
74 mConfig->configDeviceBackend.master = nullptr;
75 if (mCtx[i].mRec == nullptr) {
76 GPUError("Error obtaining instance of GPUReconstruction");
77 mNContexts = 0;
78 mCtx.reset(nullptr);
79 return 1;
80 }
81 }
82 for (uint32_t i = 0; i < mNContexts; i++) {
83 mCtx[i].mChain = mCtx[i].mRec->AddChain<GPUChainTracking>(mConfig->configInterface.maxTPCHits, mConfig->configInterface.maxTRDTracklets);
84 if (i) {
85 mCtx[i].mChain->SetQAFromForeignChain(mCtx[0].mChain);
86 }
87 mCtx[i].mChain->mConfigDisplay = &mConfig->configDisplay;
88 mCtx[i].mChain->mConfigQA = &mConfig->configQA;
89 mCtx[i].mRec->SetSettings(&mConfig->configGRP, &mConfig->configReconstruction, &mConfig->configProcessing, &mConfig->configWorkflow);
90 mCtx[i].mChain->SetCalibObjects(mConfig->configCalib);
91
92 if (i == 0 && mConfig->configWorkflow.steps.isSet(gpudatatypes::RecoStep::ITSTracking)) {
93 mChainITS = mCtx[i].mRec->AddChain<GPUChainITS>();
94 }
95
96 mCtx[i].mOutputRegions.reset(new GPUTrackingOutputs);
97 if (mConfig->configInterface.outputToExternalBuffers) {
98 for (uint32_t j = 0; j < mCtx[i].mOutputRegions->count(); j++) {
99 mCtx[i].mChain->SetSubOutputControl(j, &mCtx[i].mOutputRegions->asArray()[j]);
100 }
101 GPUOutputControl dummy;
102 dummy.set([](size_t size) -> void* {throw std::runtime_error("invalid output memory request, no common output buffer set"); return nullptr; });
103 mCtx[i].mRec->SetOutputControl(dummy);
104 }
105 }
106 for (uint32_t i = 0; i < mNContexts; i++) {
107 if (i == 0 && mCtx[i].mRec->Init()) {
108 mNContexts = 0;
109 mCtx.reset(nullptr);
110 return (1);
111 }
112 if (!mCtx[i].mRec->IsGPU() && mCtx[i].mRec->GetProcessingSettings().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_INDIVIDUAL) {
113 mCtx[i].mRec->MemoryScalers()->scalingFactor *= 2;
114 }
115 }
116 if (mConfig->configProcessing.doublePipeline) {
117 mInternals->pipelineThread.reset(new std::thread([this]() { mCtx[0].mRec->RunPipelineWorker(); }));
118 }
119 return (0);
120}
121
123{
124 if (mNContexts) {
125 if (mConfig->configProcessing.doublePipeline) {
126 mCtx[0].mRec->TerminatePipelineWorker();
127 mInternals->pipelineThread->join();
128 }
129 for (uint32_t i = 0; i < mNContexts; i++) {
130 mCtx[i].mRec->Finalize();
131 }
132 mCtx[0].mRec->Exit();
133 for (int32_t i = mNContexts - 1; i >= 0; i--) {
134 mCtx[i].mRec.reset();
135 }
136 }
137 mNContexts = 0;
138}
139
141{
142 mCtx[0].mRec->DrainPipeline();
143}
144
145void GPUO2Interface::DumpEvent(int32_t nEvent, GPUTrackingInOutPointers* data, uint32_t iThread, const char* dir)
146{
147 const auto oldPtrs = mCtx[iThread].mChain->mIOPtrs;
148 mCtx[iThread].mChain->mIOPtrs = *data;
149 char fname[1024];
150 snprintf(fname, 1024, "%sevent.%d.dump", dir, nEvent);
151 mCtx[iThread].mChain->DumpData(fname);
152 if (nEvent == 0) {
153#ifdef GPUCA_BUILD_QA
154 if (mConfig->configProcessing.runMC) {
155 mCtx[iThread].mChain->ForceInitQA();
156 snprintf(fname, 1024, "mc.%d.dump", nEvent);
157 mCtx[iThread].mChain->GetQA()->UpdateChain(mCtx[iThread].mChain);
158 mCtx[iThread].mChain->GetQA()->DumpO2MCData(fname);
159 }
160#endif
161 }
162 mCtx[iThread].mChain->mIOPtrs = oldPtrs;
163}
164
165void GPUO2Interface::DumpSettings(uint32_t iThread, const char* dir)
166{
167 mCtx[iThread].mChain->DoQueuedUpdates(-1);
168 mCtx[iThread].mRec->DumpSettings(dir);
169}
170
172{
173 if (mNContexts <= iThread) {
174 return (1);
175 }
176
177 mCtx[iThread].mChain->mIOPtrs = *data;
178
179 auto setOutputs = [this, iThread](GPUInterfaceOutputs* outputs) {
180 if (mConfig->configInterface.outputToExternalBuffers) {
181 for (uint32_t i = 0; i < mCtx[iThread].mOutputRegions->count(); i++) {
182 if (outputs->asArray()[i].allocator) {
183 mCtx[iThread].mOutputRegions->asArray()[i].set(outputs->asArray()[i].allocator);
184 } else if (outputs->asArray()[i].ptrBase) {
185 mCtx[iThread].mOutputRegions->asArray()[i].set(outputs->asArray()[i].ptrBase, outputs->asArray()[i].size);
186 } else {
187 mCtx[iThread].mOutputRegions->asArray()[i].reset();
188 }
189 }
190 }
191 };
192
193 auto inputWaitCallback = [this, iThread, inputUpdateCallback, &data, &outputs, &setOutputs]() -> int32_t {
194 GPUTrackingInOutPointers* updatedData;
195 GPUInterfaceOutputs* updatedOutputs;
196 int32_t retVal = 0;
197 if (inputUpdateCallback->callback) {
198 retVal = inputUpdateCallback->callback(updatedData, updatedOutputs);
199 if (retVal == 0) {
200 mCtx[iThread].mChain->mIOPtrs = *updatedData;
201 outputs = updatedOutputs;
202 data = updatedData;
203 setOutputs(outputs);
204 }
205 }
206 if (inputUpdateCallback->notifyCallback) {
207 inputUpdateCallback->notifyCallback();
208 }
209 return retVal;
210 };
211
212 if (inputUpdateCallback) {
213 mCtx[iThread].mChain->SetFinalInputCallback(inputWaitCallback);
214 } else {
215 mCtx[iThread].mChain->SetFinalInputCallback(nullptr);
216 }
217 if (!inputUpdateCallback || !inputUpdateCallback->callback) {
218 setOutputs(outputs);
219 }
220
221 int32_t retVal = mCtx[iThread].mRec->RunChains();
223 retVal = GPUReconstruction::retValValue::retOk; // Ignore exit signal from event display
224 }
225 if (mConfig->configQA.shipToQC && mCtx[iThread].mChain->QARanForTF()) {
226 outputs->qa.hist1 = &mCtx[iThread].mChain->GetQA()->getHistograms1D();
227 outputs->qa.hist2 = &mCtx[iThread].mChain->GetQA()->getHistograms2D();
228 outputs->qa.hist3 = &mCtx[iThread].mChain->GetQA()->getHistograms1Dd();
229 outputs->qa.hist4 = &mCtx[iThread].mChain->GetQA()->getGraphs();
230 outputs->qa.newQAHistsCreated = true;
231 }
232 *data = mCtx[iThread].mChain->mIOPtrs;
233
234 return retVal;
235}
236
237void GPUO2Interface::Clear(bool clearOutputs, uint32_t iThread) { mCtx[iThread].mRec->ClearAllocatedMemory(clearOutputs); }
238
240{
241 return mCtx[0].mRec->registerMemoryForGPU(ptr, size);
242}
243
245{
246 return mCtx[0].mRec->unregisterMemoryForGPU(ptr);
247}
248
249int32_t GPUO2Interface::UpdateCalibration(const GPUCalibObjectsConst& newCalib, const GPUNewCalibValues& newVals, uint32_t iThread)
250{
251 for (uint32_t i = 0; i < mNContexts; i++) {
252 mCtx[i].mChain->SetUpdateCalibObjects(newCalib, newVals);
253 }
254 return 0;
255}
256
257void GPUO2Interface::setErrorCodeOutput(std::vector<std::array<uint32_t, 4>>* v)
258{
259 for (uint32_t i = 0; i < mNContexts; i++) {
260 mCtx[i].mRec->setErrorCodeOutput(v);
261 }
262}
263
265{
266 trackerTraits = mChainITS->GetITSTrackerTraits();
267 vertexerTraits = mChainITS->GetITSVertexerTraits();
268 timeFrame = mChainITS->GetITSTimeframe();
269}
270
272{
273 return mCtx[iThread].mChain->GetDeviceO2Propagator();
274}
275
277{
278 prop->setGPUField(&mCtx[0].mRec->GetParam().polynomialField);
279}
280
281void GPUO2Interface::ApplySyncSettings(GPUSettingsProcessing& proc, GPUSettingsRec& rec, gpudatatypes::RecoStepField& steps, bool syncMode, int32_t dEdxMode)
282{
283 GPUChainTracking::ApplySyncSettings(proc, rec, steps, syncMode, dEdxMode);
284}
Class of a TPC cluster in TPC-native coordinates (row, time)
unsigned int uint32_t
int32_t i
int32_t retVal
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone proc
configStandalone rec
uint32_t j
Definition RawData.h:0
TBranch * ptr
o2::its::TimeFrame< 7 > * GetITSTimeframe()
o2::its::TrackerTraits< 7 > * GetITSTrackerTraits()
o2::its::VertexerTraits< 7 > * GetITSVertexerTraits()
static void ApplySyncSettings(GPUSettingsProcessing &proc, GPUSettingsRec &rec, gpudatatypes::RecoStepField &steps, bool syncMode, int32_t dEdxMode=-2)
int32_t unregisterMemoryForGPU(const void *ptr)
const o2::base::Propagator * GetDeviceO2Propagator(int32_t iThread=0) const
int32_t Initialize(const GPUO2InterfaceConfiguration &config)
void GetITSTraits(o2::its::TrackerTraits< 7 > *&trackerTraits, o2::its::VertexerTraits< 7 > *&vertexerTraits, o2::its::TimeFrame< 7 > *&timeFrame)
void DumpSettings(uint32_t iThread, const char *dir="")
void setErrorCodeOutput(std::vector< std::array< uint32_t, 4 > > *v)
void UseGPUPolynomialFieldInPropagator(o2::base::Propagator *prop) const
static void ApplySyncSettings(GPUSettingsProcessing &proc, GPUSettingsRec &rec, gpudatatypes::RecoStepField &steps, bool syncMode, int32_t dEdxMode=-2)
void DumpEvent(int32_t nEvent, GPUTrackingInOutPointers *data, uint32_t iThread, const char *dir="")
int32_t RunTracking(GPUTrackingInOutPointers *data, GPUInterfaceOutputs *outputs=nullptr, uint32_t iThread=0, GPUInterfaceInputUpdate *inputUpdateCallback=nullptr)
int32_t registerMemoryForGPU(const void *ptr, size_t size)
void Clear(bool clearOutputs, uint32_t iThread=0)
int32_t UpdateCalibration(const GPUCalibObjectsConst &newCalib, const GPUNewCalibValues &newVals, uint32_t iThread=0)
static GPUReconstruction * CreateInstance(const GPUSettingsDeviceBackend &cfg)
GLsizeiptr size
Definition glcorearb.h:659
const GLdouble * v
Definition glcorearb.h:832
std::function< int32_t(GPUTrackingInOutPointers *&data, GPUInterfaceOutputs *&outputs)> callback
const std::vector< TGraphAsymmErrors > * hist4
std::unique_ptr< std::thread > pipelineThread
std::unique_ptr< GPUReconstruction > mRec
std::unique_ptr< GPUTrackingOutputs > mOutputRegions
void set(void *p, size_t s)
std::function< void *(size_t)> allocator
GPUOutputControl * asArray()