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