CMS 3D CMS Logo

HGCRecHitCPUProduct.h
Go to the documentation of this file.
1 #ifndef CUDADAtaFormats_HGCal_HGCRecHitCPUProduct_H
2 #define CUDADAtaFormats_HGCal_HGCRecHitCPUProduct_H
3 
4 #include <cassert>
5 #include <numeric>
6 
11 
13 public:
14  HGCRecHitCPUProduct() = default;
15  explicit HGCRecHitCPUProduct(uint32_t nhits, const cudaStream_t &stream) : nhits_(nhits) {
16  size_tot_ = std::accumulate(sizes_.begin(), sizes_.end(), 0); //this might be done at compile time
17  pad_ = ((nhits - 1) / 32 + 1) * 32; //align to warp boundary (assumption: warpSize = 32)
18  mem_ = cms::cuda::make_host_unique<std::byte[]>(pad_ * size_tot_, stream);
19  }
20  ~HGCRecHitCPUProduct() = default;
21 
22  HGCRecHitCPUProduct(const HGCRecHitCPUProduct &) = delete;
26 
27  HGCRecHitSoA get() {
29  soa.energy_ = reinterpret_cast<float *>(mem_.get());
30  soa.time_ = soa.energy_ + pad_;
31  soa.timeError_ = soa.time_ + pad_;
32  soa.id_ = reinterpret_cast<uint32_t *>(soa.timeError_ + pad_);
33  soa.flagBits_ = soa.id_ + pad_;
34  soa.son_ = reinterpret_cast<uint8_t *>(soa.flagBits_ + pad_);
35  soa.nbytes_ = size_tot_;
36  soa.nhits_ = nhits_;
37  soa.pad_ = pad_;
38  return soa;
39  }
40  ConstHGCRecHitSoA get() const {
42  soa.energy_ = reinterpret_cast<float const *>(mem_.get());
43  soa.time_ = soa.energy_ + pad_;
44  soa.timeError_ = soa.time_ + pad_;
45  soa.id_ = reinterpret_cast<uint32_t const *>(soa.timeError_ + pad_);
46  soa.flagBits_ = soa.id_ + pad_;
47  soa.son_ = reinterpret_cast<uint8_t const *>(soa.flagBits_ + pad_);
48  return soa;
49  }
50  uint32_t nHits() const { return nhits_; }
51  uint32_t pad() const { return pad_; }
52  uint32_t nBytes() const { return size_tot_; }
53 
54 private:
56  static constexpr std::array<int, memory::npointers::ntypes_hgcrechits_soa> sizes_ = {
59  memory::npointers::uint8_hgcrechits_soa * sizeof(uint8_t)}};
60  uint32_t pad_;
61  uint32_t nhits_;
62  uint32_t size_tot_;
63 };
64 
65 #endif //CUDADAtaFormats_HGCal_HGCRecHitCPUProduct_H
constexpr unsigned uint8_hgcrechits_soa
Definition: HGCRecHitSoA.h:24
static constexpr std::array< int, memory::npointers::ntypes_hgcrechits_soa > sizes_
~HGCRecHitCPUProduct()=default
HGCRecHitCPUProduct(uint32_t nhits, const cudaStream_t &stream)
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
uint32_t nBytes() const
ZVertexSoA * soa
uint32_t nHits() const
HGCRecHitCPUProduct()=default
uint32_t pad() const
cms::cuda::host::unique_ptr< std::byte[]> mem_
constexpr unsigned float_hgcrechits_soa
Definition: HGCRecHitSoA.h:22
constexpr unsigned uint32_hgcrechits_soa
Definition: HGCRecHitSoA.h:23
HGCRecHitCPUProduct & operator=(const HGCRecHitCPUProduct &)=delete
std::unique_ptr< T, impl::HostDeleter > unique_ptr