CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
uint32_t * flagBits_
Definition: HGCRecHitSoA.h:12
HGCRecHitGPUProduct()=default
uint32_t * id_
Definition: HGCRecHitSoA.h:11
uint32_t nHits() const
uint32_t const * id_
uint8_t * son_
Definition: HGCRecHitSoA.h:13
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
float const * time_
static constexpr std::array< int, memory::npointers::ntypes_hgcrechits_soa > sizes_
float * energy_
Definition: HGCRecHitSoA.h:8
uint32_t pad_
Definition: HGCRecHitSoA.h:17
ZVertexSoA * soa
uint32_t nbytes_
Definition: HGCRecHitSoA.h:15
cms::cuda::device::unique_ptr< std::byte[]> mem_
uint32_t pad() const
~HGCRecHitGPUProduct()=default
uint32_t nBytes() const
float const * energy_
uint32_t const * flagBits_
constexpr unsigned float_hgcrechits_soa
Definition: HGCRecHitSoA.h:22
constexpr unsigned uint32_hgcrechits_soa
Definition: HGCRecHitSoA.h:23
float * time_
Definition: HGCRecHitSoA.h:9
float const * timeError_
HGCRecHitGPUProduct & operator=(const HGCRecHitGPUProduct &)=delete
uint8_t const * son_
float * timeError_
Definition: HGCRecHitSoA.h:10
HGCRecHitGPUProduct(uint32_t nhits, const cudaStream_t &stream)
uint32_t nhits_
Definition: HGCRecHitSoA.h:16