Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-30 08:50:30

0001 #ifndef CUDADAtaFormats_HGCal_HGCRecHitGPUProduct_H
0002 #define CUDADAtaFormats_HGCal_HGCRecHitGPUProduct_H
0003 
0004 #include <cassert>
0005 #include <numeric>
0006 
0007 #include "HeterogeneousCore/CUDAUtilities/interface/device_unique_ptr.h"
0008 #include "CUDADataFormats/HGCal/interface/HGCRecHitSoA.h"
0009 #include "CUDADataFormats/HGCal/interface/ConstHGCRecHitSoA.h"
0010 #include "CUDADataFormats/HGCal/interface/HGCUncalibRecHitSoA.h"
0011 
0012 class HGCRecHitGPUProduct {
0013 public:
0014   HGCRecHitGPUProduct() = default;
0015   explicit HGCRecHitGPUProduct(uint32_t nhits, const cudaStream_t &stream) : nhits_(nhits) {
0016     size_tot_ = std::accumulate(sizes_.begin(), sizes_.end(), 0);  //this might be done at compile time
0017     pad_ = ((nhits - 1) / 32 + 1) * 32;                            //align to warp boundary (assumption: warpSize = 32)
0018     mem_ = cms::cuda::make_device_unique<std::byte[]>(pad_ * size_tot_, stream);
0019   }
0020   ~HGCRecHitGPUProduct() = default;
0021 
0022   HGCRecHitGPUProduct(const HGCRecHitGPUProduct &) = delete;
0023   HGCRecHitGPUProduct &operator=(const HGCRecHitGPUProduct &) = delete;
0024   HGCRecHitGPUProduct(HGCRecHitGPUProduct &&) = default;
0025   HGCRecHitGPUProduct &operator=(HGCRecHitGPUProduct &&) = default;
0026 
0027   HGCRecHitSoA get() {
0028     HGCRecHitSoA soa;
0029     soa.energy_ = reinterpret_cast<float *>(mem_.get());
0030     soa.time_ = soa.energy_ + pad_;
0031     soa.timeError_ = soa.time_ + pad_;
0032     soa.id_ = reinterpret_cast<uint32_t *>(soa.timeError_ + pad_);
0033     soa.flagBits_ = soa.id_ + pad_;
0034     soa.son_ = reinterpret_cast<uint8_t *>(soa.flagBits_ + pad_);
0035     soa.nbytes_ = size_tot_;
0036     soa.nhits_ = nhits_;
0037     soa.pad_ = pad_;
0038     return soa;
0039   }
0040   ConstHGCRecHitSoA get() const {
0041     ConstHGCRecHitSoA soa;
0042     soa.energy_ = reinterpret_cast<float const *>(mem_.get());
0043     soa.time_ = soa.energy_ + pad_;
0044     soa.timeError_ = soa.time_ + pad_;
0045     soa.id_ = reinterpret_cast<uint32_t const *>(soa.timeError_ + pad_);
0046     soa.flagBits_ = soa.id_ + pad_;
0047     soa.son_ = reinterpret_cast<uint8_t const *>(soa.flagBits_ + pad_);
0048     return soa;
0049   }
0050 
0051   //number of hits stored in the SoA
0052   uint32_t nHits() const { return nhits_; }
0053   //pad of memory block (used for warp alignment, slighlty larger than 'nhits_')
0054   uint32_t pad() const { return pad_; }
0055   //number of bytes of the SoA
0056   uint32_t nBytes() const { return size_tot_; }
0057 
0058 private:
0059   cms::cuda::device::unique_ptr<std::byte[]> mem_;
0060   static constexpr std::array<int, memory::npointers::ntypes_hgcrechits_soa> sizes_ = {
0061       {memory::npointers::float_hgcrechits_soa * sizeof(float),
0062        memory::npointers::uint32_hgcrechits_soa * sizeof(uint32_t),
0063        memory::npointers::uint8_hgcrechits_soa * sizeof(uint8_t)}};
0064   uint32_t pad_;
0065   uint32_t nhits_;
0066   uint32_t size_tot_;
0067 };
0068 
0069 #endif  //CUDADAtaFormats_HGCal_HGCRecHitGPUProduct_H