Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:37:10

0001 #ifndef CondFormats_HGCalObjects_HeterogeneousHGCalHEFConditions_h
0002 #define CondFormats_HGCalObjects_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 
0014 namespace cpar = hgcal_conditions::parameters;
0015 namespace cpos = hgcal_conditions::positions;
0016 
0017 // Declare the wrapper ESProduct. The corresponding ESProducer should
0018 // produce objects of this type.
0019 class HeterogeneousHGCalHEFCellPositionsConditions {
0020 public:
0021   // Constructor takes the standard CPU ESProduct, and transforms the
0022   // necessary data to array(s) in pinned host memory
0023   HeterogeneousHGCalHEFCellPositionsConditions(cpos::HGCalPositionsMapping*);
0024 
0025   // Deallocates all pinned host memory
0026   ~HeterogeneousHGCalHEFCellPositionsConditions();
0027 
0028   // Function to return the actual payload on the memory of the current device
0029   hgcal_conditions::HeterogeneousHEFCellPositionsConditionsESProduct 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   cpos::HeterogeneousHGCalPositionsMapping posmap_;
0036   size_t nelems_posmap_;
0037 
0038   std::vector<size_t> sizes_;
0039   size_t chunk_;
0040   const size_t number_position_arrays =
0041       2;  //x and y; required due to the assymetry between cpos::HeterogeneousHGCalPositionsMapping and cpos::HGCalPositionsMapping
0042 
0043   std::vector<size_t> calculate_memory_bytes_(cpos::HGCalPositionsMapping*);
0044   size_t allocate_memory_(const std::vector<size_t>&);
0045   void transfer_data_to_heterogeneous_pointers_(const std::vector<size_t>&, cpos::HGCalPositionsMapping*);
0046   void transfer_data_to_heterogeneous_vars_(const cpos::HGCalPositionsMapping*);
0047 
0048   /*methods for managing SoA's pointers*/
0049   //float
0050   float*& select_pointer_f_(cpos::HeterogeneousHGCalPositionsMapping*, const unsigned int&) const;
0051   std::vector<float>& select_pointer_f_(cpos::HGCalPositionsMapping*, const unsigned int&);
0052   //int32_t
0053   int32_t*& select_pointer_i_(cpos::HeterogeneousHGCalPositionsMapping*, const unsigned int&) const;
0054   std::vector<int32_t>& select_pointer_i_(cpos::HGCalPositionsMapping*, const unsigned int&);
0055   //uint32_t
0056   uint32_t*& select_pointer_u_(cpos::HeterogeneousHGCalPositionsMapping*, const unsigned int&) const;
0057   std::vector<uint32_t>& select_pointer_u_(cpos::HGCalPositionsMapping*, const unsigned int&);
0058 
0059   // Helper struct to hold all information that has to be allocated and
0060   // deallocated per device
0061   struct GPUData {
0062     // Destructor should free all member pointers
0063     ~GPUData();
0064     // internal pointers are on device, struct itself is on CPU
0065     hgcal_conditions::HeterogeneousHEFCellPositionsConditionsESProduct* host = nullptr;
0066     // internal pounters and struct are on device
0067     hgcal_conditions::HeterogeneousHEFCellPositionsConditionsESProduct* device = nullptr;
0068   };
0069 
0070   // Helper that takes care of complexity of transferring the data to
0071   // multiple devices
0072   cms::cuda::ESProduct<GPUData> gpuData_;
0073 };
0074 
0075 #endif  //CondFormats_HGCalObjects_HeterogeneousHGCalHEFConditions_h