Project
Loading...
Searching...
No Matches
GPUDisplayHelpers.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 "GPUDisplay.h"
16#include "frontend/GPUDisplayInfo.inc"
17#include "HandMadeMath.h"
18#include "GPUChainTracking.h"
19#include "GPULogging.h"
20#include "GPUParam.h"
21
22#ifndef _WIN32
23#include "bitmapfile.h"
24#endif
25
26#include "oneapi/tbb.h"
27
28using namespace o2::gpu;
29
30int32_t GPUDisplay::getNumThreads()
31{
32 if (mChain) {
33 return mChain->GetProcessingSettings().nHostThreads;
34 } else {
35 return tbb::info::default_concurrency();
36 }
37}
38
39void GPUDisplay::updateOptions()
40{
41 if (mCfgH.splitCETracks == -1 && mParam) {
42 mCfgH.splitCETracks = mParam->continuousMaxTimeBin != 0;
43 }
44}
45
46void GPUDisplay::disableUnsupportedOptions()
47{
48 if (!mIOPtrs->mergedTrackHitAttachment) {
49 mCfgH.markAdjacentClusters = 0;
50 }
51 if (!mQA) {
52 mCfgH.markFakeClusters = 0;
53 }
54 if (!mChain) {
55 mCfgL.excludeClusters = mCfgL.drawInitLinks = mCfgL.drawLinks = mCfgL.drawSeeds = mCfgL.drawTracklets = mCfgL.drawTracks = mCfgL.drawExtrapolatedTracks = 0;
56 }
57}
58
59void GPUDisplay::takeScreenshot()
60{
61 static int32_t nScreenshot = 1;
62 mCfgC.requestScreenshot = true;
63 mScreenshotFile = mCfgO.mscreenShotName + std::to_string(nScreenshot++) + ".bmp";
64}
65
66void GPUDisplay::SaveGLPos()
67{
68 const char* file = mCfgO.glPosFile.c_str();
69 FILE* ftmp = fopen(file, "w+b");
70 if (!ftmp) {
71 SetInfo("Error opening file %s", file);
72 return;
73 }
74 bool ok = fwrite(mViewMatrix.get(), sizeof(*mViewMatrix), 1, ftmp) == 1;
75 ok = fclose(ftmp) == 0 && ok;
76 SetInfo(ok ? "Camera position stored to file %s" : "Error writing camera position to file %s", file);
77}
78
79void GPUDisplay::LoadGLPos()
80{
81 const char* file = mCfgO.glPosFile.c_str();
82 FILE* ftmp = fopen(file, "rb");
83 if (!ftmp) {
84 SetInfo("Error opening file %s", file);
85 return;
86 }
87 hmm_mat4 matrix;
88 const bool ok = fread(&matrix, sizeof(matrix), 1, ftmp) == 1;
89 fclose(ftmp);
90 if (ok) {
91 *mViewMatrix = matrix;
92 }
93 SetInfo(ok ? "Camera position loaded from file %s" : "Error reading camera position from file %s", file);
94}
95
96void GPUDisplay::SaveGLAnimation()
97{
98 const char* file = mCfgO.glAnimationFile.c_str();
99 FILE* ftmp = fopen(file, "w+b");
100 if (!ftmp) {
101 SetInfo("Error opening file %s", file);
102 return;
103 }
104 const int32_t size = mAnimationVectors.size();
105 bool ok = fwrite(&mCfgL, sizeof(mCfgL), 1, ftmp) == 1 && fwrite(&size, sizeof(size), 1, ftmp) == 1;
106 ok = ok && fwrite(mCfgC.animationPoints.values.data(), sizeof(float), size, ftmp) == (size_t)size;
107 ok = ok && fwrite(mAnimationVectors.data(), sizeof(mAnimationVectors[0]), size, ftmp) == (size_t)size;
108 ok = fclose(ftmp) == 0 && ok;
109 SetInfo(ok ? "Animation path stored to file %s" : "Error writing animation path to file %s", file);
110}
111
112void GPUDisplay::LoadGLAnimation()
113{
114 StopAnimation();
115 const char* file = mCfgO.glAnimationFile.c_str();
116 FILE* ftmp = fopen(file, "rb");
117 if (!ftmp) {
118 SetInfo("Error opening file %s", file);
119 return;
120 }
121 GPUSettingsDisplayLight cfg;
122 int32_t size = 0;
123 bool ok = fread(&cfg, sizeof(cfg), 1, ftmp) == 1 && fread(&size, sizeof(size), 1, ftmp) == 1 && size >= 0;
124 if (ok) { // Check the file size before allocating memory or changing anything
125 const long start = ftell(ftmp);
126 fseek(ftmp, 0, SEEK_END);
127 ok = (size_t)ftell(ftmp) == start + (size_t)size * (sizeof(float) + sizeof(animationVector));
128 fseek(ftmp, start, SEEK_SET);
129 }
130 if (ok) {
131 mCfgC.animationPoints.values.resize(size);
132 mAnimationVectors.resize(size);
133 ok = ok && fread(mCfgC.animationPoints.values.data(), sizeof(float), size, ftmp) == (size_t)size;
134 ok = ok && fread(mAnimationVectors.data(), sizeof(mAnimationVectors[0]), size, ftmp) == (size_t)size;
135 mCfgC.animationPoints.selected = -1;
136 if (ok) {
137 mCfgL = cfg;
138 updateConfig();
139 } else {
140 resetAnimation(); // Read error after the size check: no incomplete path
141 }
142 }
143 fclose(ftmp);
144 SetInfo(ok ? "Animation path loaded from file %s" : "Error reading animation path from file %s", file);
145}
146
147std::string GPUDisplay::trackFilterName() const
148{
149 if (mCfgH.trackFilter <= 0) {
150 return "";
151 }
152 return (uint32_t)mCfgH.trackFilter <= mConfig.filterMacros.size() ? "displayTrackFilter/" + mConfig.filterMacros[mCfgH.trackFilter - 1] : "Custom Macro";
153}
154
155void GPUDisplay::DoScreenshot(const char* filename, std::vector<char>& pixels, float animateTime)
156{
157 size_t screenshot_x = mBackend->mScreenWidth * mCfgR.screenshotScaleFactor;
158 size_t screenshot_y = mBackend->mScreenHeight * mCfgR.screenshotScaleFactor;
159 size_t size = 4 * screenshot_x * screenshot_y;
160 if (size != pixels.size()) {
161 GPUError("Pixel array of incorrect size obtained");
162 filename = nullptr;
163 }
164
165 if (filename) {
166 FILE* fp = fopen(filename, "w+b");
167 if (fp == nullptr) {
168 GPUError("Error opening screenshot file %s", filename);
169 return;
170 }
171
172 BITMAPFILEHEADER bmpFH;
173 BITMAPINFOHEADER bmpIH;
174 memset(&bmpFH, 0, sizeof(bmpFH));
175 memset(&bmpIH, 0, sizeof(bmpIH));
176
177 bmpFH.bfType = 19778; //"BM"
178 bmpFH.bfSize = sizeof(bmpFH) + sizeof(bmpIH) + size;
179 bmpFH.bfOffBits = sizeof(bmpFH) + sizeof(bmpIH);
180
181 bmpIH.biSize = sizeof(bmpIH);
182 bmpIH.biWidth = screenshot_x;
183 bmpIH.biHeight = screenshot_y;
184 bmpIH.biPlanes = 1;
185 bmpIH.biBitCount = 32;
186 bmpIH.biCompression = BI_RGB;
187 bmpIH.biSizeImage = size;
188 bmpIH.biXPelsPerMeter = 5670;
189 bmpIH.biYPelsPerMeter = 5670;
190
191 fwrite(&bmpFH, 1, sizeof(bmpFH), fp);
192 fwrite(&bmpIH, 1, sizeof(bmpIH), fp);
193 fwrite(pixels.data(), 1, size, fp);
194 fclose(fp);
195 }
196}
197
198void GPUDisplay::showInfo(const char* info)
199{
200 if (mCfgO.printInfoTextGUI) {
201 mGUIInfoStatus = info;
202 }
203 if (!(mCfgO.printInfoText & 1)) {
204 return;
205 }
206 float colorValue = mCfgL.invertColors ? 0.f : 1.f;
207 GLPrintText(info, 40.f, 20.f + std::max(20, mDrawTextFontSize + 4), colorValue, colorValue, colorValue, 1);
208 if (mInfoText2Timer.IsRunning()) {
209 const float time = mInfoText2Timer.GetCurrentElapsedTime(), shown = mConfig.internal.setInfoTime, transition = mConfig.internal.setInfoTransition;
210 if (time >= shown + transition) {
211 mInfoText2Timer.Reset();
212 } else {
213 GLPrintText(mInfoText2, 40.f, 20.f, colorValue, colorValue, colorValue, time <= shown ? 1.f : 1.f - (time - shown) / transition); // Opaque, then fading out
214 }
215 }
216 if (mInfoHelpTimer.IsRunning() || mCfgO.printInfoTextAlways) {
217 if (mInfoHelpTimer.GetCurrentElapsedTime() >= 6) {
218 mInfoHelpTimer.Reset();
219 } else {
220 PrintGLHelpText(colorValue);
221 }
222 }
223}
224
225float GPUDisplay::consoleVerticalFraction()
226{
227 const bool running = mConsoleTimer.IsRunning();
228 if (!mCfgC.showConsole && !running) {
229 return 0.f;
230 }
231 const double time = mConsoleTimer.GetCurrentElapsedTime();
232 if (running && !mCfgC.showConsole && time >= mConfig.internal.consoleDelay) { // Keeps running while open, for the blinking cursor
233 mConsoleTimer.Stop();
234 }
235 const float progress = running && mConfig.internal.consoleDelay > 0.f ? std::min(1.f, (float)(time / mConfig.internal.consoleDelay)) : 1.f;
236 return mConfig.internal.consoleVertical * (mCfgC.showConsole ? progress : 1.f - progress);
237}
238
239void GPUDisplay::GLPrintText(const char* s, float x, float y, float r, float g, float b, float a, uint32_t nCharacters, bool fromBotton)
240{
241 if (mBackend->mFreetypeInitialized) {
242 const float scale = mFrontend->getDisplayScale();
243 x *= scale;
244 y *= scale;
245 if (!fromBotton) {
246 y = mBackend->mScreenHeight - y;
247 }
248 float color[4] = {r, g, b, a};
249 mBackend->GLPrintText(s, x, y, color, scale / mBackend->mFontRasterScale, nCharacters);
250 }
251}
int16_t time
Definition RawEventData.h:4
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
@ BI_RGB
Definition bitmapfile.h:36
void Reset()
Definition timer.cxx:108
double GetCurrentElapsedTime(bool reset=false)
Definition timer.cxx:117
void Stop()
Definition timer.cxx:76
int32_t IsRunning()
Definition timer.h:34
const GPUSettingsProcessing & GetProcessingSettings() const
Definition GPUChain.h:76
virtual float getDisplayScale() const
GPUDisplayControl mCfgC
Definition GPUDisplay.h:93
const GPUSettingsDisplay & cfg() const
Definition GPUDisplay.h:75
GPUDisplayOptions mCfgO
Definition GPUDisplay.h:92
GLboolean GLboolean g
Definition glcorearb.h:1233
GLint GLenum GLint x
Definition glcorearb.h:403
GLsizeiptr size
Definition glcorearb.h:659
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLint y
Definition glcorearb.h:270
GLint GLint GLsizei GLint GLenum GLenum const void * pixels
Definition glcorearb.h:275
GLboolean r
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GPUdoubleBinary64 b
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
std::string filename()
uint32_t bfSize
Definition bitmapfile.h:17
uint32_t bfOffBits
Definition bitmapfile.h:19
uint16_t bfType
Definition bitmapfile.h:16
uint32_t biWidth
Definition bitmapfile.h:24
uint32_t biSize
Definition bitmapfile.h:23
uint32_t biSizeImage
Definition bitmapfile.h:29
uint32_t biCompression
Definition bitmapfile.h:28
uint16_t biBitCount
Definition bitmapfile.h:27
uint16_t biPlanes
Definition bitmapfile.h:26
uint32_t biHeight
Definition bitmapfile.h:25
uint32_t biXPelsPerMeter
Definition bitmapfile.h:30
uint32_t biYPelsPerMeter
Definition bitmapfile.h:31