Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:00:10

0001 #ifndef RecoLocalCalo_HGCRecProducers_HeterogeneousHGCalHEFConditions_h
0002 #define RecoLocalCalo_HGCRecProducers_HeterogeneousHGCalHEFConditions_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 cpar = hgcal_conditions::parameters;
0016 
0017 // Declare the wrapper ESProduct. The corresponding ESProducer should
0018 // produce objects of this type.
0019 class HeterogeneousHGCalHEFConditionsWrapper {
0020 public:
0021   // Constructor takes the standard CPU ESProduct, and transforms the
0022   // necessary data to array(s) in pinned host memory
0023   HeterogeneousHGCalHEFConditionsWrapper(const HGCalParameters *);
0024 
0025   // Deallocates all pinned host memory
0026   ~HeterogeneousHGCalHEFConditionsWrapper();
0027 
0028   // Function to return the actual payload on the memory of the current device
0029   hgcal_conditions::HeterogeneousHEFConditionsESProduct 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   cpar::HeterogeneousHGCalHEFParameters params_;
0036 
0037   std::vector<size_t> sizes_params_;
0038   size_t chunk_params_;
0039 
0040   std::vector<size_t> calculate_memory_bytes_params_(const HGCalParameters *);
0041   size_t allocate_memory_params_(const std::vector<size_t> &);
0042   void transfer_data_to_heterogeneous_pointers_params_(const std::vector<size_t> &, const HGCalParameters *);
0043 
0044   /*methods for managing SoA's pointers*/
0045   //double
0046   double *&select_pointer_d_(cpar::HeterogeneousHGCalHEFParameters *, const unsigned int &) const;
0047   std::vector<double> select_pointer_d_(const HGCalParameters *, const unsigned int &) const;
0048   //int32_t
0049   int32_t *&select_pointer_i_(cpar::HeterogeneousHGCalHEFParameters *, const unsigned int &) const;
0050   std::vector<int32_t> select_pointer_i_(const HGCalParameters *, const unsigned int &) const;
0051 
0052   // Helper struct to hold all information that has to be allocated and
0053   // deallocated per device
0054   struct GPUData {
0055     // Destructor should free all member pointers
0056     ~GPUData();
0057     // internal pointers are on device, struct itself is on CPU
0058     hgcal_conditions::HeterogeneousHEFConditionsESProduct *host = nullptr;
0059     // internal pounters and struct are on device
0060     hgcal_conditions::HeterogeneousHEFConditionsESProduct *device = nullptr;
0061   };
0062 
0063   // Helper that takes care of complexity of transferring the data to
0064   // multiple devices
0065   cms::cuda::ESProduct<GPUData> gpuData_;
0066 };
0067 
0068 #endif  //RecoLocalCalo_HGCRecProducers_HeterogeneousHGCalHEFConditions_h