Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:54

0001 #ifndef HeterogeneousHGCalHEBConditions_h
0002 #define HeterogeneousHGCalHEBConditions_h
0003 
0004 #include <numeric>  //accumulate
0005 #include <typeinfo>
0006 
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "HeterogeneousCore/CUDACore/interface/ESProduct.h"
0009 #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
0010 #include "CUDADataFormats/HGCal/interface/HGCConditions.h"
0011 #include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
0012 #include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
0013 #include "RecoLocalCalo/HGCalRecProducers/plugins/KernelManagerHGCalRecHit.h"
0014 
0015 namespace cp = hgcal_conditions::parameters;
0016 
0017 // Declare the wrapper ESProduct. The corresponding ESProducer should
0018 // produce objects of this type.
0019 class HeterogeneousHGCalHEBConditionsWrapper {
0020 public:
0021   // Constructor takes the standard CPU ESProduct, and transforms the
0022   // necessary data to array(s) in pinned host memory
0023   HeterogeneousHGCalHEBConditionsWrapper(const HGCalParameters *);
0024 
0025   // Deallocates all pinned host memory
0026   ~HeterogeneousHGCalHEBConditionsWrapper();
0027 
0028   // Function to return the actual payload on the memory of the current device
0029   hgcal_conditions::HeterogeneousHEBConditionsESProduct const *getHeterogeneousConditionsESProductAsync(
0030       cudaStream_t stream) const;
0031 
0032 private:
0033   // Holds the data in pinned CPU memory
0034   // Contrary to its non-heterogeneous counterpart (constructor argument) it is *not* a pointer (so to avoid an extra allocation)
0035   cp::HeterogeneousHGCalHEBParameters params_;
0036 
0037   std::vector<size_t> sizes_;
0038   size_t chunk_;
0039 
0040   void calculate_memory_bytes(const HGCalParameters *);
0041   double *&select_pointer_d(cp::HeterogeneousHGCalHEBParameters *, const unsigned int &) const;
0042   std::vector<double> select_pointer_d(const HGCalParameters *, const unsigned int &) const;
0043   int32_t *&select_pointer_i(cp::HeterogeneousHGCalHEBParameters *, const unsigned int &) const;
0044   std::vector<int32_t> select_pointer_i(const HGCalParameters *, const unsigned int &) const;
0045 
0046   // Helper struct to hold all information that has to be allocated and
0047   // deallocated per device
0048   struct GPUData {
0049     // Destructor should free all member pointers
0050     ~GPUData();
0051     // internal pointers are on device, struct itself is on CPU
0052     hgcal_conditions::HeterogeneousHEBConditionsESProduct *host = nullptr;
0053     // internal pounters and struct are on device
0054     hgcal_conditions::HeterogeneousHEBConditionsESProduct *device = nullptr;
0055   };
0056 
0057   // Helper that takes care of complexity of transferring the data to
0058   // multiple devices
0059   cms::cuda::ESProduct<GPUData> gpuData_;
0060 };
0061 
0062 #endif  //HeterogeneousHGCalHEBConditions_h