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.inputHistogramsOnly) {
201 configStandalone.rundEdx = false;
202 configStandalone.noEvents = true;
203 }
204 if (configStandalone.QA.dumpToROOT) {
205 configStandalone.proc.outputSharedClusterMap = true;
206 }
207 if (configStandalone.eventDisplay) {
208 configStandalone.noprompt = 1;
209 }
210 if (configStandalone.proc.debugLevel >= 4) {
211 if (configStandalone.proc.inKernelParallel) {
212 configStandalone.proc.inKernelParallel = 1;
213 } else {
214 configStandalone.proc.nHostThreads = 1;
215 }
216 }
217 if (configStandalone.setO2Settings) {
218 if (configStandalone.runGPU && configStandalone.proc.debugLevel <= 1) {
219 if (!(configStandalone.inputcontrolmem && configStandalone.outputcontrolmem)) {
220 printf("setO2Settings requires the usage of --inputMemory and --outputMemory as in O2\n");
221 return 1;
222 }
223 configStandalone.proc.forceHostMemoryPoolSize = 1024 * 1024 * 1024;
224 }
225 configStandalone.rec.tpc.trackReferenceX = 83;
226 configStandalone.proc.outputSharedClusterMap = 1;
227 configStandalone.proc.clearO2OutputFromGPU = 1;
228 configStandalone.QA.clusterRejectionHistograms = 1;
229 configStandalone.proc.tpcIncreasedMinClustersPerRow = 500000;
230 configStandalone.proc.ignoreNonFatalGPUErrors = 1;
231 // TODO: rundEdx=1
232 // GPU_proc.qcRunFraction=$TPC_TRACKING_QC_RUN_FRACTION;"
233 // [[ $CTFINPUT == 1 ]] && GPU_CONFIG_KEY+="GPU_proc.tpcInputWithClusterRejection=1;"
234 // double pipeline / rtc
235 }
236
237 if (configStandalone.outputcontrolmem) {
238 bool forceEmptyMemory = getenv("LD_PRELOAD") && strstr(getenv("LD_PRELOAD"), "valgrind") != nullptr;
239 outputmemory.reset((char*)operator new(configStandalone.outputcontrolmem, std::align_val_t(GPUCA_BUFFER_ALIGNMENT)));
240 if (forceEmptyMemory) {
241 printf("Valgrind detected, emptying GPU output memory to avoid false positive undefined reads");
242 memset(outputmemory.get(), 0, configStandalone.outputcontrolmem);
243 }
244 if (configStandalone.proc.doublePipeline) {
245 outputmemoryPipeline.reset((char*)operator new(configStandalone.outputcontrolmem, std::align_val_t(GPUCA_BUFFER_ALIGNMENT)));
246 if (forceEmptyMemory) {
247 memset(outputmemoryPipeline.get(), 0, configStandalone.outputcontrolmem);
248 }
249 }
250 }
251 if (configStandalone.inputcontrolmem) {
252 inputmemory.reset((char*)operator new(configStandalone.inputcontrolmem, std::align_val_t(GPUCA_BUFFER_ALIGNMENT)));
253 }
254
255 configStandalone.proc.showOutputStat = true;
256
257 if (configStandalone.runGPU && configStandalone.gpuType == "AUTO") {
258 if (GPUReconstruction::CheckInstanceAvailable(GPUReconstruction::DeviceType::CUDA, configStandalone.proc.debugLevel >= 2)) {
259 configStandalone.gpuType = "CUDA";
260 } else if (GPUReconstruction::CheckInstanceAvailable(GPUReconstruction::DeviceType::HIP, configStandalone.proc.debugLevel >= 2)) {
261 configStandalone.gpuType = "HIP";
262 } else if (GPUReconstruction::CheckInstanceAvailable(GPUReconstruction::DeviceType::OCL, configStandalone.proc.debugLevel >= 2)) {
263 configStandalone.gpuType = "OCL";
264 } else if (GPUReconstruction::CheckInstanceAvailable(GPUReconstruction::DeviceType::OCL, configStandalone.proc.debugLevel >= 2)) {
265 configStandalone.gpuType = "OCL";
266 } else {
267 if (configStandalone.runGPU > 1 && configStandalone.runGPUforce) {
268 printf("No GPU backend / device found, running on CPU is disabled due to runGPUforce\n");
269 return 1;
270 }
271 configStandalone.runGPU = false;
272 configStandalone.gpuType = "CPU";
273 }
274 }
275
276 if (configStandalone.printSettings) {
277 configStandalone.proc.printSettings = true;
278 }
279 if (configStandalone.printSettings > 1) {
280 printf("Config Dump after ReadConfiguration\n");
281 qConfigPrint();
282 }
283
284 return (0);
285}
286
288{
289 if (!configStandalone.eventGenerator) {
290 if (configStandalone.noEvents) {
291 eventsDir = "NON_EXISTING";
292 configStandalone.rundEdx = false;
293 } else if (rec->ReadSettings(eventsDir.c_str())) {
294 printf("Error reading event config file\n");
295 return 1;
296 }
297 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);
298 if (configStandalone.testSyncAsync) {
300 }
301 if (configStandalone.proc.doublePipeline) {
303 }
304 }
305
308 if (configStandalone.testSyncAsync) {
311 }
312
314 GPUSettingsRec recSet;
315 GPUSettingsProcessing procSet;
316 recSet = configStandalone.rec;
317 procSet = configStandalone.proc;
319
320 if (configStandalone.solenoidBzNominalGPU != -1e6f) {
321 grp.solenoidBzNominalGPU = configStandalone.solenoidBzNominalGPU;
322 }
323 if (configStandalone.constBz) {
324 grp.constBz = true;
325 }
326 if (configStandalone.TF.nMerge || configStandalone.TF.bunchSim) {
327 if (grp.grpContinuousMaxTimeBin) {
328 printf("ERROR: requested to overlay continuous data - not supported\n");
329 return 1;
330 }
331 if (!configStandalone.cont) {
332 printf("Continuous mode forced\n");
333 configStandalone.cont = true;
334 }
337 }
338 }
339 if (configStandalone.setMaxTimeBin != -2) {
340 grp.grpContinuousMaxTimeBin = configStandalone.setMaxTimeBin;
341 } else if (configStandalone.cont && grp.grpContinuousMaxTimeBin == 0) {
343 }
344 if (grp.grpContinuousMaxTimeBin < -1 && !configStandalone.noEvents) {
345 printf("Invalid maxTimeBin %d\n", grp.grpContinuousMaxTimeBin);
346 return 1;
347 }
348 if (rec->GetDeviceType() == GPUReconstruction::DeviceType::CPU) {
349 printf("Standalone Test Framework for CA Tracker - Using CPU\n");
350 } else {
351 printf("Standalone Test Framework for CA Tracker - Using GPU\n");
352 }
353
354 configStandalone.proc.forceMemoryPoolSize = (configStandalone.proc.forceMemoryPoolSize == 1 && configStandalone.eventDisplay) ? 2 : configStandalone.proc.forceMemoryPoolSize;
355 if (configStandalone.eventDisplay) {
356 eventDisplay.reset(GPUDisplayFrontendInterface::getFrontend(configStandalone.display.displayFrontend.c_str()));
357 if (eventDisplay.get() == nullptr) {
358 throw std::runtime_error("Requested display not available");
359 }
360 printf("Enabling event display (%s backend)\n", eventDisplay->frontendName());
361 procSet.eventDisplay = eventDisplay.get();
362 if (!configStandalone.QA.noMC) {
363 procSet.runMC = true;
364 }
365 }
366
367 if (procSet.runQA && !configStandalone.QA.noMC) {
368 procSet.runMC = true;
369 }
370
371 steps.steps = GPUDataTypes::RecoStep::AllRecoSteps;
372 if (configStandalone.runTRD != -1) {
373 steps.steps.setBits(GPUDataTypes::RecoStep::TRDTracking, configStandalone.runTRD > 0);
374 } else if (chainTracking->GetTRDGeometry() == nullptr) {
375 steps.steps.setBits(GPUDataTypes::RecoStep::TRDTracking, false);
376 }
377 if (configStandalone.rundEdx != -1) {
378 steps.steps.setBits(GPUDataTypes::RecoStep::TPCdEdx, configStandalone.rundEdx > 0);
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 bool runAsyncQA = procSet.runQA && !configStandalone.testSyncAsyncQcInSync;
435 if (configStandalone.testSyncAsync || configStandalone.testSync) {
436 // Set settings for synchronous
437 if (configStandalone.rundEdx == -1) {
438 steps.steps.setBits(GPUDataTypes::RecoStep::TPCdEdx, 0);
439 }
440 recSet.useMatLUT = false;
441 if (configStandalone.testSyncAsync) {
442 procSet.eventDisplay = nullptr;
443 if (!configStandalone.testSyncAsyncQcInSync) {
444 procSet.runQA = false;
445 }
446 }
447 }
448 if (configStandalone.proc.rtc.optSpecialCode == -1) {
449 configStandalone.proc.rtc.optSpecialCode = configStandalone.testSyncAsync || configStandalone.testSync;
450 }
451
452 rec->SetSettings(&grp, &recSet, &procSet, &steps);
453 if (configStandalone.proc.doublePipeline) {
454 recPipeline->SetSettings(&grp, &recSet, &procSet, &steps);
455 }
456 if (configStandalone.testSyncAsync) {
457 // Set settings for asynchronous
458 steps.steps.setBits(GPUDataTypes::RecoStep::TPCDecompression, true);
459 steps.steps.setBits(GPUDataTypes::RecoStep::TPCdEdx, true);
460 steps.steps.setBits(GPUDataTypes::RecoStep::TPCCompression, false);
461 steps.steps.setBits(GPUDataTypes::RecoStep::TPCClusterFinding, false);
462 steps.inputs.setBits(GPUDataTypes::InOutType::TPCRaw, false);
463 steps.inputs.setBits(GPUDataTypes::InOutType::TPCClusters, false);
464 steps.inputs.setBits(GPUDataTypes::InOutType::TPCCompressedClusters, true);
465 steps.outputs.setBits(GPUDataTypes::InOutType::TPCCompressedClusters, false);
466 procSet.runMC = false;
467 procSet.runQA = runAsyncQA;
468 procSet.eventDisplay = eventDisplay.get();
469 procSet.runCompressionStatistics = 0;
470 procSet.rtc.optSpecialCode = 0;
471 if (recSet.tpc.rejectionStrategy >= GPUSettings::RejectionStrategyB) {
472 procSet.tpcInputWithClusterRejection = 1;
473 }
474 recSet.tpc.disableRefitAttachment = 0xFF;
475 recSet.maxTrackQPtB5 = CAMath::Min(recSet.maxTrackQPtB5, recSet.tpc.rejectQPtB5);
476 recSet.useMatLUT = true;
477 recAsync->SetSettings(&grp, &recSet, &procSet, &steps);
478 }
479
480 if (configStandalone.outputcontrolmem) {
481 rec->SetOutputControl(outputmemory.get(), configStandalone.outputcontrolmem);
482 if (configStandalone.proc.doublePipeline) {
484 }
485 }
486
487 o2::base::Propagator* prop = nullptr;
489 prop->setGPUField(&rec->GetParam().polynomialField);
490 prop->setNominalBz(rec->GetParam().bzkG);
491 prop->setMatLUT(chainTracking->GetMatLUT());
493 if (chainTrackingAsync) {
495 }
498 }
499 procSet.o2PropagatorUseGPUField = true;
500
501 if (rec->Init()) {
502 printf("Error initializing GPUReconstruction!\n");
503 return 1;
504 }
505 if (configStandalone.outputcontrolmem && rec->IsGPU()) {
506 if (rec->registerMemoryForGPU(outputmemory.get(), configStandalone.outputcontrolmem) || (configStandalone.proc.doublePipeline && recPipeline->registerMemoryForGPU(outputmemoryPipeline.get(), configStandalone.outputcontrolmem))) {
507 printf("ERROR registering memory for the GPU!!!\n");
508 return 1;
509 }
510 }
511 if (configStandalone.inputcontrolmem && rec->IsGPU()) {
512 if (rec->registerMemoryForGPU(inputmemory.get(), configStandalone.inputcontrolmem)) {
513 printf("ERROR registering input memory for the GPU!!!\n");
514 return 1;
515 }
516 }
517 if (configStandalone.proc.debugLevel >= 4) {
519 }
520 return (0);
521}
522
523int32_t ReadEvent(int32_t n)
524{
525 if (configStandalone.inputcontrolmem && !configStandalone.preloadEvents) {
526 rec->SetInputControl(inputmemory.get(), configStandalone.inputcontrolmem);
527 }
528 int32_t r = chainTracking->ReadData((eventsDir + GPUCA_EVDUMP_FILE "." + std::to_string(n) + ".dump").c_str());
529 if (r) {
530 return r;
531 }
532#if defined(GPUCA_TPC_GEOMETRY_O2) && defined(GPUCA_BUILD_QA) && !defined(GPUCA_O2_LIB)
533 if ((configStandalone.proc.runQA || configStandalone.eventDisplay) && !configStandalone.QA.noMC) {
536 if (chainTracking->GetQA()->ReadO2MCData((eventsDir + "mc." + std::to_string(n) + ".dump").c_str()) &&
537 chainTracking->GetQA()->ReadO2MCData((eventsDir + "mc.0.dump").c_str()) && configStandalone.proc.runQA) {
538 throw std::runtime_error("Error reading O2 MC dump");
539 }
540 }
541#endif
542 if (chainTracking->mIOPtrs.clustersNative && (configStandalone.TF.bunchSim || configStandalone.TF.nMerge || !configStandalone.runTransformation)) {
543 if (configStandalone.proc.debugLevel >= 2) {
544 printf("Converting Native to Legacy ClusterData for overlaying - WARNING: No raw clusters produced - Compression etc will not run!!!\n");
545 }
547 }
548 return 0;
549}
550
551int32_t LoadEvent(int32_t iEvent, int32_t x)
552{
553 if (configStandalone.TF.bunchSim) {
554 if (tf->LoadCreateTimeFrame(iEvent)) {
555 return 1;
556 }
557 } else if (configStandalone.TF.nMerge) {
558 if (tf->LoadMergedEvents(iEvent)) {
559 return 1;
560 }
561 } else {
562 if (ReadEvent(iEvent)) {
563 return 1;
564 }
565 }
566 bool encodeZS = configStandalone.encodeZS == -1 ? (chainTracking->mIOPtrs.tpcPackedDigits && !chainTracking->mIOPtrs.tpcZS) : (bool)configStandalone.encodeZS;
567 bool zsFilter = configStandalone.zsFilter == -1 ? (!encodeZS && chainTracking->mIOPtrs.tpcPackedDigits && !chainTracking->mIOPtrs.tpcZS) : (bool)configStandalone.zsFilter;
568 if (encodeZS || zsFilter) {
570 printf("Need digit input to run ZS\n");
571 return 1;
572 }
573 if (zsFilter) {
575 }
576 if (encodeZS) {
578 }
579 }
580 if (!configStandalone.runTransformation) {
582 } else {
583 for (int32_t i = 0; i < chainTracking->NSECTORS; i++) {
585 if (configStandalone.proc.debugLevel >= 2) {
586 printf("Converting Legacy Raw Cluster to Native\n");
587 }
589 break;
590 }
591 }
592 }
593
594 if (configStandalone.stripDumpedEvents) {
597 }
598 }
599
601 printf("Need cluster native data for on-the-fly TPC transform\n");
602 return 1;
603 }
604
606 ioMemEvents[x] = std::move(chainTracking->mIOMem);
608 return 0;
609}
610
611void OutputStat(GPUChainTracking* t, int64_t* nTracksTotal = nullptr, int64_t* nClustersTotal = nullptr)
612{
613 int32_t nTracks = 0;
614 if (t->GetProcessingSettings().createO2Output) {
615 nTracks += t->mIOPtrs.nOutputTracksTPCO2;
616 } else {
617 for (uint32_t k = 0; k < t->mIOPtrs.nMergedTracks; k++) {
618 if (t->mIOPtrs.mergedTracks[k].OK()) {
619 nTracks++;
620 }
621 }
622 }
623 if (nTracksTotal && nClustersTotal) {
624 *nTracksTotal += nTracks;
625 *nClustersTotal += t->mIOPtrs.nMergedTrackHits;
626 }
627}
628
629int32_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)
630{
631 int32_t iRun = 0, iteration = 0;
632 while ((iteration = nIteration.fetch_add(1)) < runs) {
633 if (configStandalone.runs > 1) {
634 printf("Run %d (thread %d)\n", iteration + 1, threadId);
635 }
636 recUse->SetResetTimers(iRun < configStandalone.runsInit);
637 if (configStandalone.outputcontrolmem) {
638 recUse->SetOutputControl(threadId ? outputmemoryPipeline.get() : outputmemory.get(), configStandalone.outputcontrolmem);
639 }
640
641 if (configStandalone.testSyncAsync) {
642 printf("Running synchronous phase\n");
643 }
644 const GPUTrackingInOutPointers& ioPtrs = ioPtrEvents[!configStandalone.preloadEvents ? 0 : configStandalone.proc.doublePipeline ? (iteration % ioPtrEvents.size()) : (iEvent - configStandalone.StartEvent)];
645 chainTrackingUse->mIOPtrs = ioPtrs;
646 if (iteration == (configStandalone.proc.doublePipeline ? 2 : (configStandalone.runs - 1))) {
647 if (configStandalone.proc.doublePipeline && timerPipeline) {
648 timerPipeline->Start();
649 }
650 if (configStandalone.controlProfiler) {
652 }
653 }
654 int32_t tmpRetVal = recUse->RunChains();
655 int32_t iterationEnd = nIterationEnd.fetch_add(1);
656 if (iterationEnd == configStandalone.runs - 1) {
657 if (configStandalone.proc.doublePipeline && timerPipeline) {
658 timerPipeline->Stop();
659 }
660 if (configStandalone.controlProfiler) {
662 }
663 }
664
665 if (tmpRetVal == 0 || tmpRetVal == 2) {
666 OutputStat(chainTrackingUse, iRun == 0 ? nTracksTotal : nullptr, iRun == 0 ? nClustersTotal : nullptr);
667 }
668
669 if (tmpRetVal == 0 && configStandalone.testSyncAsync) {
670
675 printf("Running asynchronous phase from %'u compressed clusters\n", syncAsyncDecodedClusters);
676
677 chainTrackingAsync->mIOPtrs = ioPtrs;
687 for (int32_t i = 0; i < chainTracking->NSECTORS; i++) {
692 }
694 recAsync->SetResetTimers(iRun < configStandalone.runsInit);
695 tmpRetVal = recAsync->RunChains();
696 if (tmpRetVal == 0 || tmpRetVal == 2) {
697 OutputStat(chainTrackingAsync, nullptr, nullptr);
698 }
700 }
701 if (!configStandalone.proc.doublePipeline) {
702 recUse->ClearAllocatedMemory();
703 }
704
705 if (tmpRetVal == 2) {
706 configStandalone.continueOnError = 0; // Forced exit from event display loop
707 configStandalone.noprompt = 1;
708 }
709 if (tmpRetVal == 3 && configStandalone.proc.ignoreNonFatalGPUErrors) {
710 printf("GPU Standalone Benchmark: Non-FATAL GPU error occured, ignoring\n");
711 } else if (tmpRetVal && !configStandalone.continueOnError) {
712 if (tmpRetVal != 2) {
713 printf("GPU Standalone Benchmark: Error occured\n");
714 }
715 return 1;
716 }
717 iRun++;
718 }
719 if (configStandalone.proc.doublePipeline) {
720 recUse->ClearAllocatedMemory();
721 }
722 nIteration.store(runs);
723 return 0;
724}
725
726int32_t main(int argc, char** argv)
727{
728 std::unique_ptr<GPUReconstruction> recUnique, recUniqueAsync, recUniquePipeline;
729
730 if (ReadConfiguration(argc, argv)) {
731 return 1;
732 }
733 eventsDir = std::string(configStandalone.absoluteEventsDir ? "" : "events/") + configStandalone.eventsDir + "/";
734
735 GPUSettingsDeviceBackend deviceSet;
736 deviceSet.deviceType = configStandalone.runGPU ? GPUDataTypes::GetDeviceType(configStandalone.gpuType.c_str()) : GPUDataTypes::DeviceType::CPU;
737 deviceSet.forceDeviceType = configStandalone.runGPUforce;
738 deviceSet.master = nullptr;
739 recUnique.reset(GPUReconstruction::CreateInstance(deviceSet));
740 rec = recUnique.get();
741 deviceSet.master = rec;
742 if (configStandalone.testSyncAsync) {
743 recUniqueAsync.reset(GPUReconstruction::CreateInstance(deviceSet));
744 recAsync = recUniqueAsync.get();
745 }
746 if (configStandalone.proc.doublePipeline) {
747 recUniquePipeline.reset(GPUReconstruction::CreateInstance(deviceSet));
748 recPipeline = recUniquePipeline.get();
749 }
750 if (rec == nullptr || (configStandalone.testSyncAsync && recAsync == nullptr)) {
751 printf("Error initializing GPUReconstruction\n");
752 return 1;
753 }
754 rec->SetDebugLevelTmp(configStandalone.proc.debugLevel);
756 if (configStandalone.testSyncAsync) {
757 if (configStandalone.proc.debugLevel >= 3) {
759 }
761 }
762 if (configStandalone.proc.doublePipeline) {
763 if (configStandalone.proc.debugLevel >= 3) {
765 }
768 }
769 if (!configStandalone.proc.doublePipeline) {
771 if (configStandalone.testSyncAsync) {
773 }
774 }
775
776 if (SetupReconstruction()) {
777 return 1;
778 }
779
780 std::unique_ptr<std::thread> pipelineThread;
781 if (configStandalone.proc.doublePipeline) {
782 pipelineThread.reset(new std::thread([]() { rec->RunPipelineWorker(); }));
783 }
784
785 if (configStandalone.seed == -1) {
786 std::random_device rd;
787 configStandalone.seed = (int32_t)rd();
788 printf("Using random seed %d\n", configStandalone.seed);
789 }
790
791 srand(configStandalone.seed);
792
793 for (nEventsInDirectory = 0; true; nEventsInDirectory++) {
794 std::ifstream in;
795 in.open((eventsDir + GPUCA_EVDUMP_FILE "." + std::to_string(nEventsInDirectory) + ".dump").c_str(), std::ifstream::binary);
796 if (in.fail()) {
797 break;
798 }
799 in.close();
800 }
801
802 if (configStandalone.TF.bunchSim || configStandalone.TF.nMerge) {
804 }
805
806 if (configStandalone.eventGenerator) {
808 return 0;
809 }
810
811 int32_t nEvents = configStandalone.nEvents;
812 if (configStandalone.TF.bunchSim) {
813 nEvents = configStandalone.nEvents > 0 ? configStandalone.nEvents : 1;
814 } else {
815 if (nEvents == -1 || nEvents > nEventsInDirectory) {
816 if (nEvents >= 0) {
817 printf("Only %d events available in directory %s (%d events requested)\n", nEventsInDirectory, eventsDir.c_str(), nEvents);
818 }
820 }
821 if (nEvents == 0 && !configStandalone.noEvents) {
822 printf("No event data found in event folder\n");
823 }
824 if (configStandalone.TF.nMerge > 1) {
825 nEvents /= configStandalone.TF.nMerge;
826 }
827 }
828
829 ioPtrEvents.resize(configStandalone.preloadEvents ? (nEvents - configStandalone.StartEvent) : 1);
830 ioMemEvents.resize(configStandalone.preloadEvents ? (nEvents - configStandalone.StartEvent) : 1);
831 if (configStandalone.preloadEvents) {
832 printf("Preloading events%s", configStandalone.proc.debugLevel >= 2 ? "\n" : "");
833 fflush(stdout);
834 for (int32_t i = 0; i < nEvents - configStandalone.StartEvent; i++) {
835 LoadEvent(configStandalone.StartEvent + i, i);
836 if (configStandalone.proc.debugLevel >= 2) {
837 printf("Loading event %d\n", i);
838 } else {
839 printf(" %d", i);
840 }
841 fflush(stdout);
842 }
843 printf("\n");
844 }
845
846 for (int32_t iRunOuter = 0; iRunOuter < configStandalone.runs2; iRunOuter++) {
847 if (configStandalone.QA.inputHistogramsOnly) {
849 break;
850 }
851 if (configStandalone.runs2 > 1) {
852 printf("\nRUN2: %d\n", iRunOuter);
853 }
854 int64_t nTracksTotal = 0;
855 int64_t nClustersTotal = 0;
856 int32_t nEventsProcessed = 0;
857
858 if (configStandalone.noEvents) {
859 nEvents = 1;
860 configStandalone.StartEvent = 0;
862 }
863
864 for (int32_t iEvent = configStandalone.StartEvent; iEvent < nEvents; iEvent++) {
865 if (iEvent != configStandalone.StartEvent) {
866 printf("\n");
867 }
868 if (configStandalone.noEvents == false && !configStandalone.preloadEvents) {
869 HighResTimer timerLoad;
870 timerLoad.Start();
871 if (LoadEvent(iEvent, 0)) {
872 goto breakrun;
873 }
874 if (configStandalone.dumpEvents) {
875 char fname[1024];
876 snprintf(fname, 1024, "event.%d.dump", nEventsProcessed);
877 chainTracking->DumpData(fname);
878 if (nEventsProcessed == 0) {
879 rec->DumpSettings();
880 }
881 }
882
885 if (grp.grpContinuousMaxTimeBin == 0) {
886 printf("Cannot override max time bin for non-continuous data!\n");
887 } else {
889 printf("Max time bin set to %d\n", grp.grpContinuousMaxTimeBin);
890 rec->UpdateSettings(&grp);
891 if (recAsync) {
893 }
894 if (recPipeline) {
896 }
897 }
898 }
899 printf("Loading time: %'d us\n", (int32_t)(1000000 * timerLoad.GetCurrentElapsedTime()));
900 }
901 printf("Processing Event %d\n", iEvent);
902
903 nIteration.store(0);
904 nIterationEnd.store(0);
905 double pipelineWalltime = 1.;
906 if (configStandalone.proc.doublePipeline) {
907 HighResTimer timerPipeline;
908 if (configStandalone.proc.debugLevel < 2 && (RunBenchmark(rec, chainTracking, 1, iEvent, &nTracksTotal, &nClustersTotal) || RunBenchmark(recPipeline, chainTrackingPipeline, 2, iEvent, &nTracksTotal, &nClustersTotal))) {
909 goto breakrun;
910 }
911 auto pipeline1 = std::async(std::launch::async, RunBenchmark, rec, chainTracking, configStandalone.runs, iEvent, &nTracksTotal, &nClustersTotal, 0, &timerPipeline);
912 auto pipeline2 = std::async(std::launch::async, RunBenchmark, recPipeline, chainTrackingPipeline, configStandalone.runs, iEvent, &nTracksTotal, &nClustersTotal, 1, &timerPipeline);
913 if (pipeline1.get() || pipeline2.get()) {
914 goto breakrun;
915 }
916 pipelineWalltime = timerPipeline.GetElapsedTime() / (configStandalone.runs - 2);
917 printf("Pipeline wall time: %f, %d iterations, %f per event\n", timerPipeline.GetElapsedTime(), configStandalone.runs - 2, pipelineWalltime);
918 } else {
919 if (RunBenchmark(rec, chainTracking, configStandalone.runs, iEvent, &nTracksTotal, &nClustersTotal)) {
920 goto breakrun;
921 }
922 }
923 nEventsProcessed++;
924
925 if (configStandalone.timeFrameTime) {
926 double nClusters = chainTracking->GetProcessors()->tpcMerger.NMaxClusters();
927 if (nClusters > 0) {
928 const int32_t nOrbits = 32;
929 const double colRate = 50000;
930 const double orbitRate = 11245;
931 const double nClsPerTF = 755851. * nOrbits * colRate / orbitRate;
932 double timePerTF = (configStandalone.proc.doublePipeline ? pipelineWalltime : ((configStandalone.proc.debugLevel ? rec->GetStatKernelTime() : rec->GetStatWallTime()) / 1000000.)) * nClsPerTF / nClusters;
933 const double nGPUsReq = timePerTF * orbitRate / nOrbits;
934 char stat[1024];
935 snprintf(stat, 1024, "Sync phase: %.2f sec per %d orbit TF, %.1f GPUs required", timePerTF, nOrbits, nGPUsReq);
936 if (configStandalone.testSyncAsync) {
937 timePerTF = (configStandalone.proc.debugLevel ? recAsync->GetStatKernelTime() : recAsync->GetStatWallTime()) / 1000000. * nClsPerTF / nClusters;
938 snprintf(stat + strlen(stat), 1024 - strlen(stat), " - Async phase: %f sec per TF", timePerTF);
939 }
940 printf("%s (Measured %s time - Extrapolated from %d clusters to %d)\n", stat, configStandalone.proc.debugLevel ? "kernel" : "wall", (int32_t)nClusters, (int32_t)nClsPerTF);
941 }
942 }
945 float rejectionPercentage = (rejected) * 100.f / chainTracking->mIOPtrs.clustersNative->nClustersTotal;
946 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);
947 }
948
949 if (configStandalone.preloadEvents && configStandalone.proc.doublePipeline) {
950 break;
951 }
952 }
953 if (nEventsProcessed > 1) {
954 printf("Total: %ld clusters, %ld tracks\n", nClustersTotal, nTracksTotal);
955 }
956 }
957
958breakrun:
959 if (rec->GetProcessingSettings().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_GLOBAL) {
961 }
962
963#ifndef _WIN32
964 if (configStandalone.proc.runQA && configStandalone.fpe) {
965 fedisableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW);
966 }
967#endif
968
969 if (configStandalone.proc.doublePipeline) {
971 pipelineThread->join();
972 }
973
974 rec->Finalize();
975 if (configStandalone.testSyncAsync) {
977 }
978 if (configStandalone.outputcontrolmem && rec->IsGPU()) {
980 printf("Error unregistering memory\n");
981 }
982 }
983 rec->Exit();
984
985 if (!configStandalone.noprompt) {
986 printf("Press a key to exit!\n");
987 getchar();
988 }
989 return (0);
990}
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:147
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
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 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