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 configStandalone.noEvents = true;
202 }
203 if (configStandalone.QA.dumpToROOT) {
204 configStandalone.proc.outputSharedClusterMap = true;
205 }
206 if (configStandalone.eventDisplay) {
207 configStandalone.noprompt = 1;
208 }
209 if (configStandalone.proc.debugLevel >= 4) {
210 if (configStandalone.proc.inKernelParallel) {
211 configStandalone.proc.inKernelParallel = 1;
212 } else {
213 configStandalone.proc.nHostThreads = 1;
214 }
215 }
216 if (configStandalone.setO2Settings) {
217 if (!(configStandalone.inputcontrolmem && configStandalone.outputcontrolmem)) {
218 printf("setO2Settings requires the usage of --inputMemory and --outputMemory as in O2\n");
219 return 1;
220 }
221 if (configStandalone.runGPU) {
222 configStandalone.proc.forceHostMemoryPoolSize = 1024 * 1024 * 1024;
223 }
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 (procSet.createO2Output && !procSet.trdTrackModelO2) {
419 procSet.createO2Output = 1; // Must not be 2, to make sure TPC GPU tracks are still available for TRD
420 }
421 }
422
423 if (configStandalone.testSyncAsync || configStandalone.testSync) {
424 // Set settings for synchronous
425 if (configStandalone.rundEdx == -1) {
426 steps.steps.setBits(GPUDataTypes::RecoStep::TPCdEdx, 0);
427 }
428 recSet.useMatLUT = false;
429 if (configStandalone.testSyncAsync) {
430 procSet.eventDisplay = nullptr;
431 }
432 }
433 if (configStandalone.proc.rtc.optSpecialCode == -1) {
434 configStandalone.proc.rtc.optSpecialCode = configStandalone.testSyncAsync || configStandalone.testSync;
435 }
436
437 rec->SetSettings(&grp, &recSet, &procSet, &steps);
438 if (configStandalone.proc.doublePipeline) {
439 recPipeline->SetSettings(&grp, &recSet, &procSet, &steps);
440 }
441 if (configStandalone.testSyncAsync) {
442 // Set settings for asynchronous
443 steps.steps.setBits(GPUDataTypes::RecoStep::TPCDecompression, true);
444 steps.steps.setBits(GPUDataTypes::RecoStep::TPCdEdx, true);
445 steps.steps.setBits(GPUDataTypes::RecoStep::TPCCompression, false);
446 steps.steps.setBits(GPUDataTypes::RecoStep::TPCClusterFinding, false);
447 steps.inputs.setBits(GPUDataTypes::InOutType::TPCRaw, false);
448 steps.inputs.setBits(GPUDataTypes::InOutType::TPCClusters, false);
449 steps.inputs.setBits(GPUDataTypes::InOutType::TPCCompressedClusters, true);
450 steps.outputs.setBits(GPUDataTypes::InOutType::TPCCompressedClusters, false);
451 procSet.runMC = false;
452 procSet.runQA = false;
453 procSet.eventDisplay = eventDisplay.get();
454 procSet.runCompressionStatistics = 0;
455 procSet.rtc.optSpecialCode = 0;
456 if (recSet.tpc.rejectionStrategy >= GPUSettings::RejectionStrategyB) {
457 procSet.tpcInputWithClusterRejection = 1;
458 }
459 recSet.tpc.disableRefitAttachment = 0xFF;
460 recSet.maxTrackQPtB5 = CAMath::Min(recSet.maxTrackQPtB5, recSet.tpc.rejectQPtB5);
461 recSet.useMatLUT = true;
462 recAsync->SetSettings(&grp, &recSet, &procSet, &steps);
463 }
464
465 if (configStandalone.outputcontrolmem) {
466 rec->SetOutputControl(outputmemory.get(), configStandalone.outputcontrolmem);
467 if (configStandalone.proc.doublePipeline) {
469 }
470 }
471
472 o2::base::Propagator* prop = nullptr;
474 prop->setGPUField(&rec->GetParam().polynomialField);
475 prop->setNominalBz(rec->GetParam().bzkG);
476 prop->setMatLUT(chainTracking->GetMatLUT());
478 if (chainTrackingAsync) {
480 }
483 }
484 procSet.o2PropagatorUseGPUField = true;
485
486 if (rec->Init()) {
487 printf("Error initializing GPUReconstruction!\n");
488 return 1;
489 }
490 if (configStandalone.outputcontrolmem && rec->IsGPU()) {
491 if (rec->registerMemoryForGPU(outputmemory.get(), configStandalone.outputcontrolmem) || (configStandalone.proc.doublePipeline && recPipeline->registerMemoryForGPU(outputmemoryPipeline.get(), configStandalone.outputcontrolmem))) {
492 printf("ERROR registering memory for the GPU!!!\n");
493 return 1;
494 }
495 }
496 if (configStandalone.inputcontrolmem && rec->IsGPU()) {
497 if (rec->registerMemoryForGPU(inputmemory.get(), configStandalone.inputcontrolmem)) {
498 printf("ERROR registering input memory for the GPU!!!\n");
499 return 1;
500 }
501 }
502 if (configStandalone.proc.debugLevel >= 4) {
504 }
505 return (0);
506}
507
508int32_t ReadEvent(int32_t n)
509{
510 if (configStandalone.inputcontrolmem && !configStandalone.preloadEvents) {
511 rec->SetInputControl(inputmemory.get(), configStandalone.inputcontrolmem);
512 }
513 int32_t r = chainTracking->ReadData((eventsDir + GPUCA_EVDUMP_FILE "." + std::to_string(n) + ".dump").c_str());
514 if (r) {
515 return r;
516 }
517#if defined(GPUCA_TPC_GEOMETRY_O2) && defined(GPUCA_BUILD_QA) && !defined(GPUCA_O2_LIB)
518 if ((configStandalone.proc.runQA || configStandalone.eventDisplay) && !configStandalone.QA.noMC) {
521 if (chainTracking->GetQA()->ReadO2MCData((eventsDir + "mc." + std::to_string(n) + ".dump").c_str()) &&
522 chainTracking->GetQA()->ReadO2MCData((eventsDir + "mc.0.dump").c_str()) && configStandalone.proc.runQA) {
523 throw std::runtime_error("Error reading O2 MC dump");
524 }
525 }
526#endif
527 if (chainTracking->mIOPtrs.clustersNative && (configStandalone.TF.bunchSim || configStandalone.TF.nMerge || !configStandalone.runTransformation)) {
528 if (configStandalone.proc.debugLevel >= 2) {
529 printf("Converting Native to Legacy ClusterData for overlaying - WARNING: No raw clusters produced - Compression etc will not run!!!\n");
530 }
532 }
533 return 0;
534}
535
536int32_t LoadEvent(int32_t iEvent, int32_t x)
537{
538 if (configStandalone.TF.bunchSim) {
539 if (tf->LoadCreateTimeFrame(iEvent)) {
540 return 1;
541 }
542 } else if (configStandalone.TF.nMerge) {
543 if (tf->LoadMergedEvents(iEvent)) {
544 return 1;
545 }
546 } else {
547 if (ReadEvent(iEvent)) {
548 return 1;
549 }
550 }
551 bool encodeZS = configStandalone.encodeZS == -1 ? (chainTracking->mIOPtrs.tpcPackedDigits && !chainTracking->mIOPtrs.tpcZS) : (bool)configStandalone.encodeZS;
552 bool zsFilter = configStandalone.zsFilter == -1 ? (!encodeZS && chainTracking->mIOPtrs.tpcPackedDigits && !chainTracking->mIOPtrs.tpcZS) : (bool)configStandalone.zsFilter;
553 if (encodeZS || zsFilter) {
555 printf("Need digit input to run ZS\n");
556 return 1;
557 }
558 if (zsFilter) {
560 }
561 if (encodeZS) {
563 }
564 }
565 if (!configStandalone.runTransformation) {
567 } else {
568 for (int32_t i = 0; i < chainTracking->NSECTORS; i++) {
570 if (configStandalone.proc.debugLevel >= 2) {
571 printf("Converting Legacy Raw Cluster to Native\n");
572 }
574 break;
575 }
576 }
577 }
578
579 if (configStandalone.stripDumpedEvents) {
582 }
583 }
584
586 printf("Need cluster native data for on-the-fly TPC transform\n");
587 return 1;
588 }
589
591 ioMemEvents[x] = std::move(chainTracking->mIOMem);
593 return 0;
594}
595
596void OutputStat(GPUChainTracking* t, int64_t* nTracksTotal = nullptr, int64_t* nClustersTotal = nullptr)
597{
598 int32_t nTracks = 0;
599 if (t->GetProcessingSettings().createO2Output) {
600 nTracks += t->mIOPtrs.nOutputTracksTPCO2;
601 } else {
602 for (uint32_t k = 0; k < t->mIOPtrs.nMergedTracks; k++) {
603 if (t->mIOPtrs.mergedTracks[k].OK()) {
604 nTracks++;
605 }
606 }
607 }
608 if (nTracksTotal && nClustersTotal) {
609 *nTracksTotal += nTracks;
610 *nClustersTotal += t->mIOPtrs.nMergedTrackHits;
611 }
612}
613
614int32_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)
615{
616 int32_t iRun = 0, iteration = 0;
617 while ((iteration = nIteration.fetch_add(1)) < runs) {
618 if (configStandalone.runs > 1) {
619 printf("Run %d (thread %d)\n", iteration + 1, threadId);
620 }
621 recUse->SetResetTimers(iRun < configStandalone.runsInit);
622 if (configStandalone.outputcontrolmem) {
623 recUse->SetOutputControl(threadId ? outputmemoryPipeline.get() : outputmemory.get(), configStandalone.outputcontrolmem);
624 }
625
626 if (configStandalone.testSyncAsync) {
627 printf("Running synchronous phase\n");
628 }
629 const GPUTrackingInOutPointers& ioPtrs = ioPtrEvents[!configStandalone.preloadEvents ? 0 : configStandalone.proc.doublePipeline ? (iteration % ioPtrEvents.size()) : (iEvent - configStandalone.StartEvent)];
630 chainTrackingUse->mIOPtrs = ioPtrs;
631 if (iteration == (configStandalone.proc.doublePipeline ? 2 : (configStandalone.runs - 1))) {
632 if (configStandalone.proc.doublePipeline && timerPipeline) {
633 timerPipeline->Start();
634 }
635 if (configStandalone.controlProfiler) {
637 }
638 }
639 int32_t tmpRetVal = recUse->RunChains();
640 int32_t iterationEnd = nIterationEnd.fetch_add(1);
641 if (iterationEnd == configStandalone.runs - 1) {
642 if (configStandalone.proc.doublePipeline && timerPipeline) {
643 timerPipeline->Stop();
644 }
645 if (configStandalone.controlProfiler) {
647 }
648 }
649
650 if (tmpRetVal == 0 || tmpRetVal == 2) {
651 OutputStat(chainTrackingUse, iRun == 0 ? nTracksTotal : nullptr, iRun == 0 ? nClustersTotal : nullptr);
652 if (configStandalone.memoryStat) {
653 recUse->PrintMemoryStatistics();
654 } else if (configStandalone.proc.debugLevel >= 2) {
655 recUse->PrintMemoryOverview();
656 }
657 }
658
659 if (tmpRetVal == 0 && configStandalone.testSyncAsync) {
660 if (configStandalone.testSyncAsync) {
661 printf("Running asynchronous phase\n");
662 }
663
666
667 chainTrackingAsync->mIOPtrs = ioPtrs;
677 for (int32_t i = 0; i < chainTracking->NSECTORS; i++) {
682 }
684 recAsync->SetResetTimers(iRun < configStandalone.runsInit);
685 tmpRetVal = recAsync->RunChains();
686 if (tmpRetVal == 0 || tmpRetVal == 2) {
687 OutputStat(chainTrackingAsync, nullptr, nullptr);
688 if (configStandalone.memoryStat) {
690 }
691 }
693 }
694 if (!configStandalone.proc.doublePipeline) {
695 recUse->ClearAllocatedMemory();
696 }
697
698 if (tmpRetVal == 2) {
699 configStandalone.continueOnError = 0; // Forced exit from event display loop
700 configStandalone.noprompt = 1;
701 }
702 if (tmpRetVal == 3 && configStandalone.proc.ignoreNonFatalGPUErrors) {
703 printf("GPU Standalone Benchmark: Non-FATAL GPU error occured, ignoring\n");
704 } else if (tmpRetVal && !configStandalone.continueOnError) {
705 if (tmpRetVal != 2) {
706 printf("GPU Standalone Benchmark: Error occured\n");
707 }
708 return 1;
709 }
710 iRun++;
711 }
712 if (configStandalone.proc.doublePipeline) {
713 recUse->ClearAllocatedMemory();
714 }
715 nIteration.store(runs);
716 return 0;
717}
718
719int32_t main(int argc, char** argv)
720{
721 std::unique_ptr<GPUReconstruction> recUnique, recUniqueAsync, recUniquePipeline;
722
723 if (ReadConfiguration(argc, argv)) {
724 return 1;
725 }
726 eventsDir = std::string(configStandalone.absoluteEventsDir ? "" : "events/") + configStandalone.eventsDir + "/";
727
728 GPUSettingsDeviceBackend deviceSet;
729 deviceSet.deviceType = configStandalone.runGPU ? GPUDataTypes::GetDeviceType(configStandalone.gpuType.c_str()) : GPUDataTypes::DeviceType::CPU;
730 deviceSet.forceDeviceType = configStandalone.runGPUforce;
731 deviceSet.master = nullptr;
732 recUnique.reset(GPUReconstruction::CreateInstance(deviceSet));
733 rec = recUnique.get();
734 deviceSet.master = rec;
735 if (configStandalone.testSyncAsync) {
736 recUniqueAsync.reset(GPUReconstruction::CreateInstance(deviceSet));
737 recAsync = recUniqueAsync.get();
738 }
739 if (configStandalone.proc.doublePipeline) {
740 recUniquePipeline.reset(GPUReconstruction::CreateInstance(deviceSet));
741 recPipeline = recUniquePipeline.get();
742 }
743 if (rec == nullptr || (configStandalone.testSyncAsync && recAsync == nullptr)) {
744 printf("Error initializing GPUReconstruction\n");
745 return 1;
746 }
747 rec->SetDebugLevelTmp(configStandalone.proc.debugLevel);
749 if (configStandalone.testSyncAsync) {
750 if (configStandalone.proc.debugLevel >= 3) {
752 }
755 }
756 if (configStandalone.proc.doublePipeline) {
757 if (configStandalone.proc.debugLevel >= 3) {
759 }
762 }
763 if (!configStandalone.proc.doublePipeline) {
765 if (configStandalone.testSyncAsync) {
767 }
768 }
769
770 if (SetupReconstruction()) {
771 return 1;
772 }
773
774 std::unique_ptr<std::thread> pipelineThread;
775 if (configStandalone.proc.doublePipeline) {
776 pipelineThread.reset(new std::thread([]() { rec->RunPipelineWorker(); }));
777 }
778
779 if (configStandalone.seed == -1) {
780 std::random_device rd;
781 configStandalone.seed = (int32_t)rd();
782 printf("Using random seed %d\n", configStandalone.seed);
783 }
784
785 srand(configStandalone.seed);
786
787 for (nEventsInDirectory = 0; true; nEventsInDirectory++) {
788 std::ifstream in;
789 in.open((eventsDir + GPUCA_EVDUMP_FILE "." + std::to_string(nEventsInDirectory) + ".dump").c_str(), std::ifstream::binary);
790 if (in.fail()) {
791 break;
792 }
793 in.close();
794 }
795
796 if (configStandalone.TF.bunchSim || configStandalone.TF.nMerge) {
798 }
799
800 if (configStandalone.eventGenerator) {
802 return 0;
803 }
804
805 int32_t nEvents = configStandalone.nEvents;
806 if (configStandalone.TF.bunchSim) {
807 nEvents = configStandalone.nEvents > 0 ? configStandalone.nEvents : 1;
808 } else {
809 if (nEvents == -1 || nEvents > nEventsInDirectory) {
810 if (nEvents >= 0) {
811 printf("Only %d events available in directory %s (%d events requested)\n", nEventsInDirectory, eventsDir.c_str(), nEvents);
812 }
814 }
815 if (nEvents == 0 && !configStandalone.noEvents) {
816 printf("No event data found in event folder\n");
817 }
818 if (configStandalone.TF.nMerge > 1) {
819 nEvents /= configStandalone.TF.nMerge;
820 }
821 }
822
823 ioPtrEvents.resize(configStandalone.preloadEvents ? (nEvents - configStandalone.StartEvent) : 1);
824 ioMemEvents.resize(configStandalone.preloadEvents ? (nEvents - configStandalone.StartEvent) : 1);
825 if (configStandalone.preloadEvents) {
826 printf("Preloading events%s", configStandalone.proc.debugLevel >= 2 ? "\n" : "");
827 fflush(stdout);
828 for (int32_t i = 0; i < nEvents - configStandalone.StartEvent; i++) {
829 LoadEvent(configStandalone.StartEvent + i, i);
830 if (configStandalone.proc.debugLevel >= 2) {
831 printf("Loading event %d\n", i);
832 } else {
833 printf(" %d", i);
834 }
835 fflush(stdout);
836 }
837 printf("\n");
838 }
839
840 for (int32_t iRunOuter = 0; iRunOuter < configStandalone.runs2; iRunOuter++) {
841 if (configStandalone.QA.inputHistogramsOnly) {
843 break;
844 }
845 if (configStandalone.runs2 > 1) {
846 printf("\nRUN2: %d\n", iRunOuter);
847 }
848 int64_t nTracksTotal = 0;
849 int64_t nClustersTotal = 0;
850 int32_t nEventsProcessed = 0;
851
852 if (configStandalone.noEvents) {
853 nEvents = 1;
854 configStandalone.StartEvent = 0;
856 }
857
858 for (int32_t iEvent = configStandalone.StartEvent; iEvent < nEvents; iEvent++) {
859 if (iEvent != configStandalone.StartEvent) {
860 printf("\n");
861 }
862 if (configStandalone.noEvents == false && !configStandalone.preloadEvents) {
863 HighResTimer timerLoad;
864 timerLoad.Start();
865 if (LoadEvent(iEvent, 0)) {
866 goto breakrun;
867 }
868 if (configStandalone.dumpEvents) {
869 char fname[1024];
870 snprintf(fname, 1024, "event.%d.dump", nEventsProcessed);
871 chainTracking->DumpData(fname);
872 if (nEventsProcessed == 0) {
873 rec->DumpSettings();
874 }
875 }
876
879 if (grp.grpContinuousMaxTimeBin == 0) {
880 printf("Cannot override max time bin for non-continuous data!\n");
881 } else {
883 printf("Max time bin set to %d\n", grp.grpContinuousMaxTimeBin);
884 rec->UpdateSettings(&grp);
885 if (recAsync) {
887 }
888 if (recPipeline) {
890 }
891 }
892 }
893 printf("Loading time: %'d us\n", (int32_t)(1000000 * timerLoad.GetCurrentElapsedTime()));
894 }
895 printf("Processing Event %d\n", iEvent);
896
897 nIteration.store(0);
898 nIterationEnd.store(0);
899 double pipelineWalltime = 1.;
900 if (configStandalone.proc.doublePipeline) {
901 HighResTimer timerPipeline;
902 if (configStandalone.proc.debugLevel < 2 && (RunBenchmark(rec, chainTracking, 1, iEvent, &nTracksTotal, &nClustersTotal) || RunBenchmark(recPipeline, chainTrackingPipeline, 2, iEvent, &nTracksTotal, &nClustersTotal))) {
903 goto breakrun;
904 }
905 auto pipeline1 = std::async(std::launch::async, RunBenchmark, rec, chainTracking, configStandalone.runs, iEvent, &nTracksTotal, &nClustersTotal, 0, &timerPipeline);
906 auto pipeline2 = std::async(std::launch::async, RunBenchmark, recPipeline, chainTrackingPipeline, configStandalone.runs, iEvent, &nTracksTotal, &nClustersTotal, 1, &timerPipeline);
907 if (pipeline1.get() || pipeline2.get()) {
908 goto breakrun;
909 }
910 pipelineWalltime = timerPipeline.GetElapsedTime() / (configStandalone.runs - 2);
911 printf("Pipeline wall time: %f, %d iterations, %f per event\n", timerPipeline.GetElapsedTime(), configStandalone.runs - 2, pipelineWalltime);
912 } else {
913 if (RunBenchmark(rec, chainTracking, configStandalone.runs, iEvent, &nTracksTotal, &nClustersTotal)) {
914 goto breakrun;
915 }
916 }
917 nEventsProcessed++;
918
919 if (configStandalone.timeFrameTime) {
920 double nClusters = chainTracking->GetProcessors()->tpcMerger.NMaxClusters();
921 if (nClusters > 0) {
922 const int32_t nOrbits = 32;
923 const double colRate = 50000;
924 const double orbitRate = 11245;
925 const double nClsPerTF = 755851. * nOrbits * colRate / orbitRate;
926 double timePerTF = (configStandalone.proc.doublePipeline ? pipelineWalltime : ((configStandalone.proc.debugLevel ? rec->GetStatKernelTime() : rec->GetStatWallTime()) / 1000000.)) * nClsPerTF / nClusters;
927 const double nGPUsReq = timePerTF * orbitRate / nOrbits;
928 char stat[1024];
929 snprintf(stat, 1024, "Sync phase: %.2f sec per %d orbit TF, %.1f GPUs required", timePerTF, nOrbits, nGPUsReq);
930 if (configStandalone.testSyncAsync) {
931 timePerTF = (configStandalone.proc.debugLevel ? recAsync->GetStatKernelTime() : recAsync->GetStatWallTime()) / 1000000. * nClsPerTF / nClusters;
932 snprintf(stat + strlen(stat), 1024 - strlen(stat), " - Async phase: %f sec per TF", timePerTF);
933 }
934 printf("%s (Measured %s time - Extrapolated from %d clusters to %d)\n", stat, configStandalone.proc.debugLevel ? "kernel" : "wall", (int32_t)nClusters, (int32_t)nClsPerTF);
935 }
936 }
937
938 if (configStandalone.preloadEvents && configStandalone.proc.doublePipeline) {
939 break;
940 }
941 }
942 if (nEventsProcessed > 1) {
943 printf("Total: %ld clusters, %ld tracks\n", nClustersTotal, nTracksTotal);
944 }
945 }
946
947breakrun:
948 if (rec->GetProcessingSettings().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_GLOBAL) {
950 }
951
952#ifndef _WIN32
953 if (configStandalone.proc.runQA && configStandalone.fpe) {
954 fedisableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW);
955 }
956#endif
957
958 if (configStandalone.proc.doublePipeline) {
960 pipelineThread->join();
961 }
962
963 rec->Finalize();
964 if (configStandalone.outputcontrolmem && rec->IsGPU()) {
966 printf("Error unregistering memory\n");
967 }
968 }
969 rec->Exit();
970
971 if (!configStandalone.noprompt) {
972 printf("Press a key to exit!\n");
973 getchar();
974 }
975 return (0);
976}
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: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: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
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