forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGPUReconstruction.h
More file actions
486 lines (428 loc) · 22.2 KB
/
GPUReconstruction.h
File metadata and controls
486 lines (428 loc) · 22.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file GPUReconstruction.h
/// \author David Rohr
#if !defined(GPURECONSTRUCTION_H) && !defined(__OPENCL__)
#define GPURECONSTRUCTION_H
#include <cstddef>
#include <cstdio>
#include <cstring>
#include <string>
#include <memory>
#include <iosfwd>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include "GPUTRDDef.h"
#include "GPUParam.h"
#include "GPUSettings.h"
#include "GPUOutputControl.h"
#include "GPUMemoryResource.h"
#include "GPUConstantMem.h"
#include "GPULogging.h"
namespace o2::its
{
class TrackerTraits;
class VertexerTraits;
class TimeFrame;
} // namespace o2::its
namespace o2::gpu
{
class GPUChain;
struct GPUMemorySizeScalers;
struct GPUReconstructionPipelineContext;
struct GPUReconstructionThreading;
class GPUROOTDumpCore;
namespace gpu_reconstruction_kernels
{
struct deviceEvent;
class threadContext;
} // namespace gpu_reconstruction_kernels
class GPUReconstruction
{
protected:
class LibraryLoader; // These must be the first members to ensure correct destructor order!
std::shared_ptr<LibraryLoader> mMyLib = nullptr;
std::vector<GPUMemoryResource> mMemoryResources;
std::vector<std::unique_ptr<char[]>> mUnmanagedChunks;
std::vector<std::unique_ptr<char[]>> mVolatileChunks;
std::vector<std::unique_ptr<GPUChain>> mChains;
public:
virtual ~GPUReconstruction();
GPUReconstruction(const GPUReconstruction&) = delete;
GPUReconstruction& operator=(const GPUReconstruction&) = delete;
// General definitions
constexpr static uint32_t NSECTORS = GPUCA_NSECTORS;
using GeometryType = GPUDataTypes::GeometryType;
using DeviceType = GPUDataTypes::DeviceType;
using RecoStep = GPUDataTypes::RecoStep;
using GeneralStep = GPUDataTypes::GeneralStep;
using RecoStepField = GPUDataTypes::RecoStepField;
using InOutTypeField = GPUDataTypes::InOutTypeField;
static constexpr const char* const GEOMETRY_TYPE_NAMES[] = {"INVALID", "ALIROOT", "O2"};
#ifdef GPUCA_TPC_GEOMETRY_O2
static constexpr GeometryType geometryType = GeometryType::O2;
#else
static constexpr GeometryType geometryType = GeometryType::ALIROOT;
#endif
static DeviceType GetDeviceType(const char* type);
enum InOutPointerType : uint32_t { CLUSTER_DATA = 0,
SECTOR_OUT_TRACK = 1,
SECTOR_OUT_CLUSTER = 2,
MC_LABEL_TPC = 3,
MC_INFO_TPC = 4,
MERGED_TRACK = 5,
MERGED_TRACK_HIT = 6,
TRD_TRACK = 7,
TRD_TRACKLET = 8,
RAW_CLUSTERS = 9,
CLUSTERS_NATIVE = 10,
TRD_TRACKLET_MC = 11,
TPC_COMPRESSED_CL = 12,
TPC_DIGIT = 13,
TPC_ZS = 14,
CLUSTER_NATIVE_MC = 15,
TPC_DIGIT_MC = 16,
TRD_SPACEPOINT = 17,
TRD_TRIGGERRECORDS = 18,
TF_SETTINGS = 19 };
static constexpr const char* const IOTYPENAMES[] = {"TPC HLT Clusters", "TPC Sector Tracks", "TPC Sector Track Clusters", "TPC Cluster MC Labels", "TPC Track MC Informations", "TPC Tracks", "TPC Track Clusters", "TRD Tracks", "TRD Tracklets",
"TPC Raw Clusters", "TPC Native Clusters", "TRD Tracklet MC Labels", "TPC Compressed Clusters", "TPC Digit", "TPC ZS Page", "TPC Native Clusters MC Labels", "TPC Digit MC Labeels",
"TRD Spacepoints", "TRD Triggerrecords", "TF Settings"};
static uint32_t getNIOTypeMultiplicity(InOutPointerType type) { return (type == CLUSTER_DATA || type == SECTOR_OUT_TRACK || type == SECTOR_OUT_CLUSTER || type == RAW_CLUSTERS || type == TPC_DIGIT || type == TPC_DIGIT_MC) ? NSECTORS : 1; }
// Functionality to create an instance of GPUReconstruction for the desired device
static GPUReconstruction* CreateInstance(const GPUSettingsDeviceBackend& cfg);
static GPUReconstruction* CreateInstance(DeviceType type = DeviceType::CPU, bool forceType = true, GPUReconstruction* master = nullptr);
static GPUReconstruction* CreateInstance(int32_t type, bool forceType, GPUReconstruction* master = nullptr) { return CreateInstance((DeviceType)type, forceType, master); }
static GPUReconstruction* CreateInstance(const char* type, bool forceType, GPUReconstruction* master = nullptr);
static bool CheckInstanceAvailable(DeviceType type, bool verbose);
enum class krnlDeviceType : int32_t { CPU = 0,
Device = 1,
Auto = -1 };
// Global steering functions
template <class T, typename... Args>
T* AddChain(Args... args);
int32_t Init();
int32_t Finalize();
int32_t Exit();
void DumpSettings(const char* dir = "");
int32_t ReadSettings(const char* dir = "");
void PrepareEvent();
virtual int32_t RunChains() = 0;
uint32_t getNEventsProcessed() { return mNEventsProcessed; }
uint32_t getNEventsProcessedInStat() { return mStatNEvents; }
int32_t registerMemoryForGPU(const void* ptr, size_t size);
int32_t unregisterMemoryForGPU(const void* ptr);
virtual void* getGPUPointer(void* ptr) { return ptr; }
virtual void startGPUProfiling() {}
virtual void endGPUProfiling() {}
int32_t GPUChkErrA(const int64_t error, const char* file, int32_t line, bool failOnError);
int32_t CheckErrorCodes(bool cpuOnly = false, bool forceShowErrors = false, std::vector<std::array<uint32_t, 4>>* fillErrors = nullptr);
void RunPipelineWorker();
void TerminatePipelineWorker();
// Helpers for memory allocation
GPUMemoryResource& Res(int16_t num) { return mMemoryResources[num]; }
template <class T>
int16_t RegisterMemoryAllocation(T* proc, void* (T::*setPtr)(void*), int32_t type, const char* name = "", const GPUMemoryReuse& re = GPUMemoryReuse());
size_t AllocateMemoryResources();
size_t AllocateRegisteredMemory(GPUProcessor* proc, bool resetCustom = false);
size_t AllocateRegisteredMemory(int16_t res, GPUOutputControl* control = nullptr);
void AllocateRegisteredForeignMemory(int16_t res, GPUReconstruction* rec, GPUOutputControl* control = nullptr);
void* AllocateUnmanagedMemory(size_t size, int32_t type);
void* AllocateVolatileDeviceMemory(size_t size);
void* AllocateVolatileMemory(size_t size, bool device);
void FreeRegisteredMemory(GPUProcessor* proc, bool freeCustom = false, bool freePermanent = false);
void FreeRegisteredMemory(int16_t res);
void ClearAllocatedMemory(bool clearOutputs = true);
void ReturnVolatileDeviceMemory();
void ReturnVolatileMemory();
void PushNonPersistentMemory(uint64_t tag);
void PopNonPersistentMemory(RecoStep step, uint64_t tag);
void BlockStackedMemory(GPUReconstruction* rec);
void UnblockStackedMemory();
void ResetRegisteredMemoryPointers(GPUProcessor* proc);
void ResetRegisteredMemoryPointers(int16_t res);
void ComputeReuseMax(GPUProcessor* proc);
void PrintMemoryStatistics();
void PrintMemoryOverview();
void PrintMemoryMax();
void SetMemoryExternalInput(int16_t res, void* ptr);
GPUMemorySizeScalers* MemoryScalers() { return mMemoryScalers.get(); }
// Helpers to fetch processors from other shared libraries
virtual void GetITSTraits(std::unique_ptr<o2::its::TrackerTraits>* trackerTraits, std::unique_ptr<o2::its::VertexerTraits>* vertexerTraits, std::unique_ptr<o2::its::TimeFrame>* timeFrame);
bool slavesExist() { return mSlaves.size() || mMaster; }
// Getters / setters for parameters
DeviceType GetDeviceType() const { return (DeviceType)mDeviceBackendSettings.deviceType; }
bool IsGPU() const { return GetDeviceType() != DeviceType::INVALID_DEVICE && GetDeviceType() != DeviceType::CPU; }
const GPUParam& GetParam() const { return mHostConstantMem->param; }
const GPUConstantMem& GetConstantMem() const { return *mHostConstantMem; }
const GPUSettingsGRP& GetGRPSettings() const { return mGRPSettings; }
const GPUSettingsDeviceBackend& GetDeviceBackendSettings() { return mDeviceBackendSettings; }
const GPUSettingsProcessing& GetProcessingSettings() const { return mProcessingSettings; }
bool IsInitialized() const { return mInitialized; }
void SetSettings(float solenoidBzNominalGPU, const GPURecoStepConfiguration* workflow = nullptr);
void SetSettings(const GPUSettingsGRP* grp, const GPUSettingsRec* rec = nullptr, const GPUSettingsProcessing* proc = nullptr, const GPURecoStepConfiguration* workflow = nullptr);
void SetResetTimers(bool reset) { mProcessingSettings.resetTimers = reset; } // May update also after Init()
void SetDebugLevelTmp(int32_t level) { mProcessingSettings.debugLevel = level; } // Temporarily, before calling SetSettings()
void UpdateSettings(const GPUSettingsGRP* g, const GPUSettingsProcessing* p = nullptr, const GPUSettingsRecDynamic* d = nullptr);
void UpdateDynamicSettings(const GPUSettingsRecDynamic* d);
void SetOutputControl(const GPUOutputControl& v) { mOutputControl = v; }
void SetOutputControl(void* ptr, size_t size);
void SetInputControl(void* ptr, size_t size);
GPUOutputControl& OutputControl() { return mOutputControl; }
uint32_t NStreams() const { return mNStreams; }
const void* DeviceMemoryBase() const { return mDeviceMemoryBase; }
RecoStepField GetRecoSteps() const { return mRecoSteps.steps; }
RecoStepField GetRecoStepsGPU() const { return mRecoSteps.stepsGPUMask; }
InOutTypeField GetRecoStepsInputs() const { return mRecoSteps.inputs; }
InOutTypeField GetRecoStepsOutputs() const { return mRecoSteps.outputs; }
int32_t getRecoStepNum(RecoStep step, bool validCheck = true);
int32_t getGeneralStepNum(GeneralStep step, bool validCheck = true);
void setErrorCodeOutput(std::vector<std::array<uint32_t, 4>>* v) { mOutputErrorCodes = v; }
std::vector<std::array<uint32_t, 4>>* getErrorCodeOutput() { return mOutputErrorCodes; }
// Registration of GPU Processors
template <class T>
void RegisterGPUProcessor(T* proc, bool deviceSlave);
template <class T>
void SetupGPUProcessor(T* proc, bool allocate);
void RegisterGPUDeviceProcessor(GPUProcessor* proc, GPUProcessor* slaveProcessor);
void ConstructGPUProcessor(GPUProcessor* proc);
// Support / Debugging
virtual void PrintKernelOccupancies() {}
double GetStatKernelTime() { return mStatKernelTime; }
double GetStatWallTime() { return mStatWallTime; }
// Threading
std::shared_ptr<GPUReconstructionThreading> mThreading;
static int32_t getHostThreadIndex();
int32_t GetMaxBackendThreads() const { return mMaxBackendThreads; }
protected:
void AllocateRegisteredMemoryInternal(GPUMemoryResource* res, GPUOutputControl* control, GPUReconstruction* recPool);
void FreeRegisteredMemory(GPUMemoryResource* res);
GPUReconstruction(const GPUSettingsDeviceBackend& cfg); // Constructor
int32_t InitPhaseBeforeDevice();
virtual void UpdateAutomaticProcessingSettings() {}
virtual int32_t InitDevice() = 0;
int32_t InitPhasePermanentMemory();
int32_t InitPhaseAfterDevice();
void WriteConstantParams();
virtual int32_t ExitDevice() = 0;
virtual size_t WriteToConstantMemory(size_t offset, const void* src, size_t size, int32_t stream = -1, gpu_reconstruction_kernels::deviceEvent* ev = nullptr) = 0;
void UpdateMaxMemoryUsed();
int32_t EnqueuePipeline(bool terminate = false);
GPUChain* GetNextChainInQueue();
virtual int32_t GPUChkErrInternal(const int64_t error, const char* file, int32_t line) const { return 0; }
virtual int32_t registerMemoryForGPU_internal(const void* ptr, size_t size) = 0;
virtual int32_t unregisterMemoryForGPU_internal(const void* ptr) = 0;
// Management for GPU thread contexts
virtual std::unique_ptr<gpu_reconstruction_kernels::threadContext> GetThreadContext() = 0;
// Private helpers for library loading
static std::shared_ptr<LibraryLoader>* GetLibraryInstance(DeviceType type, bool verbose);
// Private helper functions for memory management
size_t AllocateRegisteredMemoryHelper(GPUMemoryResource* res, void*& ptr, void*& memorypool, void* memorybase, size_t memorysize, void* (GPUMemoryResource::*SetPointers)(void*), void*& memorypoolend, const char* device);
size_t AllocateRegisteredPermanentMemory();
// Private helper functions for reading / writing / allocating IO buffer from/to file
template <class T, class S>
uint32_t DumpData(FILE* fp, const T* const* entries, const S* num, InOutPointerType type);
template <class T, class S>
size_t ReadData(FILE* fp, const T** entries, S* num, std::unique_ptr<T[]>* mem, InOutPointerType type, T** nonConstPtrs = nullptr);
template <class T>
T* AllocateIOMemoryHelper(size_t n, const T*& ptr, std::unique_ptr<T[]>& u);
// Private helper functions to dump / load flat objects
template <class T>
void DumpFlatObjectToFile(const T* obj, const char* file);
template <class T>
std::unique_ptr<T> ReadFlatObjectFromFile(const char* file);
template <class T>
void DumpStructToFile(const T* obj, const char* file);
template <class T>
std::unique_ptr<T> ReadStructFromFile(const char* file);
template <class T>
int32_t ReadStructFromFile(const char* file, T* obj);
// Others
virtual RecoStepField AvailableGPURecoSteps() { return RecoStep::AllRecoSteps; }
virtual bool CanQueryMaxMemory() { return false; }
// Pointers to tracker classes
GPUConstantMem* processors() { return mHostConstantMem.get(); }
const GPUConstantMem* processors() const { return mHostConstantMem.get(); }
GPUParam& param() { return mHostConstantMem->param; }
std::unique_ptr<GPUConstantMem> mHostConstantMem;
GPUConstantMem* mDeviceConstantMem = nullptr;
// Settings
GPUSettingsGRP mGRPSettings; // Global Run Parameters
GPUSettingsDeviceBackend mDeviceBackendSettings; // Processing Parameters (at constructor level)
GPUSettingsProcessing mProcessingSettings; // Processing Parameters (at init level)
GPUOutputControl mOutputControl; // Controls the output of the individual components
GPUOutputControl mInputControl; // Prefefined input memory location for reading standalone dumps
std::unique_ptr<GPUMemorySizeScalers> mMemoryScalers; // Scalers how much memory will be needed
GPURecoStepConfiguration mRecoSteps;
std::string mDeviceName = "CPU";
// Ptrs to host and device memory;
void* mHostMemoryBase = nullptr; // Ptr to begin of large host memory buffer
void* mHostMemoryPermanent = nullptr; // Ptr to large host memory buffer offset by permanently allocated memory
void* mHostMemoryPool = nullptr; // Ptr to next free location in host memory buffer
void* mHostMemoryPoolEnd = nullptr; // Ptr to end of pool
void* mHostMemoryPoolBlocked = nullptr; // Ptr to end of pool
size_t mHostMemorySize = 0; // Size of host memory buffer
size_t mHostMemoryUsedMax = 0; // Maximum host memory size used over time
void* mDeviceMemoryBase = nullptr; //
void* mDeviceMemoryPermanent = nullptr; //
void* mDeviceMemoryPool = nullptr; //
void* mDeviceMemoryPoolEnd = nullptr; //
void* mDeviceMemoryPoolBlocked = nullptr; //
size_t mDeviceMemorySize = 0; //
void* mVolatileMemoryStart = nullptr; // Ptr to beginning of temporary volatile memory allocation, nullptr if uninitialized
size_t mDeviceMemoryUsedMax = 0; //
std::unordered_set<const void*> mRegisteredMemoryPtrs; // List of pointers registered for GPU
GPUReconstruction* mMaster = nullptr; // Ptr to a GPUReconstruction object serving as master, sharing GPU memory, events, etc.
std::vector<GPUReconstruction*> mSlaves; // Ptr to slave GPUReconstructions
// Others
bool mInitialized = false;
bool mInErrorHandling = false;
uint32_t mStatNEvents = 0;
uint32_t mNEventsProcessed = 0;
double mStatKernelTime = 0.;
double mStatWallTime = 0.;
double mStatCPUTime = 0.;
std::shared_ptr<GPUROOTDumpCore> mROOTDump;
std::vector<std::array<uint32_t, 4>>* mOutputErrorCodes = nullptr;
int32_t mMaxBackendThreads = 0; // Maximum number of threads that may be running, on CPU or GPU
int32_t mGPUStuck = 0; // Marks that the GPU is stuck, skip future events
int32_t mNStreams = 1; // Number of parallel GPU streams
int32_t mMaxHostThreads = 0; // Maximum number of OMP threads
// Management for GPUProcessors
struct ProcessorData {
ProcessorData(GPUProcessor* p, void (GPUProcessor::*r)(), void (GPUProcessor::*i)(), void (GPUProcessor::*d)(const GPUTrackingInOutPointers&)) : proc(p), RegisterMemoryAllocation(r), InitializeProcessor(i), SetMaxData(d) {}
GPUProcessor* proc;
void (GPUProcessor::*RegisterMemoryAllocation)();
void (GPUProcessor::*InitializeProcessor)();
void (GPUProcessor::*SetMaxData)(const GPUTrackingInOutPointers&);
};
std::vector<ProcessorData> mProcessors;
struct MemoryReuseMeta {
MemoryReuseMeta() = default;
MemoryReuseMeta(GPUProcessor* p, uint16_t r) : proc(p), res{r} {}
GPUProcessor* proc = nullptr;
std::vector<uint16_t> res;
};
std::unordered_map<GPUMemoryReuse::ID, MemoryReuseMeta> mMemoryReuse1to1;
std::vector<std::tuple<void*, void*, size_t, uint64_t>> mNonPersistentMemoryStack;
std::vector<GPUMemoryResource*> mNonPersistentIndividualAllocations;
std::unique_ptr<GPUReconstructionPipelineContext> mPipelineContext;
// Helpers for loading device library via dlopen
class LibraryLoader
{
public:
~LibraryLoader();
LibraryLoader(const LibraryLoader&) = delete;
const LibraryLoader& operator=(const LibraryLoader&) = delete;
private:
friend class GPUReconstruction;
LibraryLoader(const char* lib, const char* func);
int32_t LoadLibrary();
int32_t CloseLibrary();
GPUReconstruction* GetPtr(const GPUSettingsDeviceBackend& cfg);
const char* mLibName;
const char* mFuncName;
void* mGPULib;
void* mGPUEntry;
};
static std::shared_ptr<LibraryLoader> sLibCUDA, sLibHIP, sLibOCL;
static GPUReconstruction* GPUReconstruction_Create_CPU(const GPUSettingsDeviceBackend& cfg);
};
template <class T>
inline T* GPUReconstruction::AllocateIOMemoryHelper(size_t n, const T*& ptr, std::unique_ptr<T[]>& u)
{
if (n == 0) {
u.reset(nullptr);
return nullptr;
}
T* retVal;
if (mInputControl.useExternal()) {
u.reset(nullptr);
mInputControl.checkCurrent();
GPUProcessor::computePointerWithAlignment(mInputControl.ptrCurrent, retVal, n);
if ((size_t)((char*)mInputControl.ptrCurrent - (char*)mInputControl.ptrBase) > mInputControl.size) {
throw std::bad_alloc();
}
} else {
u.reset(new T[n]);
retVal = u.get();
if (mProcessingSettings.registerStandaloneInputMemory) {
if (registerMemoryForGPU(u.get(), n * sizeof(T))) {
GPUError("Error registering memory for GPU: %p - %ld bytes\n", (void*)u.get(), (int64_t)(n * sizeof(T)));
throw std::bad_alloc();
}
}
}
ptr = retVal;
return retVal;
}
template <class T, typename... Args>
inline T* GPUReconstruction::AddChain(Args... args)
{
mChains.emplace_back(new T(this, args...));
return (T*)mChains.back().get();
}
template <class T>
inline int16_t GPUReconstruction::RegisterMemoryAllocation(T* proc, void* (T::*setPtr)(void*), int32_t type, const char* name, const GPUMemoryReuse& re)
{
if (!(type & (GPUMemoryResource::MEMORY_HOST | GPUMemoryResource::MEMORY_GPU))) {
if ((type & GPUMemoryResource::MEMORY_SCRATCH) && !mProcessingSettings.keepDisplayMemory) { // keepAllMemory --> keepDisplayMemory
type |= (proc->mGPUProcessorType == GPUProcessor::PROCESSOR_TYPE_CPU ? GPUMemoryResource::MEMORY_HOST : GPUMemoryResource::MEMORY_GPU);
} else {
type |= GPUMemoryResource::MEMORY_HOST | GPUMemoryResource::MEMORY_GPU;
}
}
if (proc->mGPUProcessorType == GPUProcessor::PROCESSOR_TYPE_CPU) {
type &= ~GPUMemoryResource::MEMORY_GPU;
}
mMemoryResources.emplace_back(proc, static_cast<void* (GPUProcessor::*)(void*)>(setPtr), (GPUMemoryResource::MemoryType)type, name);
if (mMemoryResources.size() >= 32768) {
throw std::bad_alloc();
}
uint16_t retVal = mMemoryResources.size() - 1;
if (re.type != GPUMemoryReuse::NONE && !mProcessingSettings.disableMemoryReuse) {
const auto& it = mMemoryReuse1to1.find(re.id);
if (it == mMemoryReuse1to1.end()) {
mMemoryReuse1to1[re.id] = {proc, retVal};
} else {
mMemoryResources[retVal].mReuse = it->second.res[0];
it->second.res.emplace_back(retVal);
}
}
return retVal;
}
template <class T>
inline void GPUReconstruction::RegisterGPUProcessor(T* proc, bool deviceSlave)
{
mProcessors.emplace_back(proc, static_cast<void (GPUProcessor::*)()>(&T::RegisterMemoryAllocation), static_cast<void (GPUProcessor::*)()>(&T::InitializeProcessor), static_cast<void (GPUProcessor::*)(const GPUTrackingInOutPointers& io)>(&T::SetMaxData));
GPUProcessor::ProcessorType processorType = deviceSlave ? GPUProcessor::PROCESSOR_TYPE_SLAVE : GPUProcessor::PROCESSOR_TYPE_CPU;
proc->InitGPUProcessor(this, processorType);
}
template <class T>
inline void GPUReconstruction::SetupGPUProcessor(T* proc, bool allocate)
{
static_assert(sizeof(T) > sizeof(GPUProcessor), "Need to setup derived class");
if (allocate) {
proc->SetMaxData(mHostConstantMem->ioPtrs);
}
if (proc->mGPUProcessorType != GPUProcessor::PROCESSOR_TYPE_DEVICE && proc->mLinkedProcessor) {
std::memcpy((void*)proc->mLinkedProcessor, (const void*)proc, sizeof(*proc));
proc->mLinkedProcessor->InitGPUProcessor((GPUReconstruction*)this, GPUProcessor::PROCESSOR_TYPE_DEVICE, proc);
}
if (allocate) {
AllocateRegisteredMemory(proc, true);
} else {
ResetRegisteredMemoryPointers(proc);
}
}
} // namespace o2::gpu
#endif