Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:45

0001 #ifndef CUDADAtaFormats_HGCal_HGCUncalibRecHitHost_H
0002 #define CUDADAtaFormats_HGCal_HGCUncalibRecHitHost_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/HGCUncalibRecHitSoA.h"
0010 
0011 template <class T>
0012 class HGCUncalibRecHitHost {
0013 public:
0014   HGCUncalibRecHitHost() = default;
0015   explicit HGCUncalibRecHitHost(uint32_t nhits, const T &hits, 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     ptr_ = cms::cuda::make_host_unique<std::byte[]>(pad_ * size_tot_, stream);
0019 
0020     defineSoAMemoryLayout_();
0021     fillSoA_(hits);
0022   }
0023   ~HGCUncalibRecHitHost() = default;
0024 
0025   HGCUncalibRecHitHost(const HGCUncalibRecHitHost &) = delete;
0026   HGCUncalibRecHitHost &operator=(const HGCUncalibRecHitHost &) = delete;
0027   HGCUncalibRecHitHost(HGCUncalibRecHitHost &&) = default;
0028   HGCUncalibRecHitHost &operator=(HGCUncalibRecHitHost &&) = default;
0029 
0030   void defineSoAMemoryLayout_() {
0031     soa_.amplitude_ = reinterpret_cast<float *>(ptr_.get());
0032     soa_.pedestal_ = soa_.amplitude_ + pad_;
0033     soa_.jitter_ = soa_.pedestal_ + pad_;
0034     soa_.chi2_ = soa_.jitter_ + pad_;
0035     soa_.OOTamplitude_ = soa_.chi2_ + pad_;
0036     soa_.OOTchi2_ = soa_.OOTamplitude_ + pad_;
0037     soa_.flags_ = reinterpret_cast<uint32_t *>(soa_.OOTchi2_ + pad_);
0038     soa_.aux_ = soa_.flags_ + pad_;
0039     soa_.id_ = soa_.aux_ + pad_;
0040     soa_.aux_ = soa_.flags_ + pad_;
0041     soa_.id_ = soa_.aux_ + pad_;
0042 
0043     soa_.nbytes_ = size_tot_;
0044     soa_.nhits_ = nhits_;
0045     soa_.pad_ = pad_;
0046   }
0047 
0048   void fillSoA_(const T &c) {
0049     for (unsigned i(0); i < nhits_; ++i) {
0050       soa_.amplitude_[i] = c[i].amplitude();
0051       soa_.pedestal_[i] = c[i].pedestal();
0052       soa_.jitter_[i] = c[i].jitter();
0053       soa_.chi2_[i] = c[i].chi2();
0054       soa_.OOTamplitude_[i] = c[i].outOfTimeEnergy();
0055       soa_.OOTchi2_[i] = c[i].outOfTimeChi2();
0056       soa_.flags_[i] = c[i].flags();
0057       soa_.aux_[i] = 0;
0058       soa_.id_[i] = c[i].id().rawId();
0059     }
0060   }
0061 
0062   HGCUncalibRecHitSoA get() const { return soa_; }
0063   uint32_t nHits() const { return nhits_; }
0064   uint32_t pad() const { return pad_; }
0065   uint32_t nBytes() const { return size_tot_; }
0066 
0067 private:
0068   cms::cuda::host::unique_ptr<std::byte[]> ptr_;
0069   HGCUncalibRecHitSoA soa_;
0070   static constexpr std::array<int, memory::npointers::ntypes_hgcuncalibrechits_soa> sizes_ = {
0071       {memory::npointers::float_hgcuncalibrechits_soa * sizeof(float),
0072        memory::npointers::uint32_hgcuncalibrechits_soa * sizeof(uint32_t)}};
0073   uint32_t size_tot_;
0074   uint32_t pad_;
0075   uint32_t nhits_;
0076 };
0077 
0078 #endif  //CUDADAtaFormats_HGCal_HGCUncalibRecHitHost_H