2525#include < unordered_map>
2626#include < unordered_set>
2727
28- #include " GPUTRDDef.h"
29- #include " GPUParam.h"
30- #include " GPUSettings.h"
31- #include " GPUOutputControl.h"
28+ #include " GPUDataTypes.h"
3229#include " GPUMemoryResource.h"
33- #include " GPUConstantMem.h"
34- #include " GPULogging.h"
30+ #include " GPUOutputControl.h"
31+
32+ /* #include "GPUParam.h"
33+ #include "GPUSettings.h"
34+ #include "GPULogging.h"*/
3535
3636namespace o2 ::its
3737{
@@ -49,6 +49,13 @@ struct GPUReconstructionThreading;
4949class GPUROOTDumpCore ;
5050class ThrustVolatileAllocator ;
5151struct GPUDefParameters ;
52+ class GPUMemoryResource ;
53+ struct GPUSettingsDeviceBackend ;
54+ struct GPUSettingsGRP ;
55+ struct GPUSettingsProcessing ;
56+ struct GPUSettingsRec ;
57+ struct GPUSettingsRecDynamic ;
58+ struct GPUMemoryReuse ;
5259
5360namespace gpu_reconstruction_kernels
5461{
@@ -186,18 +193,20 @@ class GPUReconstruction
186193 bool slavesExist () { return mSlaves .size () || mMaster ; }
187194
188195 // Getters / setters for parameters
189- DeviceType GetDeviceType () const { return (DeviceType) mDeviceBackendSettings . deviceType ; }
196+ DeviceType GetDeviceType () const ;
190197 bool IsGPU () const { return GetDeviceType () != DeviceType::INVALID_DEVICE && GetDeviceType () != DeviceType::CPU; }
191- const GPUParam& GetParam () const { return mHostConstantMem -> param ; }
198+ const GPUParam& GetParam () const ;
192199 const GPUConstantMem& GetConstantMem () const { return *mHostConstantMem ; }
193- const GPUSettingsGRP& GetGRPSettings () const { return mGRPSettings ; }
194- const GPUSettingsDeviceBackend& GetDeviceBackendSettings () { return mDeviceBackendSettings ; }
195- const GPUSettingsProcessing& GetProcessingSettings () const { return mProcessingSettings ; }
200+ const GPUTrackingInOutPointers GetIOPtrs () const ;
201+ const GPUSettingsGRP& GetGRPSettings () const { return *mGRPSettings ; }
202+ const GPUSettingsDeviceBackend& GetDeviceBackendSettings () const { return *mDeviceBackendSettings ; }
203+ const GPUSettingsProcessing& GetProcessingSettings () const { return *mProcessingSettings ; }
204+ const GPUCalibObjectsConst& GetCalib () const ;
196205 bool IsInitialized () const { return mInitialized ; }
197206 void SetSettings (float solenoidBzNominalGPU, const GPURecoStepConfiguration* workflow = nullptr );
198207 void SetSettings (const GPUSettingsGRP* grp, const GPUSettingsRec* rec = nullptr , const GPUSettingsProcessing* proc = nullptr , const GPURecoStepConfiguration* workflow = nullptr );
199- void SetResetTimers (bool reset) { mProcessingSettings . resetTimers = reset; } // May update also after Init()
200- void SetDebugLevelTmp (int32_t level) { mProcessingSettings . debugLevel = level; } // Temporarily, before calling SetSettings()
208+ void SetResetTimers (bool reset); // May update also after Init()
209+ void SetDebugLevelTmp (int32_t level); // Temporarily, before calling SetSettings()
201210 void UpdateSettings (const GPUSettingsGRP* g, const GPUSettingsProcessing* p = nullptr , const GPUSettingsRecDynamic* d = nullptr );
202211 void UpdateDynamicSettings (const GPUSettingsRecDynamic* d);
203212 void SetOutputControl (const GPUOutputControl& v) { mOutputControl = v; }
@@ -272,6 +281,7 @@ class GPUReconstruction
272281 size_t ReadData (FILE* fp, const T** entries, S* num, std::unique_ptr<T[]>* mem, InOutPointerType type, T** nonConstPtrs = nullptr );
273282 template <class T >
274283 T* AllocateIOMemoryHelper (size_t n, const T*& ptr, std::unique_ptr<T[]>& u);
284+ int16_t RegisterMemoryAllocationHelper (GPUProcessor* proc, void * (GPUProcessor::*setPtr)(void *), int32_t type, const char* name, const GPUMemoryReuse& re);
275285
276286 // Private helper functions to dump / load flat objects
277287 template <class T >
@@ -292,17 +302,17 @@ class GPUReconstruction
292302 // Pointers to tracker classes
293303 GPUConstantMem* processors () { return mHostConstantMem .get (); }
294304 const GPUConstantMem* processors () const { return mHostConstantMem .get (); }
295- GPUParam& param () { return mHostConstantMem -> param ; }
305+ GPUParam& param ();
296306 std::unique_ptr<GPUConstantMem> mHostConstantMem ;
297307 GPUConstantMem* mDeviceConstantMem = nullptr ;
298308
299309 // Settings
300- GPUSettingsGRP mGRPSettings ; // Global Run Parameters
301- GPUSettingsDeviceBackend mDeviceBackendSettings ; // Processing Parameters (at constructor level)
302- GPUSettingsProcessing mProcessingSettings ; // Processing Parameters (at init level)
303- GPUOutputControl mOutputControl ; // Controls the output of the individual components
304- GPUOutputControl mInputControl ; // Prefefined input memory location for reading standalone dumps
305- std::unique_ptr<GPUMemorySizeScalers> mMemoryScalers ; // Scalers how much memory will be needed
310+ std::unique_ptr< GPUSettingsGRP> mGRPSettings ; // Global Run Parameters
311+ std::unique_ptr< GPUSettingsDeviceBackend> mDeviceBackendSettings ; // Processing Parameters (at constructor level)
312+ std::unique_ptr< GPUSettingsProcessing> mProcessingSettings ; // Processing Parameters (at init level)
313+ GPUOutputControl mOutputControl ; // Controls the output of the individual components
314+ GPUOutputControl mInputControl ; // Prefefined input memory location for reading standalone dumps
315+ std::unique_ptr<GPUMemorySizeScalers> mMemoryScalers ; // Scalers how much memory will be needed
306316
307317 GPURecoStepConfiguration mRecoSteps ;
308318
@@ -392,35 +402,6 @@ class GPUReconstruction
392402 static GPUReconstruction* GPUReconstruction_Create_CPU (const GPUSettingsDeviceBackend& cfg);
393403};
394404
395- template <class T >
396- inline T* GPUReconstruction::AllocateIOMemoryHelper (size_t n, const T*& ptr, std::unique_ptr<T[]>& u)
397- {
398- if (n == 0 ) {
399- u.reset (nullptr );
400- return nullptr ;
401- }
402- T* retVal;
403- if (mInputControl .useExternal ()) {
404- u.reset (nullptr );
405- mInputControl .checkCurrent ();
406- GPUProcessor::computePointerWithAlignment (mInputControl .ptrCurrent , retVal, n);
407- if ((size_t )((char *)mInputControl .ptrCurrent - (char *)mInputControl .ptrBase ) > mInputControl .size ) {
408- throw std::bad_alloc ();
409- }
410- } else {
411- u.reset (new T[n]);
412- retVal = u.get ();
413- if (mProcessingSettings .registerStandaloneInputMemory ) {
414- if (registerMemoryForGPU (u.get (), n * sizeof (T))) {
415- GPUError (" Error registering memory for GPU: %p - %ld bytes\n " , (void *)u.get (), (int64_t )(n * sizeof (T)));
416- throw std::bad_alloc ();
417- }
418- }
419- }
420- ptr = retVal;
421- return retVal;
422- }
423-
424405template <class T , typename ... Args>
425406inline T* GPUReconstruction::AddChain (Args... args)
426407{
@@ -431,31 +412,7 @@ inline T* GPUReconstruction::AddChain(Args... args)
431412template <class T >
432413inline int16_t GPUReconstruction::RegisterMemoryAllocation (T* proc, void * (T::*setPtr)(void *), int32_t type, const char* name, const GPUMemoryReuse& re)
433414{
434- if (!(type & (GPUMemoryResource::MEMORY_HOST | GPUMemoryResource::MEMORY_GPU))) {
435- if ((type & GPUMemoryResource::MEMORY_SCRATCH) && !mProcessingSettings .keepDisplayMemory ) { // keepAllMemory --> keepDisplayMemory
436- type |= (proc->mGPUProcessorType == GPUProcessor::PROCESSOR_TYPE_CPU ? GPUMemoryResource::MEMORY_HOST : GPUMemoryResource::MEMORY_GPU);
437- } else {
438- type |= GPUMemoryResource::MEMORY_HOST | GPUMemoryResource::MEMORY_GPU;
439- }
440- }
441- if (proc->mGPUProcessorType == GPUProcessor::PROCESSOR_TYPE_CPU) {
442- type &= ~GPUMemoryResource::MEMORY_GPU;
443- }
444- mMemoryResources .emplace_back (proc, static_cast <void * (GPUProcessor::*)(void *)>(setPtr), (GPUMemoryResource::MemoryType)type, name);
445- if (mMemoryResources .size () >= 32768 ) {
446- throw std::bad_alloc ();
447- }
448- uint16_t retVal = mMemoryResources .size () - 1 ;
449- if (re.type != GPUMemoryReuse::NONE && !mProcessingSettings .disableMemoryReuse ) {
450- const auto & it = mMemoryReuse1to1 .find (re.id );
451- if (it == mMemoryReuse1to1 .end ()) {
452- mMemoryReuse1to1 [re.id ] = {proc, retVal};
453- } else {
454- mMemoryResources [retVal].mReuse = it->second .res [0 ];
455- it->second .res .emplace_back (retVal);
456- }
457- }
458- return retVal;
415+ return RegisterMemoryAllocationHelper (proc, static_cast <void * (GPUProcessor::*)(void *)>(setPtr), type, name, re);
459416}
460417
461418template <class T >
@@ -471,7 +428,7 @@ inline void GPUReconstruction::SetupGPUProcessor(T* proc, bool allocate)
471428{
472429 static_assert (sizeof (T) > sizeof (GPUProcessor), " Need to setup derived class" );
473430 if (allocate) {
474- proc->SetMaxData (mHostConstantMem -> ioPtrs );
431+ proc->SetMaxData (GetIOPtrs () );
475432 }
476433 if (proc->mGPUProcessorType != GPUProcessor::PROCESSOR_TYPE_DEVICE && proc->mLinkedProcessor ) {
477434 std::memcpy ((void *)proc->mLinkedProcessor , (const void *)proc, sizeof (*proc));
0 commit comments