CMS 3D CMS Logo

PixelRecHitKernels.dev.cc
Go to the documentation of this file.
1 // C++ headers
2 #include <cassert>
3 #include <cstdint>
4 #include <type_traits>
5 
6 // Alpaka headers
7 #include <alpaka/alpaka.hpp>
8 
9 // CMSSW headers
20 
21 // local headers
22 #include "PixelRecHitKernel.h"
23 #include "PixelRecHits.h"
24 
25 //#define GPU_DEBUG
26 
28  using namespace cms::alpakatools;
29  template <typename TrackerTraits>
31  public:
32  template <typename TAcc, typename = std::enable_if_t<alpaka::isAccelerator<TAcc>>>
33  ALPAKA_FN_ACC void operator()(TAcc const& acc,
34  uint32_t const* __restrict__ hitsModuleStart,
35  pixelCPEforDevice::ParamsOnDeviceT<TrackerTraits> const* __restrict__ cpeParams,
36  uint32_t* __restrict__ hitsLayerStart) const {
37  ALPAKA_ASSERT_ACC(0 == hitsModuleStart[0]);
38 
40  hitsLayerStart[i] = hitsModuleStart[cpeParams->layerGeometry().layerStart[i]];
41 #ifdef GPU_DEBUG
42  int old = i == 0 ? 0 : hitsModuleStart[cpeParams->layerGeometry().layerStart[i - 1]];
43  printf("LayerStart %d/%d at module %d: %d - %d\n",
44  i,
46  cpeParams->layerGeometry().layerStart[i],
47  hitsLayerStart[i],
48  hitsLayerStart[i] - old);
49 #endif
50  }
51  }
52  };
53 
54  namespace pixelgpudetails {
55 
56  template <typename TrackerTraits>
58  SiPixelDigisSoACollection const& digis_d,
59  SiPixelClustersSoACollection const& clusters_d,
60  BeamSpotPOD const* bs_d,
62  Queue queue) const {
63  using namespace pixelRecHits;
64  auto nHits = clusters_d.nClusters();
65  auto offsetBPIX2 = clusters_d.offsetBPIX2();
66 
67  TrackingRecHitsSoACollection<TrackerTraits> hits_d(queue, nHits, offsetBPIX2, clusters_d->clusModuleStart());
68 
69  int activeModulesWithDigis = digis_d.nModules();
70 
71  // protect from empty events
72  if (activeModulesWithDigis) {
73  int threadsPerBlock = 128;
74  // note: the kernel should work with an arbitrary number of blocks
75  int blocks = activeModulesWithDigis;
76  const auto workDiv1D = cms::alpakatools::make_workdiv<Acc1D>(blocks, threadsPerBlock);
77 
78 #ifdef GPU_DEBUG
79  std::cout << "launching GetHits kernel on " << alpaka::core::demangled<Acc1D> << " with " << blocks << " blocks"
80  << std::endl;
81 #endif
82  alpaka::exec<Acc1D>(queue,
83  workDiv1D,
84  GetHits<TrackerTraits>{},
85  cpeParams,
86  bs_d,
87  digis_d.view(),
88  digis_d.nDigis(),
89  digis_d.nModules(),
90  clusters_d.view(),
91  hits_d.view());
92 #ifdef GPU_DEBUG
94 #endif
95 
96  // assuming full warp of threads is better than a smaller number...
97  if (nHits) {
98  const auto workDiv1D = cms::alpakatools::make_workdiv<Acc1D>(1, 32);
99  alpaka::exec<Acc1D>(queue,
100  workDiv1D,
102  clusters_d->clusModuleStart(),
103  cpeParams,
104  hits_d.view().hitsLayerStart().data());
106 
107  // Use a view since it's runtime sized and can't use the implicit definition
108  // see HeterogeneousCore/AlpakaInterface/interface/OneToManyAssoc.h:100
110  hrv_d.assoc = &(hits_d.view().phiBinner());
111  hrv_d.offSize = -1;
112  hrv_d.offStorage = nullptr;
113  hrv_d.contentSize = nHits;
114  hrv_d.contentStorage = hits_d.view().phiBinnerStorage();
115 
116  cms::alpakatools::fillManyFromVector<Acc1D>(&(hits_d.view().phiBinner()),
117  hrv_d,
118  nLayers,
119  hits_d.view().iphi(),
120  hits_d.view().hitsLayerStart().data(),
121  nHits,
122  (uint32_t)256,
123  queue);
124 
125 #ifdef GPU_DEBUG
127 #endif
128  }
129  }
130 
131 #ifdef GPU_DEBUG
133  std::cout << "PixelRecHitKernel -> DONE!" << std::endl;
134 #endif
135 
136  return hits_d;
137  }
138 
142 
143  } // namespace pixelgpudetails
144 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
ALPAKA_FN_ACC void operator()(TAcc const &acc, uint32_t const *__restrict__ hitsModuleStart, pixelCPEforDevice::ParamsOnDeviceT< TrackerTraits > const *__restrict__ cpeParams, uint32_t *__restrict__ hitsLayerStart) const
ALPAKA_FN_ACC auto uniform_elements(TAcc const &acc, TArgs... args)
Definition: workdivision.h:311
typename PhiBinner::View PhiBinnerView
constexpr uint32_t numberOfLayers
std::conditional_t< std::is_same_v< Device, alpaka::DevCpu >, SiPixelDigisHost, SiPixelDigisDevice< Device > > SiPixelDigisSoACollection
constexpr LayerGeometry const &__restrict__ layerGeometry() const
std::conditional_t< std::is_same_v< Device, alpaka::DevCpu >, TrackingRecHitHost< TrackerTraits >, TrackingRecHitDevice< TrackerTraits, Device > > TrackingRecHitsSoACollection
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
std::conditional_t< std::is_same_v< Device, alpaka::DevCpu >, SiPixelClustersHost, SiPixelClustersDevice< Device > > SiPixelClustersSoACollection