Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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