Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CUDADAtaFormats_HGCal_HGCRecHitCPUProduct_H
0002 #define CUDADAtaFormats_HGCal_HGCRecHitCPUProduct_H
0003 
0004 #include <cassert>
0005 #include <numeric>
0006 
0007 #include "HeterogeneousCore/CUDAUtilities/interface/host_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 HGCRecHitCPUProduct {
0013 public:
0014   HGCRecHitCPUProduct() = default;
0015   explicit HGCRecHitCPUProduct(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_host_unique<std::byte[]>(pad_ * size_tot_, stream);
0019   }
0020   ~HGCRecHitCPUProduct() = default;
0021 
0022   HGCRecHitCPUProduct(const HGCRecHitCPUProduct &) = delete;
0023   HGCRecHitCPUProduct &operator=(const HGCRecHitCPUProduct &) = delete;
0024   HGCRecHitCPUProduct(HGCRecHitCPUProduct &&) = default;
0025   HGCRecHitCPUProduct &operator=(HGCRecHitCPUProduct &&) = 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   uint32_t nHits() const { return nhits_; }
0051   uint32_t pad() const { return pad_; }
0052   uint32_t nBytes() const { return size_tot_; }
0053 
0054 private:
0055   cms::cuda::host::unique_ptr<std::byte[]> mem_;
0056   static constexpr std::array<int, memory::npointers::ntypes_hgcrechits_soa> sizes_ = {
0057       {memory::npointers::float_hgcrechits_soa * sizeof(float),
0058        memory::npointers::uint32_hgcrechits_soa * sizeof(uint32_t),
0059        memory::npointers::uint8_hgcrechits_soa * sizeof(uint8_t)}};
0060   uint32_t pad_;
0061   uint32_t nhits_;
0062   uint32_t size_tot_;
0063 };
0064 
0065 #endif  //CUDADAtaFormats_HGCal_HGCRecHitCPUProduct_H