Project
Loading...
Searching...
No Matches
standalone.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 "utils/qconfig.h"
16#include "GPUReconstruction.h"
19#include "GPUChainTracking.h"
20#include "GPUChainTrackingGetters.inc"
21#include "GPUTPCDef.h"
22#include "GPUQA.h"
23#include "GPUParam.h"
25#include "genEvents.h"
26
27#include "TPCFastTransform.h"
29#include "GPUTPCGMMergedTrack.h"
30#include "GPUSettings.h"
31#include "GPUConstantMem.h"
32
33#include "GPUO2DataTypes.h"
34#include "GPUChainITS.h"
35
37
38#include <iostream>
39#include <fstream>
40#include <cstdio>
41#include <cstring>
42#include <chrono>
43#include <tuple>
44#include <algorithm>
45#include <thread>
46#include <future>
47#include <atomic>
48#include <vector>
49
50#ifndef _WIN32
51#include <unistd.h>
52#include <sched.h>
53#include <csignal>
54#include <sys/types.h>
55#include <sys/wait.h>
56#include <sys/select.h>
57#include <cfenv>
58#include <clocale>
59#include <sys/stat.h>
60#endif
61#include "utils/timer.h"
63#include "utils/vecpod.h"
64
65using namespace o2::gpu;
66
67// #define BROKEN_EVENTS
68
69namespace o2::gpu
70{
71extern GPUSettingsStandalone configStandalone;
72}
73
77std::string eventsDir;
79{
80 operator delete(v, std::align_val_t(GPUCA_BUFFER_ALIGNMENT));
81}
83std::unique_ptr<GPUDisplayFrontendInterface> eventDisplay;
84std::unique_ptr<GPUReconstructionTimeframe> tf;
86std::atomic<uint32_t> nIteration, nIterationEnd;
87
88std::vector<GPUTrackingInOutPointers> ioPtrEvents;
89std::vector<GPUChainTracking::InOutMemory> ioMemEvents;
90
91int32_t ReadConfiguration(int argc, char** argv)
92{
93 int32_t qcRet = qConfigParse(argc, (const char**)argv);
94 if (qcRet) {
95 if (qcRet != qConfig::qcrHelp) {
96 printf("Error parsing command line parameters\n");
97 }
98 return 1;
99 }
100 if (configStandalone.printSettings > 1) {
101 printf("Config Dump before ReadConfiguration\n");
102 qConfigPrint();
103 }
104 if (configStandalone.proc.debugLevel == -1) {
105 configStandalone.proc.debugLevel = 0;
106 }
107#ifndef _WIN32
108 setlocale(LC_ALL, "en_US.utf-8");
109 setlocale(LC_NUMERIC, "en_US.utf-8");
110 if (configStandalone.cpuAffinity != -1) {
111 cpu_set_t mask;
112 CPU_ZERO(&mask);
113 CPU_SET(configStandalone.cpuAffinity, &mask);
114
115 printf("Setting affinitiy to restrict on CPU core %d\n", configStandalone.cpuAffinity);
116 if (0 != sched_setaffinity(0, sizeof(mask), &mask)) {
117 printf("Error setting CPU affinity\n");
118 return 1;
119 }
120 }
121 if (configStandalone.fifoScheduler) {
122 printf("Setting FIFO scheduler\n");
123 sched_param param;
124 sched_getparam(0, &param);
125 param.sched_priority = 1;
126 if (0 != sched_setscheduler(0, SCHED_FIFO, &param)) {
127 printf("Error setting scheduler\n");
128 return 1;
129 }
130 }
131#ifdef __FAST_MATH__
132 if (configStandalone.fpe == 1) {
133#else
134 if (configStandalone.fpe) {
135#endif
136 feenableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW);
137 }
138 if (configStandalone.flushDenormals) {
139 disable_denormals();
140 }
141
142#else
143 if (configStandalone.cpuAffinity != -1) {
144 printf("Affinity setting not supported on Windows\n");
145 return 1;
146 }
147 if (configStandalone.fifoScheduler) {
148 printf("FIFO Scheduler setting not supported on Windows\n");
149 return 1;
150 }
151 if (configStandalone.fpe == 1) {
152 printf("FPE not supported on Windows\n");
153 return 1;
154 }
155#endif
156#ifndef GPUCA_TPC_GEOMETRY_O2
157#error Why was configStandalone.rec.tpc.mergerReadFromTrackerDirectly = 0 needed?
158 configStandalone.proc.inKernelParallel = false;
159 configStandalone.proc.createO2Output = 0;
160 if (configStandalone.rundEdx == -1) {
161 configStandalone.rundEdx = 0;
162 }
163#endif
164#ifndef GPUCA_BUILD_QA
165 if (configStandalone.proc.runQA || configStandalone.eventGenerator) {
166 printf("QA not enabled in build\n");
167 return 1;
168 }
169#endif
170 if (configStandalone.proc.doublePipeline && configStandalone.testSyncAsync) {
171 printf("Cannot run asynchronous processing with double pipeline\n");
172 return 1;
173 }
174 if (configStandalone.proc.doublePipeline && (configStandalone.runs < 4 || !configStandalone.outputcontrolmem)) {
175 printf("Double pipeline mode needs at least 3 runs per event and external output. To cycle though multiple events, use --preloadEvents and --runs n for n iterations round-robin\n");
176 return 1;
177 }
178 if (configStandalone.TF.bunchSim && configStandalone.TF.nMerge) {
179 printf("Cannot run --MERGE and --SIMBUNCHES togeterh\n");
180 return 1;
181 }
182 if (configStandalone.TF.bunchSim > 1) {
183 configStandalone.TF.timeFrameLen = 1.e9 * configStandalone.TF.bunchSim / configStandalone.TF.interactionRate;
184 }
185 if (configStandalone.TF.nMerge) {
186 double len = configStandalone.TF.nMerge - 1;
187 if (configStandalone.TF.randomizeDistance) {
188 len += 0.5;
189 }
190 if (configStandalone.TF.shiftFirstEvent) {
191 len += 0.5;
192 }
194 }
195 if (configStandalone.QA.inputHistogramsOnly && configStandalone.QA.compareInputs.size() == 0) {
196 printf("Can only produce QA pdf output when input files are specified!\n");
197 return 1;
198 }
199 if (configStandalone.QA.inputHistogramsOnly) {
200 configStandalone.rundEdx = false;
201 }
202 if (configStandalone.QA.dumpToROOT) {
203 configStandalone.proc.outputSharedClusterMap = true;
204 }
205 if (configStandalone.eventDisplay) {
206 configStandalone.noprompt = 1;
207 }
208 if (configStandalone.proc.debugLevel >= 4) {
209 if (configStandalone.proc.inKernelParallel) {
210 configStandalone.proc.inKernelParallel = 1;
211 } else {
212 configStandalone.proc.nHostThreads = 1;
213 }
214 }
215 if (configStandalone.setO2Settings) {
216 if (!(configStandalone.inputcontrolmem && configStandalone.outputcontrolmem)) {
217 printf("setO2Settings requires the usage of --inputMemory and --outputMemory as in O2\n");
218 return 1;
219 }
220 if (configStandalone.runGPU) {
221 configStandalone.proc.forceHostMemoryPoolSize = 1024 * 1024 * 1024;
222 }
223 configStandalone.rec.tpc.nWaysOuter = 1;
224 configStandalone.rec.tpc.trackReferenceX = 83;
225 configStandalone.proc.outputSharedClusterMap = 1;
226 configStandalone.proc.clearO2OutputFromGPU = 1;
227 configStandalone.QA.clusterRejectionHistograms = 1;
228 configStandalone.proc.tpcIncreasedMinClustersPerRow = 500000;
229 configStandalone.proc.ignoreNonFatalGPUErrors = 1;
230 // TODO: rundEdx=1
231 // GPU_proc.qcRunFraction=$TPC_TRACKING_QC_RUN_FRACTION;"
232 // [[ $CTFINPUT == 1 ]] && GPU_CONFIG_KEY+="GPU_proc.tpcInputWithClusterRejection=1;"
233 // double pipeline / rtc
234 }
235
236 if (configStandalone.outputcontrolmem) {
237 bool forceEmptyMemory = getenv("LD_PRELOAD") && strstr(getenv("LD_PRELOAD"), "valgrind") != nullptr;
238 outputmemory.reset((char*)operator new(configStandalone.outputcontrolmem, std::align_val_t(GPUCA_BUFFER_ALIGNMENT)));
239 if (forceEmptyMemory) {
240 printf("Valgrind detected, emptying GPU output memory to avoid false positive undefined reads");
241 memset(outputmemory.get(), 0, configStandalone.outputcontrolmem);
242 }
243 if (configStandalone.proc.doublePipeline) {
244 outputmemoryPipeline.reset((char*)operator new(configStandalone.outputcontrolmem, std::align_val_t(GPUCA_BUFFER_ALIGNMENT)));
245 if (forceEmptyMemory) {
246 memset(outputmemoryPipeline.get(), 0, configStandalone.outputcontrolmem);
247 }
248 }
249 }
250 if (configStandalone.inputcontrolmem) {
251 inputmemory.reset((char*)operator new(configStandalone.inputcontrolmem, std::align_val_t(GPUCA_BUFFER_ALIGNMENT)));
252 }
253
254 configStandalone.proc.showOutputStat = true;
255
256 if (configStandalone.runGPU && configStandalone.gpuType == "AUTO") {
257 if (GPUReconstruction::CheckInstanceAvailable(GPUReconstruction::DeviceType::CUDA, configStandalone.proc.debugLevel >= 2)) {
258 configStandalone.gpuType = "CUDA";
259 } else if (GPUReconstruction::CheckInstanceAvailable(GPUReconstruction::DeviceType::HIP, configStandalone.proc.debugLevel >= 2)) {
260 configStandalone.gpuType = "HIP";
261 } else if (GPUReconstruction::CheckInstanceAvailable(GPUReconstruction::DeviceType::OCL, configStandalone.proc.debugLevel >= 2)) {
262 configStandalone.gpuType = "OCL";
263 } else if (GPUReconstruction::CheckInstanceAvailable(GPUReconstruction::DeviceType::OCL, configStandalone.proc.debugLevel >= 2)) {
264 configStandalone.gpuType = "OCL";
265 } else {
266 if (configStandalone.runGPU > 1 && configStandalone.runGPUforce) {
267 printf("No GPU backend / device found, running on CPU is disabled due to runGPUforce\n");
268 return 1;
269 }
270 configStandalone.runGPU = false;
271 configStandalone.gpuType = "CPU";
272 }
273 }
274
275 if (configStandalone.printSettings) {
276 configStandalone.proc.printSettings = true;
277 }
278 if (configStandalone.printSettings > 1) {
279 printf("Config Dump after ReadConfiguration\n");
280 qConfigPrint();
281 }
282
283 return (0);
284}
285
287{
288 if (!configStandalone.eventGenerator) {
289 if (configStandalone.noEvents) {
290 eventsDir = "NON_EXISTING";
291 configStandalone.rundEdx = false;
292 } else if (rec->ReadSettings(eventsDir.c_str())) {
293 printf("Error reading event config file\n");
294 return 1;
295 }
296 printf("Read event settings from dir %s (solenoidBz: %f, constBz %d, maxTimeBin %d)\n", eventsDir.c_str(), rec->GetGRPSettings().solenoidBzNominalGPU, (int32_t)rec->GetGRPSettings().constBz, rec->GetGRPSettings().grpContinuousMaxTimeBin);
297 if (configStandalone.testSyncAsync) {
299 }
300 if (configStandalone.proc.doublePipeline) {
302 }
303 }
304
307
309 GPUSettingsRec recSet;
310 GPUSettingsProcessing procSet;
311 recSet = configStandalone.rec;
312 procSet = configStandalone.proc;
314
315 if (configStandalone.solenoidBzNominalGPU != -1e6f) {
316 grp.solenoidBzNominalGPU = configStandalone.solenoidBzNominalGPU;
317 }
318 if (configStandalone.constBz) {
319 grp.constBz = true;
320 }
321 if (configStandalone.TF.nMerge || configStandalone.TF.bunchSim) {
322 if (grp.grpContinuousMaxTimeBin) {
323 printf("ERROR: requested to overlay continuous data - not supported\n");
324 return 1;
325 }
326 if (!configStandalone.cont) {
327 printf("Continuous mode forced\n");
328 configStandalone.cont = true;
329 }
332 }
333 }
334 if (configStandalone.cont && grp.grpContinuousMaxTimeBin == 0) {
336 }
337 if (rec->GetDeviceType() == GPUReconstruction::DeviceType::CPU) {
338 printf("Standalone Test Framework for CA Tracker - Using CPU\n");
339 } else {
340 printf("Standalone Test Framework for CA Tracker - Using GPU\n");
341 }
342
343 configStandalone.proc.forceMemoryPoolSize = (configStandalone.proc.forceMemoryPoolSize == 1 && configStandalone.eventDisplay) ? 2 : configStandalone.proc.forceMemoryPoolSize;
344 if (configStandalone.eventDisplay) {
345 eventDisplay.reset(GPUDisplayFrontendInterface::getFrontend(configStandalone.display.displayFrontend.c_str()));
346 if (eventDisplay.get() == nullptr) {
347 throw std::runtime_error("Requested display not available");
348 }
349 printf("Enabling event display (%s backend)\n", eventDisplay->frontendName());
350 procSet.eventDisplay = eventDisplay.get();
351 if (!configStandalone.QA.noMC) {
352 procSet.runMC = true;
353 }
354 }
355
356 if (procSet.runQA && !configStandalone.QA.noMC) {
357 procSet.runMC = true;
358 }
359
360 steps.steps = GPUDataTypes::RecoStep::AllRecoSteps;
361 if (configStandalone.runTRD != -1) {
362 steps.steps.setBits(GPUDataTypes::RecoStep::TRDTracking, configStandalone.runTRD > 0);
363 } else if (chainTracking->GetTRDGeometry() == nullptr) {
364 steps.steps.setBits(GPUDataTypes::RecoStep::TRDTracking, false);
365 }
366 if (configStandalone.rundEdx != -1) {
367 steps.steps.setBits(GPUDataTypes::RecoStep::TPCdEdx, configStandalone.rundEdx > 0);
368 }
369 if (configStandalone.runCompression != -1) {
370 steps.steps.setBits(GPUDataTypes::RecoStep::TPCCompression, configStandalone.runCompression > 0);
371 }
372 if (configStandalone.runTransformation != -1) {
373 steps.steps.setBits(GPUDataTypes::RecoStep::TPCConversion, configStandalone.runTransformation > 0);
374 }
375 steps.steps.setBits(GPUDataTypes::RecoStep::Refit, configStandalone.runRefit);
376 if (!configStandalone.runMerger) {
377 steps.steps.setBits(GPUDataTypes::RecoStep::TPCMerging, false);
378 steps.steps.setBits(GPUDataTypes::RecoStep::TRDTracking, false);
379 steps.steps.setBits(GPUDataTypes::RecoStep::TPCdEdx, false);
380 steps.steps.setBits(GPUDataTypes::RecoStep::TPCCompression, false);
381 steps.steps.setBits(GPUDataTypes::RecoStep::Refit, false);
382 }
383
384 if (configStandalone.TF.bunchSim || configStandalone.TF.nMerge) {
385 steps.steps.setBits(GPUDataTypes::RecoStep::TRDTracking, false);
386 }
387 steps.inputs.set(GPUDataTypes::InOutType::TPCClusters, GPUDataTypes::InOutType::TRDTracklets);
388 steps.steps.setBits(GPUDataTypes::RecoStep::TPCDecompression, false);
389 steps.inputs.setBits(GPUDataTypes::InOutType::TPCCompressedClusters, false);
390 if (grp.doCompClusterDecode) {
391 steps.inputs.setBits(GPUDataTypes::InOutType::TPCCompressedClusters, true);
392 steps.inputs.setBits(GPUDataTypes::InOutType::TPCClusters, false);
393 steps.steps.setBits(GPUDataTypes::RecoStep::TPCCompression, false);
394 steps.steps.setBits(GPUDataTypes::RecoStep::TPCClusterFinding, false);
395 steps.steps.setBits(GPUDataTypes::RecoStep::TPCDecompression, true);
396 steps.outputs.setBits(GPUDataTypes::InOutType::TPCCompressedClusters, false);
397 } else if (grp.needsClusterer) {
398 steps.inputs.setBits(GPUDataTypes::InOutType::TPCRaw, true);
399 steps.inputs.setBits(GPUDataTypes::InOutType::TPCClusters, false);
400 } else {
401 steps.steps.setBits(GPUDataTypes::RecoStep::TPCClusterFinding, false);
402 }
403
404 if (configStandalone.recoSteps >= 0) {
405 steps.steps &= configStandalone.recoSteps;
406 }
407 if (configStandalone.recoStepsGPU >= 0) {
408 steps.stepsGPUMask &= configStandalone.recoStepsGPU;
409 }
410
411 steps.outputs.clear();
412 steps.outputs.setBits(GPUDataTypes::InOutType::TPCMergedTracks, steps.steps.isSet(GPUDataTypes::RecoStep::TPCMerging));
413 steps.outputs.setBits(GPUDataTypes::InOutType::TPCCompressedClusters, steps.steps.isSet(GPUDataTypes::RecoStep::TPCCompression));
414 steps.outputs.setBits(GPUDataTypes::InOutType::TRDTracks, steps.steps.isSet(GPUDataTypes::RecoStep::TRDTracking));
415 steps.outputs.setBits(GPUDataTypes::InOutType::TPCClusters, steps.steps.isSet(GPUDataTypes::RecoStep::TPCClusterFinding));
416
417 if (steps.steps.isSet(GPUDataTypes::RecoStep::TRDTracking)) {
418 if (recSet.tpc.nWays > 1) {
419 recSet.tpc.nWaysOuter = 1;
420 }
421 if (procSet.createO2Output && !procSet.trdTrackModelO2) {
422 procSet.createO2Output = 1; // Must not be 2, to make sure TPC GPU tracks are still available for TRD
423 }
424 }
425
426 if (configStandalone.testSyncAsync || configStandalone.testSync) {
427 // Set settings for synchronous
428 if (configStandalone.rundEdx == -1) {
429 steps.steps.setBits(GPUDataTypes::RecoStep::TPCdEdx, 0);
430 }
431 recSet.useMatLUT = false;
432 if (configStandalone.testSyncAsync) {
433 procSet.eventDisplay = nullptr;
434 }
435 }
436 if (configStandalone.proc.rtc.optSpecialCode == -1) {
437 configStandalone.proc.rtc.optSpecialCode = configStandalone.testSyncAsync || configStandalone.testSync;
438 }
439
440 rec->SetSettings(&grp, &recSet, &procSet, &steps);
441 if (configStandalone.proc.doublePipeline) {
442 recPipeline->SetSettings(&grp, &recSet, &procSet, &steps);
443 }
444 if (configStandalone.testSyncAsync) {
445 // Set settings for asynchronous
446 steps.steps.setBits(GPUDataTypes::RecoStep::TPCDecompression, true);
447 steps.steps.setBits(GPUDataTypes::RecoStep::TPCdEdx, true);
448 steps.steps.setBits(GPUDataTypes::RecoStep::TPCCompression, false);
449 steps.steps.setBits(GPUDataTypes::RecoStep::TPCClusterFinding, false);
450 steps.inputs.setBits(GPUDataTypes::InOutType::TPCRaw, false);
451 steps.inputs.setBits(GPUDataTypes::InOutType::TPCClusters, false);
452 steps.inputs.setBits(GPUDataTypes::InOutType::TPCCompressedClusters, true);
453 steps.outputs.setBits(GPUDataTypes::InOutType::TPCCompressedClusters, false);
454 procSet.runMC = false;
455 procSet.runQA = false;
456 procSet.eventDisplay = eventDisplay.get();
457 procSet.runCompressionStatistics = 0;
458 procSet.rtc.optSpecialCode = 0;
459 if (recSet.tpc.rejectionStrategy >= GPUSettings::RejectionStrategyB) {
460 procSet.tpcInputWithClusterRejection = 1;
461 }
462 recSet.tpc.disableRefitAttachment = 0xFF;
463 recSet.tpc.looperInterpolationInExtraPass = 0;
464 recSet.maxTrackQPtB5 = CAMath::Min(recSet.maxTrackQPtB5, recSet.tpc.rejectQPtB5);
465 recSet.useMatLUT = true;
466 recAsync->SetSettings(&grp, &recSet, &procSet, &steps);
467 }
468
469 if (configStandalone.outputcontrolmem) {
470 rec->SetOutputControl(outputmemory.get(), configStandalone.outputcontrolmem);
471 if (configStandalone.proc.doublePipeline) {
473 }
474 }
475
476 o2::base::Propagator* prop = nullptr;
478 prop->setGPUField(&rec->GetParam().polynomialField);
479 prop->setNominalBz(rec->GetParam().bzkG);
480 prop->setMatLUT(chainTracking->GetMatLUT());
482 if (chainTrackingAsync) {
484 }
487 }
488 procSet.o2PropagatorUseGPUField = true;
489
490 if (rec->Init()) {
491 printf("Error initializing GPUReconstruction!\n");
492 return 1;
493 }
494 if (configStandalone.outputcontrolmem && rec->IsGPU()) {
495 if (rec->registerMemoryForGPU(outputmemory.get(), configStandalone.outputcontrolmem) || (configStandalone.proc.doublePipeline && recPipeline->registerMemoryForGPU(outputmemoryPipeline.get(), configStandalone.outputcontrolmem))) {
496 printf("ERROR registering memory for the GPU!!!\n");
497 return 1;
498 }
499 }
500 if (configStandalone.inputcontrolmem && rec->IsGPU()) {
501 if (rec->registerMemoryForGPU(inputmemory.get(), configStandalone.inputcontrolmem)) {
502 printf("ERROR registering input memory for the GPU!!!\n");
503 return 1;
504 }
505 }
506 if (configStandalone.proc.debugLevel >= 4) {
508 }
509 return (0);
510}
511
512int32_t ReadEvent(int32_t n)
513{
514 if (configStandalone.inputcontrolmem && !configStandalone.preloadEvents) {
515 rec->SetInputControl(inputmemory.get(), configStandalone.inputcontrolmem);
516 }
517 int32_t r = chainTracking->ReadData((eventsDir + GPUCA_EVDUMP_FILE "." + std::to_string(n) + ".dump").c_str());
518 if (r) {
519 return r;
520 }
521#if defined(GPUCA_TPC_GEOMETRY_O2) && defined(GPUCA_BUILD_QA) && !defined(GPUCA_O2_LIB)
522 if ((configStandalone.proc.runQA || configStandalone.eventDisplay) && !configStandalone.QA.noMC) {
525 if (chainTracking->GetQA()->ReadO2MCData((eventsDir + "mc." + std::to_string(n) + ".dump").c_str()) &&
526 chainTracking->GetQA()->ReadO2MCData((eventsDir + "mc.0.dump").c_str()) && configStandalone.proc.runQA) {
527 throw std::runtime_error("Error reading O2 MC dump");
528 }
529 }
530#endif
531 if (chainTracking->mIOPtrs.clustersNative && (configStandalone.TF.bunchSim || configStandalone.TF.nMerge || !configStandalone.runTransformation)) {
532 if (configStandalone.proc.debugLevel >= 2) {
533 printf("Converting Native to Legacy ClusterData for overlaying - WARNING: No raw clusters produced - Compression etc will not run!!!\n");
534 }
536 }
537 return 0;
538}
539
540int32_t LoadEvent(int32_t iEvent, int32_t x)
541{
542 if (configStandalone.TF.bunchSim) {
543 if (tf->LoadCreateTimeFrame(iEvent)) {
544 return 1;
545 }
546 } else if (configStandalone.TF.nMerge) {
547 if (tf->LoadMergedEvents(iEvent)) {
548 return 1;
549 }
550 } else {
551 if (ReadEvent(iEvent)) {
552 return 1;
553 }
554 }
555 bool encodeZS = configStandalone.encodeZS == -1 ? (chainTracking->mIOPtrs.tpcPackedDigits && !chainTracking->mIOPtrs.tpcZS) : (bool)configStandalone.encodeZS;
556 bool zsFilter = configStandalone.zsFilter == -1 ? (!encodeZS && chainTracking->mIOPtrs.tpcPackedDigits && !chainTracking->mIOPtrs.tpcZS) : (bool)configStandalone.zsFilter;
557 if (encodeZS || zsFilter) {
559 printf("Need digit input to run ZS\n");
560 return 1;
561 }
562 if (zsFilter) {
564 }
565 if (encodeZS) {
567 }
568 }
569 if (!configStandalone.runTransformation) {
571 } else {
572 for (int32_t i = 0; i < chainTracking->NSECTORS; i++) {
574 if (configStandalone.proc.debugLevel >= 2) {
575 printf("Converting Legacy Raw Cluster to Native\n");
576 }
578 break;
579 }
580 }
581 }
582
583 if (configStandalone.stripDumpedEvents) {
586 }
587 }
588
590 printf("Need cluster native data for on-the-fly TPC transform\n");
591 return 1;
592 }
593
595 ioMemEvents[x] = std::move(chainTracking->mIOMem);
597 return 0;
598}
599
600void OutputStat(GPUChainTracking* t, int64_t* nTracksTotal = nullptr, int64_t* nClustersTotal = nullptr)
601{
602 int32_t nTracks = 0;
603 if (t->GetProcessingSettings().createO2Output) {
604 nTracks += t->mIOPtrs.nOutputTracksTPCO2;
605 } else {
606 for (uint32_t k = 0; k < t->mIOPtrs.nMergedTracks; k++) {
607 if (t->mIOPtrs.mergedTracks[k].OK()) {
608 nTracks++;
609 }
610 }
611 }
612 if (nTracksTotal && nClustersTotal) {
613 *nTracksTotal += nTracks;
614 *nClustersTotal += t->mIOPtrs.nMergedTrackHits;
615 }
616}
617
618int32_t RunBenchmark(GPUReconstruction* recUse, GPUChainTracking* chainTrackingUse, int32_t runs, int32_t iEvent, int64_t* nTracksTotal, int64_t* nClustersTotal, int32_t threadId = 0, HighResTimer* timerPipeline = nullptr)
619{
620 int32_t iRun = 0, iteration = 0;
621 while ((iteration = nIteration.fetch_add(1)) < runs) {
622 if (configStandalone.runs > 1) {
623 printf("Run %d (thread %d)\n", iteration + 1, threadId);
624 }
625 recUse->SetResetTimers(iRun < configStandalone.runsInit);
626 if (configStandalone.outputcontrolmem) {
627 recUse->SetOutputControl(threadId ? outputmemoryPipeline.get() : outputmemory.get(), configStandalone.outputcontrolmem);
628 }
629
630 if (configStandalone.testSyncAsync) {
631 printf("Running synchronous phase\n");
632 }
633 const GPUTrackingInOutPointers& ioPtrs = ioPtrEvents[!configStandalone.preloadEvents ? 0 : configStandalone.proc.doublePipeline ? (iteration % ioPtrEvents.size()) : (iEvent - configStandalone.StartEvent)];
634 chainTrackingUse->mIOPtrs = ioPtrs;
635 if (iteration == (configStandalone.proc.doublePipeline ? 2 : (configStandalone.runs - 1))) {
636 if (configStandalone.proc.doublePipeline && timerPipeline) {
637 timerPipeline->Start();
638 }
639 if (configStandalone.controlProfiler) {
641 }
642 }
643 int32_t tmpRetVal = recUse->RunChains();
644 int32_t iterationEnd = nIterationEnd.fetch_add(1);
645 if (iterationEnd == configStandalone.runs - 1) {
646 if (configStandalone.proc.doublePipeline && timerPipeline) {
647 timerPipeline->Stop();
648 }
649 if (configStandalone.controlProfiler) {
651 }
652 }
653
654 if (tmpRetVal == 0 || tmpRetVal == 2) {
655 OutputStat(chainTrackingUse, iRun == 0 ? nTracksTotal : nullptr, iRun == 0 ? nClustersTotal : nullptr);
656 if (configStandalone.memoryStat) {
657 recUse->PrintMemoryStatistics();
658 } else if (configStandalone.proc.debugLevel >= 2) {
659 recUse->PrintMemoryOverview();
660 }
661 }
662
663 if (tmpRetVal == 0 && configStandalone.testSyncAsync) {
664 if (configStandalone.testSyncAsync) {
665 printf("Running asynchronous phase\n");
666 }
667
670
671 chainTrackingAsync->mIOPtrs = ioPtrs;
681 for (int32_t i = 0; i < chainTracking->NSECTORS; i++) {
686 }
688 recAsync->SetResetTimers(iRun < configStandalone.runsInit);
689 tmpRetVal = recAsync->RunChains();
690 if (tmpRetVal == 0 || tmpRetVal == 2) {
691 OutputStat(chainTrackingAsync, nullptr, nullptr);
692 if (configStandalone.memoryStat) {
694 }
695 }
697 }
698 if (!configStandalone.proc.doublePipeline) {
699 recUse->ClearAllocatedMemory();
700 }
701
702 if (tmpRetVal == 2) {
703 configStandalone.continueOnError = 0; // Forced exit from event display loop
704 configStandalone.noprompt = 1;
705 }
706 if (tmpRetVal == 3 && configStandalone.proc.ignoreNonFatalGPUErrors) {
707 printf("Non-FATAL GPU error occured, ignoring\n");
708 } else if (tmpRetVal && !configStandalone.continueOnError) {
709 if (tmpRetVal != 2) {
710 printf("Error occured\n");
711 }
712 return 1;
713 }
714 iRun++;
715 }
716 if (configStandalone.proc.doublePipeline) {
717 recUse->ClearAllocatedMemory();
718 }
719 nIteration.store(runs);
720 return 0;
721}
722
723int32_t main(int argc, char** argv)
724{
725 std::unique_ptr<GPUReconstruction> recUnique, recUniqueAsync, recUniquePipeline;
726
727 if (ReadConfiguration(argc, argv)) {
728 return 1;
729 }
730 eventsDir = std::string(configStandalone.absoluteEventsDir ? "" : "events/") + configStandalone.eventsDir + "/";
731
732 GPUSettingsDeviceBackend deviceSet;
733 deviceSet.deviceType = configStandalone.runGPU ? GPUDataTypes::GetDeviceType(configStandalone.gpuType.c_str()) : GPUDataTypes::DeviceType::CPU;
734 deviceSet.forceDeviceType = configStandalone.runGPUforce;
735 deviceSet.master = nullptr;
736 recUnique.reset(GPUReconstruction::CreateInstance(deviceSet));
737 rec = recUnique.get();
738 deviceSet.master = rec;
739 if (configStandalone.testSyncAsync) {
740 recUniqueAsync.reset(GPUReconstruction::CreateInstance(deviceSet));
741 recAsync = recUniqueAsync.get();
742 }
743 if (configStandalone.proc.doublePipeline) {
744 recUniquePipeline.reset(GPUReconstruction::CreateInstance(deviceSet));
745 recPipeline = recUniquePipeline.get();
746 }
747 if (rec == nullptr || (configStandalone.testSyncAsync && recAsync == nullptr)) {
748 printf("Error initializing GPUReconstruction\n");
749 return 1;
750 }
751 rec->SetDebugLevelTmp(configStandalone.proc.debugLevel);
753 if (configStandalone.testSyncAsync) {
754 if (configStandalone.proc.debugLevel >= 3) {
756 }
759 }
760 if (configStandalone.proc.doublePipeline) {
761 if (configStandalone.proc.debugLevel >= 3) {
763 }
766 }
767 if (!configStandalone.proc.doublePipeline) {
769 if (configStandalone.testSyncAsync) {
771 }
772 }
773
774 if (SetupReconstruction()) {
775 return 1;
776 }
777
778 std::unique_ptr<std::thread> pipelineThread;
779 if (configStandalone.proc.doublePipeline) {
780 pipelineThread.reset(new std::thread([]() { rec->RunPipelineWorker(); }));
781 }
782
783 if (configStandalone.seed == -1) {
784 std::random_device rd;
785 configStandalone.seed = (int32_t)rd();
786 printf("Using random seed %d\n", configStandalone.seed);
787 }
788
789 srand(configStandalone.seed);
790
791 for (nEventsInDirectory = 0; true; nEventsInDirectory++) {
792 std::ifstream in;
793 in.open((eventsDir + GPUCA_EVDUMP_FILE "." + std::to_string(nEventsInDirectory) + ".dump").c_str(), std::ifstream::binary);
794 if (in.fail()) {
795 break;
796 }
797 in.close();
798 }
799
800 if (configStandalone.TF.bunchSim || configStandalone.TF.nMerge) {
802 }
803
804 if (configStandalone.eventGenerator) {
806 return 0;
807 }
808
809 int32_t nEvents = configStandalone.nEvents;
810 if (configStandalone.TF.bunchSim) {
811 nEvents = configStandalone.nEvents > 0 ? configStandalone.nEvents : 1;
812 } else {
813 if (nEvents == -1 || nEvents > nEventsInDirectory) {
814 if (nEvents >= 0) {
815 printf("Only %d events available in directory %s (%d events requested)\n", nEventsInDirectory, eventsDir.c_str(), nEvents);
816 }
818 }
819 if (nEvents == 0 && !configStandalone.noEvents) {
820 printf("No event data found in event folder\n");
821 }
822 if (configStandalone.TF.nMerge > 1) {
823 nEvents /= configStandalone.TF.nMerge;
824 }
825 }
826
827 ioPtrEvents.resize(configStandalone.preloadEvents ? (nEvents - configStandalone.StartEvent) : 1);
828 ioMemEvents.resize(configStandalone.preloadEvents ? (nEvents - configStandalone.StartEvent) : 1);
829 if (configStandalone.preloadEvents) {
830 printf("Preloading events%s", configStandalone.proc.debugLevel >= 2 ? "\n" : "");
831 fflush(stdout);
832 for (int32_t i = 0; i < nEvents - configStandalone.StartEvent; i++) {
833 LoadEvent(configStandalone.StartEvent + i, i);
834 if (configStandalone.proc.debugLevel >= 2) {
835 printf("Loading event %d\n", i);
836 } else {
837 printf(" %d", i);
838 }
839 fflush(stdout);
840 }
841 printf("\n");
842 }
843
844 for (int32_t iRunOuter = 0; iRunOuter < configStandalone.runs2; iRunOuter++) {
845 if (configStandalone.QA.inputHistogramsOnly) {
847 break;
848 }
849 if (configStandalone.runs2 > 1) {
850 printf("RUN2: %d\n", iRunOuter);
851 }
852 int64_t nTracksTotal = 0;
853 int64_t nClustersTotal = 0;
854 int32_t nEventsProcessed = 0;
855
856 if (configStandalone.noEvents) {
857 nEvents = 1;
858 configStandalone.StartEvent = 0;
860 }
861
862 for (int32_t iEvent = configStandalone.StartEvent; iEvent < nEvents; iEvent++) {
863 if (iEvent != configStandalone.StartEvent) {
864 printf("\n");
865 }
866 if (configStandalone.noEvents == false && !configStandalone.preloadEvents) {
867 HighResTimer timerLoad;
868 timerLoad.Start();
869 if (LoadEvent(iEvent, 0)) {
870 goto breakrun;
871 }
872 if (configStandalone.dumpEvents) {
873 char fname[1024];
874 snprintf(fname, 1024, "event.%d.dump", nEventsProcessed);
875 chainTracking->DumpData(fname);
876 if (nEventsProcessed == 0) {
877 rec->DumpSettings();
878 }
879 }
880
883 if (grp.grpContinuousMaxTimeBin == 0) {
884 printf("Cannot override max time bin for non-continuous data!\n");
885 } else {
887 printf("Max time bin set to %d\n", grp.grpContinuousMaxTimeBin);
888 rec->UpdateSettings(&grp);
889 if (recAsync) {
891 }
892 if (recPipeline) {
894 }
895 }
896 }
897 printf("Loading time: %'d us\n", (int32_t)(1000000 * timerLoad.GetCurrentElapsedTime()));
898 }
899 printf("Processing Event %d\n", iEvent);
900
901 nIteration.store(0);
902 nIterationEnd.store(0);
903 double pipelineWalltime = 1.;
904 if (configStandalone.proc.doublePipeline) {
905 HighResTimer timerPipeline;
906 if (configStandalone.proc.debugLevel < 2 && (RunBenchmark(rec, chainTracking, 1, iEvent, &nTracksTotal, &nClustersTotal) || RunBenchmark(recPipeline, chainTrackingPipeline, 2, iEvent, &nTracksTotal, &nClustersTotal))) {
907 goto breakrun;
908 }
909 auto pipeline1 = std::async(std::launch::async, RunBenchmark, rec, chainTracking, configStandalone.runs, iEvent, &nTracksTotal, &nClustersTotal, 0, &timerPipeline);
910 auto pipeline2 = std::async(std::launch::async, RunBenchmark, recPipeline, chainTrackingPipeline, configStandalone.runs, iEvent, &nTracksTotal, &nClustersTotal, 1, &timerPipeline);
911 if (pipeline1.get() || pipeline2.get()) {
912 goto breakrun;
913 }
914 pipelineWalltime = timerPipeline.GetElapsedTime() / (configStandalone.runs - 2);
915 printf("Pipeline wall time: %f, %d iterations, %f per event\n", timerPipeline.GetElapsedTime(), configStandalone.runs - 2, pipelineWalltime);
916 } else {
917 if (RunBenchmark(rec, chainTracking, configStandalone.runs, iEvent, &nTracksTotal, &nClustersTotal)) {
918 goto breakrun;
919 }
920 }
921 nEventsProcessed++;
922
923 if (configStandalone.timeFrameTime) {
924 double nClusters = chainTracking->GetProcessors()->tpcMerger.NMaxClusters();
925 if (nClusters > 0) {
926 const int32_t nOrbits = 32;
927 const double colRate = 50000;
928 const double orbitRate = 11245;
929 const double nClsPerTF = 755851. * nOrbits * colRate / orbitRate;
930 double timePerTF = (configStandalone.proc.doublePipeline ? pipelineWalltime : ((configStandalone.proc.debugLevel ? rec->GetStatKernelTime() : rec->GetStatWallTime()) / 1000000.)) * nClsPerTF / nClusters;
931 const double nGPUsReq = timePerTF * orbitRate / nOrbits;
932 char stat[1024];
933 snprintf(stat, 1024, "Sync phase: %.2f sec per %d orbit TF, %.1f GPUs required", timePerTF, nOrbits, nGPUsReq);
934 if (configStandalone.testSyncAsync) {
935 timePerTF = (configStandalone.proc.debugLevel ? recAsync->GetStatKernelTime() : recAsync->GetStatWallTime()) / 1000000. * nClsPerTF / nClusters;
936 snprintf(stat + strlen(stat), 1024 - strlen(stat), " - Async phase: %f sec per TF", timePerTF);
937 }
938 printf("%s (Measured %s time - Extrapolated from %d clusters to %d)\n", stat, configStandalone.proc.debugLevel ? "kernel" : "wall", (int32_t)nClusters, (int32_t)nClsPerTF);
939 }
940 }
941
942 if (configStandalone.preloadEvents && configStandalone.proc.doublePipeline) {
943 break;
944 }
945 }
946 if (nEventsProcessed > 1) {
947 printf("Total: %ld clusters, %ld tracks\n", nClustersTotal, nTracksTotal);
948 }
949 }
950
951breakrun:
952 if (rec->GetProcessingSettings().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_GLOBAL) {
954 }
955
956#ifndef _WIN32
957 if (configStandalone.proc.runQA && configStandalone.fpe) {
958 fedisableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW);
959 }
960#endif
961
962 if (configStandalone.proc.doublePipeline) {
964 pipelineThread->join();
965 }
966
967 rec->Finalize();
968 if (configStandalone.outputcontrolmem && rec->IsGPU()) {
970 printf("Error unregistering memory\n");
971 }
972 }
973 rec->Exit();
974
975 if (!configStandalone.noprompt) {
976 printf("Press a key to exit!\n");
977 getchar();
978 }
979 return (0);
980}
Container to store compressed TPC cluster data.
Helper class to access correction maps.
int32_t i
#define GPUCA_BUFFER_ALIGNMENT
#define GPUCA_EVDUMP_FILE
Definition GPUDef.h:37
Definition of TPCFastTransform class.
int nClusters
void Start()
Definition timer.cxx:57
double GetCurrentElapsedTime(bool reset=false)
Definition timer.cxx:110
double GetElapsedTime()
Definition timer.cxx:108
void set(S v)
Definition bitfield.h:55
void clear()
Definition bitfield.h:54
S get() const
Definition bitfield.h:63
bitfield & setBits(const bitfield v, bool w)
Definition bitfield.h:45
bool isSet(const bitfield &v) const
Definition bitfield.h:66
GPUd() value_type estimateLTFast(o2 static GPUd() float estimateLTIncrement(const o2 PropagatorImpl * Instance(bool uninitialized=false)
Definition Propagator.h:143
void SetQAFromForeignChain(GPUChainTracking *chain)
const CorrectionMapsHelper * GetTPCTransformHelper() const
void SetO2Propagator(const o2::base::Propagator *prop)
const GPUTRDGeometry * GetTRDGeometry() const
const o2::base::MatLayerCylSet * GetMatLUT() const
const GPUSettingsDisplay * mConfigDisplay
void DumpData(const char *filename, const GPUTrackingInOutPointers *ioPtrs=nullptr)
const GPUQA * GetQA() const
GPUTrackingInOutPointers & mIOPtrs
struct o2::gpu::GPUChainTracking::InOutMemory mIOMem
int32_t ReadData(const char *filename)
const GPUSettingsQA * mConfigQA
const GPUSettingsProcessing & GetProcessingSettings() const
Definition GPUChain.h:76
static constexpr int32_t NSECTORS
Definition GPUChain.h:58
const GPUConstantMem * GetProcessors() const
Definition GPUChain.h:68
static DeviceType GetDeviceType(const char *type)
static GPUDisplayFrontendInterface * getFrontend(const char *type)
int32_t ReadO2MCData(const char *filename)
Definition GPUQA.h:54
void UpdateChain(GPUChainTracking *chain)
Definition GPUQA.h:58
static int32_t GetMaxTimeBin(const o2::tpc::ClusterNativeAccess &native)
static DeviceType GetDeviceType(const char *type)
void SetInputControl(void *ptr, size_t size)
static bool CheckInstanceAvailable(DeviceType type, bool verbose)
void SetSettings(float solenoidBzNominalGPU, const GPURecoStepConfiguration *workflow=nullptr)
static GPUReconstruction * CreateInstance(const GPUSettingsDeviceBackend &cfg)
void UpdateSettings(const GPUSettingsGRP *g, const GPUSettingsProcessing *p=nullptr, const GPUSettingsRecDynamic *d=nullptr)
virtual int32_t RunChains()=0
const GPUParam & GetParam() const
void ClearAllocatedMemory(bool clearOutputs=true)
const GPUSettingsProcessing & GetProcessingSettings() const
void DumpSettings(const char *dir="")
int32_t unregisterMemoryForGPU(const void *ptr)
int32_t registerMemoryForGPU(const void *ptr, size_t size)
const GPUSettingsGRP & GetGRPSettings() const
void SetDebugLevelTmp(int32_t level)
int32_t ReadSettings(const char *dir="")
void SetOutputControl(const GPUOutputControl &v)
static void RunEventGenerator(GPUChainTracking *rec, const std::string &dir)
Definition genEvents.h:34
GLdouble n
Definition glcorearb.h:1982
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLboolean r
Definition glcorearb.h:1233
GLenum GLenum GLsizei len
Definition glcorearb.h:4232
GLenum GLfloat param
Definition glcorearb.h:271
GLint GLuint mask
Definition glcorearb.h:291
GPUSettingsStandalone configStandalone
Definition genEvents.cxx:47
@ qcrHelp
Definition qconfig.h:29
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
void qConfigPrint()
Definition qconfig.cxx:515
int32_t qConfigParse(int argc, const char **argv, const char *filename)
Definition qconfig.cxx:513
std::unique_ptr< GPUReconstructionTimeframe > tf
int32_t RunBenchmark(GPUReconstruction *recUse, GPUChainTracking *chainTrackingUse, int32_t runs, int32_t iEvent, int64_t *nTracksTotal, int64_t *nClustersTotal, int32_t threadId=0, HighResTimer *timerPipeline=nullptr)
int32_t SetupReconstruction()
std::unique_ptr< char, void(*)(char *)> outputmemoryPipeline(nullptr, unique_ptr_aligned_delete)
std::atomic< uint32_t > nIteration
GPUReconstruction * recPipeline
std::unique_ptr< char, void(*)(char *)> outputmemory(nullptr, unique_ptr_aligned_delete)
int32_t nEventsInDirectory
int32_t ReadConfiguration(int argc, char **argv)
std::unique_ptr< char, void(*)(char *)> inputmemory(nullptr, unique_ptr_aligned_delete)
int32_t LoadEvent(int32_t iEvent, int32_t x)
std::vector< GPUTrackingInOutPointers > ioPtrEvents
GPUChainITS * chainITSPipeline
int32_t ReadEvent(int32_t n)
void unique_ptr_aligned_delete(char *v)
std::vector< GPUChainTracking::InOutMemory > ioMemEvents
std::unique_ptr< GPUDisplayFrontendInterface > eventDisplay
GPUReconstruction * rec
GPUChainITS * chainITS
GPUChainTracking * chainTrackingAsync
GPUChainITS * chainITSAsync
GPUChainTracking * chainTrackingPipeline
GPUReconstruction * recAsync
void OutputStat(GPUChainTracking *t, int64_t *nTracksTotal=nullptr, int64_t *nClustersTotal=nullptr)
std::atomic< uint32_t > nIterationEnd
std::string eventsDir
GPUChainTracking * chainTracking
GPUDataTypes::RecoStepField stepsGPUMask
GPUDataTypes::InOutTypeField outputs
GPUDataTypes::RecoStepField steps
GPUDataTypes::InOutTypeField inputs
const o2::tpc::ClusterNativeAccess * clustersNative
const GPUTPCMCInfo * mcInfosTPC
const o2::tpc::CompressedClustersFlat * tpcCompressedClusters
const AliHLTTPCClusterMCLabel * mcLabelsTPC
const GPUTrackingInOutZS * tpcZS
const AliHLTTPCRawCluster * rawClusters[NSECTORS]
const GPUTPCClusterData * clusterData[NSECTORS]
const GPUTrackingInOutDigits * tpcPackedDigits
const GPUTPCMCInfoCol * mcInfosTPCCol
const GPUTPCGMMergedTrack * mergedTracks
GPUTPCGMPolynomialField polynomialField
Definition GPUParam.h:63
const int nEvents
Definition test_Fifo.cxx:27
#define main
std::random_device rd
typename std::vector< T, vecpod_allocator< T > > vecpod
Definition vecpod.h:31