CMS 3D CMS Logo

CAHitNtupletGeneratorKernels.h
Go to the documentation of this file.
1 #ifndef RecoTracker_PixelSeeding_plugins_CAHitNtupletGeneratorKernels_h
2 #define RecoTracker_PixelSeeding_plugins_CAHitNtupletGeneratorKernels_h
3 
4 //#define GPU_DEBUG
5 //#define DUMP_GPU_TK_TUPLES
6 
12 
13 #include "GPUCACell.h"
14 #include "gpuPixelDoublets.h"
15 
17 
18  //Configuration params common to all topologies, for the algorithms
19  struct AlgoParams {
20  const bool onGPU_;
21  const uint32_t minHitsForSharingCut_;
22  const bool useRiemannFit_;
23  const bool fitNas4_;
25  const bool earlyFishbone_;
26  const bool lateFishbone_;
27  const bool doStats_;
28  const bool doSharedHitCut_;
29  const bool dupPassThrough_;
31  };
32 
33  //CAParams
34  struct CACommon {
35  const uint32_t maxNumberOfDoublets_;
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;
207 
208  template <typename T>
210 
214 
223 
225 
228 
230  : params_(params), paramsMaxDoubletes3Quarters_(3 * params.caParams_.maxNumberOfDoublets_ / 4) {}
231 
232  ~CAHitNtupletGeneratorKernels() = default;
233 
235 
236  void launchKernels(const HitsConstView& hh, TkSoAView& track_view, cudaStream_t cudaStream);
237 
238  void classifyTuples(const HitsConstView& hh, TkSoAView& track_view, cudaStream_t cudaStream);
239 
240  void buildDoublets(const HitsConstView& hh, cudaStream_t stream);
241  void allocateOnGPU(int32_t nHits, cudaStream_t stream);
242  void cleanup(cudaStream_t cudaStream);
243 
244  static void printCounters(Counters const* counters);
246 
247 protected:
248  Counters* counters_ = nullptr;
249 
250  // workspace
256 
260  uint32_t* device_nCells_ = nullptr;
261 
265 
267 
269 
271 
273 
275 
276  // params
281  inline uint32_t nDoubletBlocks(uint32_t blockSize) {
282  // We want (3 * params_.maxNumberOfDoublets_ / 4 + blockSize - 1) / blockSize, but first part is pre-computed.
283  return (paramsMaxDoubletes3Quarters_ + blockSize - 1) / blockSize;
284  }
285 
287  inline uint32_t nQuadrupletBlocks(uint32_t blockSize) {
288  // pixelTopology::maxNumberOfQuadruplets is a constexpr, so the compiler will pre compute the 3*max/4
289  return (3 * TrackerTraits::maxNumberOfQuadruplets / 4 + blockSize - 1) / blockSize;
290  }
291 };
292 
293 template <typename TrackerTraits>
294 class CAHitNtupletGeneratorKernelsGPU : public CAHitNtupletGeneratorKernels<cms::cudacompat::GPUTraits, TrackerTraits> {
296 
299 
301 
306 
309 
311 
312 public:
313  void launchKernels(const HitsConstView& hh, TkSoAView& track_view, cudaStream_t cudaStream);
314  void classifyTuples(const HitsConstView& hh, TkSoAView& track_view, cudaStream_t cudaStream);
315  void buildDoublets(const HitsConstView& hh, int32_t offsetBPIX2, cudaStream_t stream);
316  void allocateOnGPU(int32_t nHits, cudaStream_t stream);
317  static void printCounters(Counters const* counters);
318 };
319 
320 template <typename TrackerTraits>
321 class CAHitNtupletGeneratorKernelsCPU : public CAHitNtupletGeneratorKernels<cms::cudacompat::CPUTraits, TrackerTraits> {
323 
326 
328 
333 
336 
338 
339 public:
340  void launchKernels(const HitsConstView& hh, TkSoAView& track_view, cudaStream_t cudaStream);
341  void classifyTuples(const HitsConstView& hh, TkSoAView& track_view, cudaStream_t cudaStream);
342  void buildDoublets(const HitsConstView& hh, int32_t offsetBPIX2, cudaStream_t stream);
343  void allocateOnGPU(int32_t nHits, cudaStream_t stream);
344  static void printCounters(Counters const* counters);
345 };
346 
347 #endif // RecoTracker_PixelSeeding_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
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.
ALPAKA_FN_ACC ALPAKA_FN_INLINE void uint32_t const uint32_t CACellT< TrackerTraits > uint32_t CellNeighborsVector< TrackerTraits > CellTracksVector< TrackerTraits > HitsConstView< TrackerTraits > hh
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
typename OneToManyAssocBase< I, ONES, SIZE >::View View
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__ 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)