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 
6 
7 template <typename Traits>
9 public:
10  template <typename T>
12 
14 
16 
18  uint32_t nHits,
19  int32_t offsetBPIX2,
20  pixelCPEforGPU::ParamsOnGPU const* cpeParams,
21  uint32_t const* hitsModuleStart,
22  cudaStream_t stream,
24 
26 
31 
32  TrackingRecHit2DSOAView* view() { return m_view.get(); }
33  TrackingRecHit2DSOAView const* view() const { return m_view.get(); }
34 
35  auto nHits() const { return m_nHits; }
36  auto offsetBPIX2() const { return m_offsetBPIX2; }
37 
38  auto hitsModuleStart() const { return m_hitsModuleStart; }
39  auto hitsLayerStart() { return m_hitsLayerStart; }
40  auto phiBinner() { return m_phiBinner; }
42  auto iphi() { return m_iphi; }
43 
44  // only the local coord and detector index
47 
48  // needs specialization for Host
50 
51 private:
52  static constexpr uint32_t n16 = 4; // number of elements in m_store16
53  static constexpr uint32_t n32 = 10; // number of elements in m_store32
54  static_assert(sizeof(uint32_t) == sizeof(float)); // just stating the obvious
55 
58 
61 
63 
64  uint32_t m_nHits;
65  int32_t m_offsetBPIX2;
66 
67  uint32_t const* m_hitsModuleStart; // needed for legacy, this is on GPU!
68 
69  // needed as kernel params...
72  uint32_t* m_hitsLayerStart;
73  int16_t* m_iphi;
74 };
75 
79 
82 
83 template <typename Traits>
85  uint32_t nHits,
86  int32_t offsetBPIX2,
87  pixelCPEforGPU::ParamsOnGPU const* cpeParams,
88  uint32_t const* hitsModuleStart,
89  cudaStream_t stream,
91  : m_nHits(nHits), m_offsetBPIX2(offsetBPIX2), m_hitsModuleStart(hitsModuleStart) {
92  auto view = Traits::template make_host_unique<TrackingRecHit2DSOAView>(stream);
93 
94  view->m_nHits = nHits;
95  m_view = Traits::template make_unique<TrackingRecHit2DSOAView>(stream); // leave it on host and pass it by value?
96  m_AverageGeometryStore = Traits::template make_unique<TrackingRecHit2DSOAView::AverageGeometry>(stream);
97  view->m_averageGeometry = m_AverageGeometryStore.get();
98  view->m_cpeParams = cpeParams;
100 
101  // if empy do not bother
102  if (0 == nHits) {
104  cms::cuda::copyAsync(m_view, view, stream);
105  } else {
106  m_view.reset(view.release()); // NOLINT: std::move() breaks CUDA version
107  }
108  return;
109  }
110 
111  // the single arrays are not 128 bit alligned...
112  // the hits are actually accessed in order only in building
113  // if ordering is relevant they may have to be stored phi-ordered by layer or so
114  // this will break 1to1 correspondence with cluster and module locality
115  // so unless proven VERY inefficient we keep it ordered as generated
116 
117  // host copy is "reduced" (to be reviewed at some point)
119  // it has to compile for ALL cases
120  copyFromGPU(input, stream);
121  } else {
122  assert(input == nullptr);
123  m_store16 = Traits::template make_unique<uint16_t[]>(nHits * n16, stream);
124  m_store32 = Traits::template make_unique<float[]>(nHits * n32 + phase1PixelTopology::numberOfLayers + 1, stream);
125  m_PhiBinnerStore = Traits::template make_unique<TrackingRecHit2DSOAView::PhiBinner>(stream);
126  }
127 
128  static_assert(sizeof(TrackingRecHit2DSOAView::hindex_type) == sizeof(float));
130 
131  auto get32 = [&](int i) { return m_store32.get() + i * nHits; };
132 
133  // copy all the pointers
136  reinterpret_cast<TrackingRecHit2DSOAView::PhiBinner::index_type*>(get32(9));
137 
138  view->m_xl = get32(0);
139  view->m_yl = get32(1);
140  view->m_xerr = get32(2);
141  view->m_yerr = get32(3);
142  view->m_chargeAndStatus = reinterpret_cast<uint32_t*>(get32(4));
143 
145  assert(input == nullptr);
146  view->m_xg = get32(5);
147  view->m_yg = get32(6);
148  view->m_zg = get32(7);
149  view->m_rg = get32(8);
150 
151  auto get16 = [&](int i) { return m_store16.get() + i * nHits; };
152  m_iphi = view->m_iphi = reinterpret_cast<int16_t*>(get16(1));
153 
154  view->m_xsize = reinterpret_cast<int16_t*>(get16(2));
155  view->m_ysize = reinterpret_cast<int16_t*>(get16(3));
156  view->m_detInd = get16(0);
157 
159  m_hitsLayerStart = view->m_hitsLayerStart = reinterpret_cast<uint32_t*>(get32(n32));
160  }
161 
162  // transfer view
164  cms::cuda::copyAsync(m_view, view, stream);
165  } else {
166  m_view.reset(view.release()); // NOLINT: std::move() breaks CUDA version
167  }
168 }
169 
170 #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
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, 128,-1, 8 *sizeof(int16_t), hindex_type, 10 > 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
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
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