CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TrackingRecHit2DHeterogeneous.h
Go to the documentation of this file.
1 #ifndef CUDADataFormats_TrackingRecHit_interface_TrackingRecHit2DHeterogeneous_h
2 #define CUDADataFormats_TrackingRecHit_interface_TrackingRecHit2DHeterogeneous_h
3 
7 
8 template <typename Traits>
10 public:
11  template <typename T>
13 
15 
17 
19  uint32_t nHits,
20  bool isPhase2,
21  int32_t offsetBPIX2,
22  pixelCPEforGPU::ParamsOnGPU const* cpeParams,
23  uint32_t const* hitsModuleStart,
24  cudaStream_t stream,
26 
28 
33 
34  TrackingRecHit2DSOAView* view() { return m_view.get(); }
35  TrackingRecHit2DSOAView const* view() const { return m_view.get(); }
36 
37  auto nHits() const { return m_nHits; }
38  auto nMaxModules() const { return m_nMaxModules; }
39  auto offsetBPIX2() const { return m_offsetBPIX2; }
40 
41  auto hitsModuleStart() const { return m_hitsModuleStart; }
42  auto hitsLayerStart() { return m_hitsLayerStart; }
43  auto phiBinner() { return m_phiBinner; }
45  auto iphi() { return m_iphi; }
46 
47  // only the local coord and detector index
50 
51  // needs specialization for Host
53 
54 private:
55  static constexpr uint32_t n16 = 4; // number of elements in m_store16
56  static constexpr uint32_t n32 = 10; // number of elements in m_store32
57  static_assert(sizeof(uint32_t) == sizeof(float)); // just stating the obvious
58 
61 
64 
66 
67  uint32_t m_nHits;
68  int32_t m_offsetBPIX2;
69 
70  uint32_t const* m_hitsModuleStart; // needed for legacy, this is on GPU!
71 
72  uint32_t m_nMaxModules;
73  // needed as kernel params...
76  uint32_t* m_hitsLayerStart;
77  int16_t* m_iphi;
78 };
79 
83 
86 
87 template <typename Traits>
89  uint32_t nHits,
90  bool isPhase2,
91  int32_t offsetBPIX2,
92  pixelCPEforGPU::ParamsOnGPU const* cpeParams,
93  uint32_t const* hitsModuleStart,
94  cudaStream_t stream,
96  : m_nHits(nHits), m_offsetBPIX2(offsetBPIX2), m_hitsModuleStart(hitsModuleStart) {
97  auto view = Traits::template make_host_unique<TrackingRecHit2DSOAView>(stream);
98 
100 
101  view->m_nHits = nHits;
103  m_view = Traits::template make_unique<TrackingRecHit2DSOAView>(stream); // leave it on host and pass it by value?
104  m_AverageGeometryStore = Traits::template make_unique<TrackingRecHit2DSOAView::AverageGeometry>(stream);
105  view->m_averageGeometry = m_AverageGeometryStore.get();
106  view->m_cpeParams = cpeParams;
108 
109  // if empy do not bother
110  if (0 == nHits) {
112  cms::cuda::copyAsync(m_view, view, stream);
113  } else {
114  m_view.reset(view.release()); // NOLINT: std::move() breaks CUDA version
115  }
116  return;
117  }
118 
119  // the single arrays are not 128 bit alligned...
120  // the hits are actually accessed in order only in building
121  // if ordering is relevant they may have to be stored phi-ordered by layer or so
122  // this will break 1to1 correspondence with cluster and module locality
123  // so unless proven VERY inefficient we keep it ordered as generated
124 
125  // host copy is "reduced" (to be reviewed at some point)
127  // it has to compile for ALL cases
128  copyFromGPU(input, stream);
129  } else {
130  assert(input == nullptr);
131 
133 
134  m_store16 = Traits::template make_unique<uint16_t[]>(nHits * n16, stream);
135  m_store32 = Traits::template make_unique<float[]>(nHits * n32 + nL + 1, stream);
136  m_PhiBinnerStore = Traits::template make_unique<TrackingRecHit2DSOAView::PhiBinner>(stream);
137  }
138 
139  static_assert(sizeof(TrackingRecHit2DSOAView::hindex_type) == sizeof(float));
141 
142  auto get32 = [&](int i) { return m_store32.get() + i * nHits; };
143 
144  // copy all the pointers
147  reinterpret_cast<TrackingRecHit2DSOAView::PhiBinner::index_type*>(get32(9));
148 
149  view->m_xl = get32(0);
150  view->m_yl = get32(1);
151  view->m_xerr = get32(2);
152  view->m_yerr = get32(3);
153  view->m_chargeAndStatus = reinterpret_cast<uint32_t*>(get32(4));
154 
156  assert(input == nullptr);
157  view->m_xg = get32(5);
158  view->m_yg = get32(6);
159  view->m_zg = get32(7);
160  view->m_rg = get32(8);
161 
162  auto get16 = [&](int i) { return m_store16.get() + i * nHits; };
163  m_iphi = view->m_iphi = reinterpret_cast<int16_t*>(get16(1));
164 
165  view->m_xsize = reinterpret_cast<int16_t*>(get16(2));
166  view->m_ysize = reinterpret_cast<int16_t*>(get16(3));
167  view->m_detInd = get16(0);
168 
170  m_hitsLayerStart = view->m_hitsLayerStart = reinterpret_cast<uint32_t*>(get32(n32));
171  }
172 
173  // transfer view
175  cms::cuda::copyAsync(m_view, view, stream);
176  } else {
177  m_view.reset(view.release()); // NOLINT: std::move() breaks CUDA version
178  }
179 }
180 
181 #endif // CUDADataFormats_TrackingRecHit_interface_TrackingRecHit2DHeterogeneous_h
cms::cuda::host::unique_ptr< float[]> localCoordToHostAsync(cudaStream_t stream) const
constexpr uint32_t numberOfLayers
void copyFromGPU(TrackingRecHit2DHeterogeneous< cms::cudacompat::GPUTraits > const *input, cudaStream_t stream)
unique_ptr< TrackingRecHit2DSOAView > m_view
constexpr uint32_t numberOfModules
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
assert(be >=bs)
cms::cuda::host::unique_ptr< uint32_t[]> hitsModuleStartToHostAsync(cudaStream_t stream) const
static std::string const input
Definition: EdmProvDump.cc:47
typename Traits::template unique_ptr< T > unique_ptr
typename Base::index_type index_type
cms::cuda::HistoContainer< int16_t, 256,-1, 8 *sizeof(int16_t), hindex_type, pixelTopology::maxLayers > PhiBinner
unique_ptr< TrackingRecHit2DSOAView::AverageGeometry > m_AverageGeometryStore
void copyAsync(device::unique_ptr< T > &dst, const host::unique_ptr< T > &src, cudaStream_t stream)
Definition: copyAsync.h:20
PhiBinner::index_type * m_phiBinnerStorage
TrackingRecHit2DHeterogeneous & operator=(const TrackingRecHit2DHeterogeneous &)=delete
TrackingRecHit2DSOAView const * view() const
constexpr uint32_t numberOfModules
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t nHits
constexpr uint8_t numberOfLayers
std::unique_ptr< T, impl::HostDeleter > unique_ptr
pixelCPEforGPU::ParamsOnGPU const * m_cpeParams
def template
Definition: svgfig.py:521
unique_ptr< TrackingRecHit2DSOAView::PhiBinner > m_PhiBinnerStore