CMS 3D CMS Logo

CAHitNtupletGeneratorKernels.h
Go to the documentation of this file.
1 #ifndef RecoPixelVertexing_PixelTriplets_plugins_CAHitNtupletGeneratorKernels_h
2 #define RecoPixelVertexing_PixelTriplets_plugins_CAHitNtupletGeneratorKernels_h
3 
4 // #define GPU_DEBUG
5 
6 #include "GPUCACell.h"
7 #include "gpuPixelDoublets.h"
8 
14 
15 // #define DUMP_GPU_TK_TUPLES
16 
18 
19  //Configuration params common to all topologies, for the algorithms
20  struct AlgoParams {
21  const bool onGPU_;
22  const uint32_t minHitsForSharingCut_;
23  const bool useRiemannFit_;
24  const bool fitNas4_;
26  const bool earlyFishbone_;
27  const bool lateFishbone_;
28  const bool doStats_;
29  const bool doSharedHitCut_;
30  const bool dupPassThrough_;
32  };
33 
34  //CAParams
35  struct CACommon {
36  const uint32_t minHitsPerNtuplet_;
37  const float ptmin_;
38  const float CAThetaCutBarrel_;
39  const float CAThetaCutForward_;
40  const float hardCurvCut_;
41  const float dcaCutInnerTriplet_;
42  const float dcaCutOuterTriplet_;
43  };
44 
45  template <typename TrackerTraits, typename Enable = void>
46  struct CAParamsT : public CACommon {
47  __device__ __forceinline__ bool startingLayerPair(int16_t pid) const { return false; };
48  __device__ __forceinline__ bool startAt0(int16_t pid) const { return false; };
49  };
50 
51  template <typename TrackerTraits>
52  struct CAParamsT<TrackerTraits, pixelTopology::isPhase1Topology<TrackerTraits>> : public CACommon {
54  __device__ __forceinline__ bool startingLayerPair(int16_t pid) const {
55  return minHitsPerNtuplet_ > 3 ? pid < 3 : pid < 8 || pid > 12;
56  }
57 
59  __device__ __forceinline__ bool startAt0(int16_t pid) const {
60  assert((pixelTopology::Phase1::layerPairs[pid * 2] == 0) ==
61  (pid < 3 || pid == 13 || pid == 15 || pid == 16)); // to be 100% sure it's working, may be removed
62  return pixelTopology::Phase1::layerPairs[pid * 2] == 0;
63  }
64  };
65 
66  template <typename TrackerTraits>
67  struct CAParamsT<TrackerTraits, pixelTopology::isPhase2Topology<TrackerTraits>> : public CACommon {
68  const bool includeFarForwards_;
70  __device__ __forceinline__ bool startingLayerPair(int16_t pid) const {
71  return pid < 33; // in principle one could remove 5,6,7 23, 28 and 29
72  }
73 
75  __device__ __forceinline__ bool startAt0(int16_t pid) const {
76  assert((pixelTopology::Phase2::layerPairs[pid * 2] == 0) == ((pid < 3) | (pid >= 23 && pid < 28)));
77  return pixelTopology::Phase2::layerPairs[pid * 2] == 0;
78  }
79  };
80 
81  //Full list of params = algo params + ca params + cell params + quality cuts
82  //Generic template
83  template <typename TrackerTraits, typename Enable = void>
84  struct ParamsT : public AlgoParams {
85  // one should define the params for its own pixelTopology
86  // not defining anything here
87  inline uint32_t nPairs() const { return 0; }
88  };
89 
90  template <typename TrackerTraits>
91  struct ParamsT<TrackerTraits, pixelTopology::isPhase1Topology<TrackerTraits>> : public AlgoParams {
92  using TT = TrackerTraits;
93  using QualityCuts = pixelTrack::QualityCutsT<TT>; //track quality cuts
94  using CellCuts = gpuPixelDoublets::CellCutsT<TT>; //cell building cuts
95  using CAParams = CAParamsT<TT>; //params to be used on device
96 
97  ParamsT(AlgoParams const& commonCuts,
98  CellCuts const& cellCuts,
99  QualityCuts const& cutsCuts,
100  CAParams const& caParams)
101  : AlgoParams(commonCuts), cellCuts_(cellCuts), qualityCuts_(cutsCuts), caParams_(caParams) {}
102 
104  const QualityCuts qualityCuts_{// polynomial coefficients for the pT-dependent chi2 cut
105  {0.68177776, 0.74609577, -0.08035491, 0.00315399},
106  // max pT used to determine the chi2 cut
107  10.,
108  // chi2 scale factor: 30 for broken line fit, 45 for Riemann fit
109  30.,
110  // regional cuts for triplets
111  {
112  0.3, // |Tip| < 0.3 cm
113  0.5, // pT > 0.5 GeV
114  12.0 // |Zip| < 12.0 cm
115  },
116  // regional cuts for quadruplets
117  {
118  0.5, // |Tip| < 0.5 cm
119  0.3, // pT > 0.3 GeV
120  12.0 // |Zip| < 12.0 cm
121  }};
124  inline uint32_t nPairs() const {
125  // take all layer pairs into account
126  uint32_t nActualPairs = TT::nPairs;
128  // exclude forward "jumping" layer pairs
129  nActualPairs = TT::nPairsForTriplets;
130  }
131  if (caParams_.minHitsPerNtuplet_ > 3) {
132  // for quadruplets, exclude all "jumping" layer pairs
133  nActualPairs = TT::nPairsForQuadruplets;
134  }
135 
136  return nActualPairs;
137  }
138 
139  }; // Params Phase1
140 
141  template <typename TrackerTraits>
142  struct ParamsT<TrackerTraits, pixelTopology::isPhase2Topology<TrackerTraits>> : public AlgoParams {
143  using TT = TrackerTraits;
147 
148  ParamsT(AlgoParams const& commonCuts,
149  CellCuts const& cellCuts,
150  QualityCuts const& qualityCuts,
151  CAParams const& caParams)
152  : AlgoParams(commonCuts), cellCuts_(cellCuts), qualityCuts_(qualityCuts), caParams_(caParams) {}
153 
154  // quality cuts
156  const QualityCuts qualityCuts_{5.0f, /*chi2*/ 0.9f, /* pT in Gev*/ 0.4f, /*zip in cm*/ 12.0f /*tip in cm*/};
158 
159  inline uint32_t nPairs() const {
160  // take all layer pairs into account
161  uint32_t nActualPairs = TT::nPairsMinimal;
162  if (caParams_.includeFarForwards_) {
163  // considera far forwards (> 11 & > 23)
164  nActualPairs = TT::nPairsFarForwards;
165  }
167  // include jumping forwards
169  }
170 
171  return nActualPairs;
172  }
173 
174  }; // Params Phase1
175 
176  // counters
177  struct Counters {
178  unsigned long long nEvents;
179  unsigned long long nHits;
180  unsigned long long nCells;
181  unsigned long long nTuples;
182  unsigned long long nFitTracks;
183  unsigned long long nLooseTracks;
184  unsigned long long nGoodTracks;
185  unsigned long long nUsedHits;
186  unsigned long long nDupHits;
187  unsigned long long nFishCells;
188  unsigned long long nKilledCells;
189  unsigned long long nEmptyCells;
190  unsigned long long nZeroTrackCells;
191  };
192 
194 
195 } // namespace caHitNtupletGenerator
196 
197 template <typename TTraits, typename TTTraits>
199 public:
200  using Traits = TTraits;
201  using TrackerTraits = TTTraits;
206 
207  template <typename T>
209 
213 
222 
224 
227 
229  : params_(params), paramsMaxDoubletes3Quarters_(3 * params.cellCuts_.maxNumberOfDoublets_ / 4) {}
230 
231  ~CAHitNtupletGeneratorKernels() = default;
232 
234 
235  void launchKernels(const HitsConstView& hh, TkSoAView& track_view, cudaStream_t cudaStream);
236 
237  void classifyTuples(const HitsConstView& hh, TkSoAView& track_view, cudaStream_t cudaStream);
238 
239  void buildDoublets(const HitsConstView& hh, cudaStream_t stream);
240  void allocateOnGPU(int32_t nHits, cudaStream_t stream);
241  void cleanup(cudaStream_t cudaStream);
242 
243  static void printCounters(Counters const* counters);
245 
246 protected:
247  Counters* counters_ = nullptr;
248  // workspace
254 
258  uint32_t* device_nCells_ = nullptr;
259 
263 
265 
267 
269 
271 
272  // params
277  inline uint32_t nDoubletBlocks(uint32_t blockSize) {
278  // We want (3 * params_.maxNumberOfDoublets_ / 4 + blockSize - 1) / blockSize, but first part is pre-computed.
279  return (paramsMaxDoubletes3Quarters_ + blockSize - 1) / blockSize;
280  }
281 
283  inline uint32_t nQuadrupletBlocks(uint32_t blockSize) {
284  // pixelTopology::maxNumberOfQuadruplets is a constexpr, so the compiler will pre compute the 3*max/4
285  return (3 * TrackerTraits::maxNumberOfQuadruplets / 4 + blockSize - 1) / blockSize;
286  }
287 };
288 
289 template <typename TrackerTraits>
290 class CAHitNtupletGeneratorKernelsGPU : public CAHitNtupletGeneratorKernels<cms::cudacompat::GPUTraits, TrackerTraits> {
292 
295 
297 
302 
305 
306 public:
307  void launchKernels(const HitsConstView& hh, TkSoAView& track_view, cudaStream_t cudaStream);
308  void classifyTuples(const HitsConstView& hh, TkSoAView& track_view, cudaStream_t cudaStream);
309  void buildDoublets(const HitsConstView& hh, int32_t offsetBPIX2, cudaStream_t stream);
310  void allocateOnGPU(int32_t nHits, cudaStream_t stream);
311  static void printCounters(Counters const* counters);
312 };
313 
314 template <typename TrackerTraits>
315 class CAHitNtupletGeneratorKernelsCPU : public CAHitNtupletGeneratorKernels<cms::cudacompat::CPUTraits, TrackerTraits> {
317 
320 
322 
327 
330 
331 public:
332  void launchKernels(const HitsConstView& hh, TkSoAView& track_view, cudaStream_t cudaStream);
333  void classifyTuples(const HitsConstView& hh, TkSoAView& track_view, cudaStream_t cudaStream);
334  void buildDoublets(const HitsConstView& hh, int32_t offsetBPIX2, cudaStream_t stream);
335  void allocateOnGPU(int32_t nHits, cudaStream_t stream);
336  static void printCounters(Counters const* counters);
337 };
338 
339 #endif // RecoPixelVertexing_PixelTriplets_plugins_CAHitNtupletGeneratorKernels_h
void classifyTuples(const HitsConstView &hh, TkSoAView &track_view, cudaStream_t cudaStream)
CAHitNtupletGeneratorKernels(Params const &params)
TrackingRecHitSoAConstView< TrackerTraits > HitsConstView
static void printCounters(Counters const *counters)
#define __forceinline__
Definition: cudaCompat.h:22
unique_ptr< OuterHitOfCellContainer[]> device_isOuterHitOfCell_
void launchKernels(const HitsConstView &hh, TkSoAView &track_view, cudaStream_t cudaStream)
void classifyTuples(const HitsConstView &hh, TkSoAView &track_view, cudaStream_t cudaStream)
unique_ptr< CellTracksVector > device_theCellTracks_
typename std::enable_if< std::is_base_of< Phase2, T >::value >::type isPhase2Topology
caHitNtupletGenerator::Counters Counters
cms::cuda::AtomicPairCounter * device_hitToTuple_apc_
TrackSoAView< TrackerTraits > TkSoAView
const uint32_t paramsMaxDoubletes3Quarters_
Intermediate result avoiding repeated computations.
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
unique_ptr< HitToTuple > device_hitToTuple_
assert(be >=bs)
unique_ptr< uint32_t[]> device_hitToTupleStorage_
void classifyTuples(const HitsConstView &hh, TkSoAView &track_view, cudaStream_t cudaStream)
void allocateOnGPU(int32_t nHits, cudaStream_t stream)
ParamsT(AlgoParams const &commonCuts, CellCuts const &cellCuts, QualityCuts const &cutsCuts, CAParams const &caParams)
TupleMultiplicity< TrackerTraits > const HitToTuple< TrackerTraits > const cms::cuda::AtomicPairCounter GPUCACellT< TrackerTraits > const *__restrict__ uint32_t const *__restrict__ CellNeighborsVector< TrackerTraits > const CellTracksVector< TrackerTraits > const OuterHitOfCell< TrackerTraits > const int32_t uint32_t Counters * counters
static void printCounters(Counters const *counters)
unique_ptr< TupleMultiplicity > device_tupleMultiplicity_
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
void buildDoublets(const HitsConstView &hh, cudaStream_t stream)
typename std::enable_if< std::is_base_of< Phase1, T >::value >::type isPhase1Topology
TupleMultiplicity const * tupleMultiplicity() const
ParamsT(AlgoParams const &commonCuts, CellCuts const &cellCuts, QualityCuts const &qualityCuts, CAParams const &caParams)
uint32_t CellNeighborsVector< TrackerTraits > CellTracksVector< TrackerTraits > HitsConstView< TrackerTraits > OuterHitOfCell< TrackerTraits > int nActualPairs
typename TrackSoA< TrackerTraits >::HitContainer HitContainer
uint32_t nQuadrupletBlocks(uint32_t blockSize)
Compute the number of quadruplet blocks for block size.
void launchKernels(const HitsConstView &hh, TkSoAView &track_view, cudaStream_t cudaStream)
caHitNtupletGenerator::Counters Counters
unique_ptr< unsigned char[]> cellStorage_
uint32_t nDoubletBlocks(uint32_t blockSize)
Compute the number of doublet blocks for block size.
unique_ptr< CellNeighborsVector > device_theCellNeighbors_
void allocateOnGPU(int32_t nHits, cudaStream_t stream)
typename TrackSoA< TrackerTraits >::HitContainer HitContainer
TrackingRecHitSoAConstView< TrackerTraits > HitsConstView
typename TrackingRecHitSoA< TrackerTraits >::template TrackingRecHitSoALayout<>::ConstView TrackingRecHitSoAConstView
void allocateOnGPU(int32_t nHits, cudaStream_t stream)
void launchKernels(const HitsConstView &hh, TkSoAView &track_view, cudaStream_t cudaStream)
void buildDoublets(const HitsConstView &hh, int32_t offsetBPIX2, cudaStream_t stream)
typename TrackSoA< TrackerTraits >::template TrackSoALayout<>::View TrackSoAView
void buildDoublets(const HitsConstView &hh, int32_t offsetBPIX2, cudaStream_t stream)
typename TrackingRecHitSoA< TrackerTraits >::template TrackingRecHitSoALayout<>::View TrackingRecHitSoAView
unique_ptr< cms::cuda::AtomicPairCounter::c_type[]> device_storage_
TupleMultiplicity< TrackerTraits > const *__restrict__ TrackingRecHitSoAConstView< TrackerTraits > hh
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
#define __device__
static constexpr uint8_t const * layerPairs
TrackSoAView< TrackerTraits > TkSoAView
static void printCounters(Counters const *counters)
static constexpr uint8_t const * layerPairs
cms::cuda::AtomicPairCounter * device_hitTuple_apc_
void cleanup(cudaStream_t cudaStream)