CMS 3D CMS Logo

HGCRecHitGPUProduct.h
Go to the documentation of this file.
1 #ifndef CUDADAtaFormats_HGCal_HGCRecHitGPUProduct_H
2 #define CUDADAtaFormats_HGCal_HGCRecHitGPUProduct_H
3 
4 #include <cassert>
5 #include <numeric>
6 
11 
13 public:
14  HGCRecHitGPUProduct() = default;
15  explicit HGCRecHitGPUProduct(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_device_unique<std::byte[]>(pad_ * size_tot_, stream);
19  }
20  ~HGCRecHitGPUProduct() = default;
21 
22  HGCRecHitGPUProduct(const HGCRecHitGPUProduct &) = 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 
51  //number of hits stored in the SoA
52  uint32_t nHits() const { return nhits_; }
53  //pad of memory block (used for warp alignment, slighlty larger than 'nhits_')
54  uint32_t pad() const { return pad_; }
55  //number of bytes of the SoA
56  uint32_t nBytes() const { return size_tot_; }
57 
58 private:
60  static constexpr std::array<int, memory::npointers::ntypes_hgcrechits_soa> sizes_ = {
63  memory::npointers::uint8_hgcrechits_soa * sizeof(uint8_t)}};
64  uint32_t pad_;
65  uint32_t nhits_;
66  uint32_t size_tot_;
67 };
68 
69 #endif //CUDADAtaFormats_HGCal_HGCRecHitGPUProduct_H
constexpr unsigned uint8_hgcrechits_soa
Definition: HGCRecHitSoA.h:24
HGCRecHitGPUProduct()=default
uint32_t pad() const
uint32_t nHits() const
uint32_t nBytes() const
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
static constexpr std::array< int, memory::npointers::ntypes_hgcrechits_soa > sizes_
ZVertexSoA * soa
cms::cuda::device::unique_ptr< std::byte[]> mem_
~HGCRecHitGPUProduct()=default
constexpr unsigned float_hgcrechits_soa
Definition: HGCRecHitSoA.h:22
constexpr unsigned uint32_hgcrechits_soa
Definition: HGCRecHitSoA.h:23
HGCRecHitGPUProduct & operator=(const HGCRecHitGPUProduct &)=delete
HGCRecHitGPUProduct(uint32_t nhits, const cudaStream_t &stream)