Project
Loading...
Searching...
No Matches
GPUReconstructionIO.h
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#if !defined(GPURECONSTRUCTIONIO_H)
16#define GPURECONSTRUCTIONIO_H
17
18#include "GPUReconstruction.h"
19#include "GPUSettings.h"
20
21namespace o2::gpu
22{
23
24template <class T>
25inline T* GPUReconstruction::AllocateIOMemoryHelper(size_t n, const T*& ptr, std::unique_ptr<T[]>& u)
26{
27 if (n == 0) {
28 u.reset(nullptr);
29 return nullptr;
30 }
31 T* retVal;
33 u.reset(nullptr);
36 if ((size_t)((char*)mInputControl.ptrCurrent - (char*)mInputControl.ptrBase) > mInputControl.size) {
37 throw std::bad_alloc();
38 }
39 } else {
40 u.reset(new T[n]);
41 retVal = u.get();
42 if (GetProcessingSettings().registerStandaloneInputMemory) {
43 if (registerMemoryForGPU(u.get(), n * sizeof(T))) {
44 GPUError("Error registering memory for GPU: %p - %zu bytes\n", (void*)u.get(), n * sizeof(T));
45 throw std::bad_alloc();
46 }
47 }
48 }
49 ptr = retVal;
50 return retVal;
51}
52
53template <class T, class S>
54inline uint32_t GPUReconstruction::DumpData(FILE* fp, const T* const* entries, const S* num, InOutPointerType type)
55{
57 uint32_t numTotal = 0;
58 for (int32_t i = 0; i < count; i++) {
59 numTotal += num[i];
60 }
61 if (numTotal == 0) {
62 return 0;
63 }
64 fwrite(&type, sizeof(type), 1, fp);
65 for (int32_t i = 0; i < count; i++) {
66 fwrite(&num[i], sizeof(num[i]), 1, fp);
67 if (num[i]) {
68 fwrite(entries[i], sizeof(*entries[i]), num[i], fp);
69 }
70 }
71 if (GetProcessingSettings().debugLevel >= 2) {
72 GPUInfo("Dumped %u %s", numTotal, IOTYPENAMES[type]);
73 }
74 return numTotal;
75}
76
77template <class T, class S>
78inline size_t GPUReconstruction::ReadData(FILE* fp, const T** entries, S* num, std::unique_ptr<T[]>* mem, InOutPointerType type, T** nonConstPtrs)
79{
80 if (feof(fp)) {
81 return 0;
82 }
83 InOutPointerType inType;
84 size_t r, pos = ftell(fp);
85 r = fread(&inType, sizeof(inType), 1, fp);
86 if (r != 1 || inType != type) {
87 fseek(fp, pos, SEEK_SET);
88 return 0;
89 }
90
92 size_t numTotal = 0;
93 for (int32_t i = 0; i < count; i++) {
94 r = fread(&num[i], sizeof(num[i]), 1, fp);
95 T* m = AllocateIOMemoryHelper(num[i], entries[i], mem[i]);
96 if (nonConstPtrs) {
97 nonConstPtrs[i] = m;
98 }
99 if (num[i]) {
100 r = fread(m, sizeof(*entries[i]), num[i], fp);
101 }
102 numTotal += num[i];
103 }
104 (void)r;
105 if (GetProcessingSettings().debugLevel >= 2) {
106 GPUInfo("Read %zu %s", numTotal, IOTYPENAMES[type]);
107 }
108 return numTotal;
109}
110
111template <class T>
112inline void GPUReconstruction::DumpFlatObjectToFile(const T* obj, const char* file)
113{
114 FILE* fp = fopen(file, "w+b");
115 if (fp == nullptr) {
116 return;
117 }
118 size_t size[2] = {sizeof(*obj), obj->getFlatBufferSize()};
119 fwrite(size, sizeof(size[0]), 2, fp);
120 fwrite(obj, 1, size[0], fp);
121 fwrite(obj->getFlatBufferPtr(), 1, size[1], fp);
122 fclose(fp);
123}
124
125template <class T>
126inline std::unique_ptr<T> GPUReconstruction::ReadFlatObjectFromFile(const char* file)
127{
128 FILE* fp = fopen(file, "rb");
129 if (fp == nullptr) {
130 return nullptr;
131 }
132 size_t size[2] = {0}, r;
133 r = fread(size, sizeof(size[0]), 2, fp);
134 if (r == 0 || size[0] != sizeof(T)) {
135 fclose(fp);
136 GPUError("ERROR reading %s, invalid size: %zu (%zu expected)", file, size[0], sizeof(T));
137 throw std::runtime_error("invalid size");
138 }
139 std::unique_ptr<T> retVal(new T);
140 retVal->destroy();
141 char* buf = new char[size[1]]; // Not deleted as ownership is transferred to FlatObject
142 r = fread((void*)retVal.get(), 1, size[0], fp);
143 r = fread(buf, 1, size[1], fp);
144 fclose(fp);
145 if (GetProcessingSettings().debugLevel >= 2) {
146 GPUInfo("Read %zu bytes from %s", r, file);
147 }
148 retVal->clearInternalBufferPtr();
149 retVal->setActualBufferAddress(buf);
150 retVal->adoptInternalBuffer(buf);
151 return retVal;
152}
153
154template <class T>
155inline void GPUReconstruction::DumpStructToFile(const T* obj, const char* file)
156{
157 FILE* fp = fopen(file, "w+b");
158 if (fp == nullptr) {
159 return;
160 }
161 size_t size = sizeof(*obj);
162 fwrite(&size, sizeof(size), 1, fp);
163 fwrite(obj, 1, size, fp);
164 fclose(fp);
165}
166
167template <class T>
168inline std::unique_ptr<T> GPUReconstruction::ReadStructFromFile(const char* file, T* obj, bool* errorOnMissing, bool allowSmaller)
169{
170 FILE* fp = fopen(file, "rb");
171 if (fp == nullptr) {
172 if (errorOnMissing) {
173 *errorOnMissing = true;
174 }
175 return nullptr;
176 }
177 size_t size, r;
178 r = fread(&size, sizeof(size), 1, fp);
179 if (r == 0 || (!allowSmaller && size != sizeof(T))) {
180 fclose(fp);
181 GPUError("ERROR reading %s, invalid size: %zu (%zu expected)", file, size, sizeof(T));
182 throw std::runtime_error("invalid size");
183 }
184 std::unique_ptr<T> retVal(nullptr);
185 if (obj == nullptr) {
186 retVal = std::make_unique<T>();
187 obj = retVal.get();
188 }
189 r = fread(obj, 1, size, fp);
190 fclose(fp);
191 if (r != size) {
192 GPUError("ERROR reading %s, read %zu (%zu expected)", file, r, size);
193 throw std::runtime_error("invalid size");
194 }
195 if (GetProcessingSettings().debugLevel >= 2) {
196 GPUInfo("Read %zu bytes from %s", r, file);
197 }
198 if (errorOnMissing) {
199 *errorOnMissing = false;
200 }
201 return retVal;
202}
203
204template <class T>
205inline void GPUReconstruction::DumpDynamicStructToFile(const T* obj, size_t dynamicSize, const char* file)
206{
207 FILE* fp = fopen(file, "w+b");
208 if (fp == nullptr) {
209 return;
210 }
211 size_t size = sizeof(*obj);
212 fwrite(&size, sizeof(size), 1, fp);
213 fwrite(&dynamicSize, sizeof(dynamicSize), 1, fp);
214 fwrite(obj, 1, dynamicSize, fp);
215 fclose(fp);
216}
217
218template <class T, auto F>
220{
221 FILE* fp = fopen(file, "rb");
222 if (fp == nullptr) {
223 return nullptr;
224 }
225 size_t size, dynsize, r, r2;
226 r = fread(&size, sizeof(size), 1, fp);
227 r2 = fread(&dynsize, sizeof(dynsize), 1, fp);
228 if (r == 0 || r2 == 0 || size != sizeof(T) || dynsize < size) {
229 fclose(fp);
230 GPUError("ERROR reading %s, invalid size: %zu (%zu buffer size, %zu object size expected)", file, size, dynsize, sizeof(T));
231 throw std::runtime_error("invalid size");
232 }
233 std::unique_ptr<T> tmp = std::make_unique<T>();
234 r = fread(tmp.get(), sizeof(T), 1, fp);
235 if (r == 0) {
236 fclose(fp);
237 GPUError("ERROR reading %s %zu (%zu expected)", file, size, sizeof(T));
238 throw std::runtime_error("read error");
239 }
240 if ((tmp.get()->*F)() != dynsize) {
241 fclose(fp);
242 GPUError("ERROR in %s: invalid size: %zu (%zu expected)", file, dynsize, (tmp.get()->*F)());
243 throw std::runtime_error("invalid size");
244 }
245 aligned_unique_buffer_ptr<T> newObj(dynsize);
246 memcpy(newObj.get(), tmp.get(), sizeof(T));
247 r = fread(newObj.getraw() + sizeof(T), 1, dynsize - sizeof(T), fp);
248 fclose(fp);
249 if (r != dynsize - sizeof(T)) {
250 GPUError("ERROR in %s: File Read error: %zu (%zu expected)", file, r, dynsize - sizeof(T));
251 throw std::runtime_error("invalid size");
252 }
253 if (GetProcessingSettings().debugLevel >= 2) {
254 GPUInfo("Read %zu bytes from %s", r + dynsize, file);
255 }
256 return newObj;
257}
258
259} // namespace o2::gpu
260
261#endif
std::vector< long > entries
int32_t i
int32_t retVal
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
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
uint16_t pos
Definition RawData.h:3
TBranch * ptr
double num
static void computePointerWithAlignment(T *&basePtr, S *&objPtr, size_t nEntries=1)
std::unique_ptr< T > ReadStructFromFile(const char *file, T *obj=nullptr, bool *errorOnMissing=nullptr, bool allowSmaller=false)
static uint32_t getNIOTypeMultiplicity(InOutPointerType type)
uint32_t DumpData(FILE *fp, const T *const *entries, const S *num, InOutPointerType type)
std::unique_ptr< T > ReadFlatObjectFromFile(const char *file)
void DumpStructToFile(const T *obj, const char *file)
void DumpDynamicStructToFile(const T *obj, size_t dynamicSize, const char *file)
T * AllocateIOMemoryHelper(size_t n, const T *&ptr, std::unique_ptr< T[]> &u)
static constexpr const char *const IOTYPENAMES[]
size_t ReadData(FILE *fp, const T **entries, S *num, std::unique_ptr< T[]> *mem, InOutPointerType type, T **nonConstPtrs=nullptr)
const GPUSettingsProcessing & GetProcessingSettings() const
void DumpFlatObjectToFile(const T *obj, const char *file)
int32_t registerMemoryForGPU(const void *ptr, size_t size)
aligned_unique_buffer_ptr< T > ReadDynamicStructFromFile(const char *file)
GLdouble n
Definition glcorearb.h:1982
const GLfloat * m
Definition glcorearb.h:4066
GLint GLsizei count
Definition glcorearb.h:399
GLsizeiptr size
Definition glcorearb.h:659
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLboolean r
Definition glcorearb.h:1233
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition glcorearb.h:2514