CMS 3D CMS Logo

CAHitNtupletGeneratorKernels.cc
Go to the documentation of this file.
2 
3 template <>
5  kernel_printCounters(counters);
6 }
7 
8 template <>
9 void CAHitNtupletGeneratorKernelsCPU::fillHitDetIndices(HitsView const *hv, TkSoA *tracks_d, cudaStream_t) {
10  kernel_fillHitDetIndices(&tracks_d->hitIndices, hv, &tracks_d->detIndices);
11 }
12 
13 template <>
15  auto nhits = hh.nHits();
16 
17 #ifdef NTUPLE_DEBUG
18  std::cout << "building Doublets out of " << nhits << " Hits" << std::endl;
19 #endif
20 
21  // use "nhits" to heuristically dimension the workspace
22 
23  // no need to use the Traits allocations, since we know this is being compiled for the CPU
24  //device_isOuterHitOfCell_ = Traits::template make_unique<GPUCACell::OuterHitOfCell[]>(std::max(1U, nhits), stream);
25  device_isOuterHitOfCell_ = std::make_unique<GPUCACell::OuterHitOfCell[]>(std::max(1U, nhits));
27 
28  auto cellStorageSize = caConstants::maxNumOfActiveDoublets * sizeof(GPUCACell::CellNeighbors) +
30  // no need to use the Traits allocations, since we know this is being compiled for the CPU
31  //cellStorage_ = Traits::template make_unique<unsigned char[]>(cellStorageSize, stream);
32  cellStorage_ = std::make_unique<unsigned char[]>(cellStorageSize);
35  sizeof(GPUCACell::CellNeighbors));
36 
37  gpuPixelDoublets::initDoublets(device_isOuterHitOfCell_.get(),
38  nhits,
43 
44  // no need to use the Traits allocations, since we know this is being compiled for the CPU
45  //device_theCells_ = Traits::template make_unique<GPUCACell[]>(params_.maxNumberOfDoublets_, stream);
46  device_theCells_ = std::make_unique<GPUCACell[]>(params_.maxNumberOfDoublets_);
47  if (0 == nhits)
48  return; // protect against empty events
49 
50  // take all layer pairs into account
53  // exclude forward "jumping" layer pairs
55  }
56  if (params_.minHitsPerNtuplet_ > 3) {
57  // for quadruplets, exclude all "jumping" layer pairs
59  }
60 
62  gpuPixelDoublets::getDoubletsFromHisto(device_theCells_.get(),
66  hh.view(),
74 }
75 
76 template <>
77 void CAHitNtupletGeneratorKernelsCPU::launchKernels(HitsOnCPU const &hh, TkSoA *tracks_d, cudaStream_t cudaStream) {
78  auto *tuples_d = &tracks_d->hitIndices;
79  auto *quality_d = tracks_d->qualityData();
80 
81  assert(tuples_d && quality_d);
82 
83  // zero tuples
84  cms::cuda::launchZero(tuples_d, cudaStream);
85 
86  auto nhits = hh.nHits();
88 
89  // std::cout << "N hits " << nhits << std::endl;
90  // if (nhits<2) std::cout << "too few hits " << nhits << std::endl;
91 
92  //
93  // applying conbinatoric cleaning such as fishbone at this stage is too expensive
94  //
95 
96  kernel_connect(device_hitTuple_apc_,
97  device_hitToTuple_apc_, // needed only to be reset, ready for next kernel
98  hh.view(),
99  device_theCells_.get(),
104  params_.ptmin_,
109 
110  if (nhits > 1 && params_.earlyFishbone_) {
111  gpuPixelDoublets::fishbone(
112  hh.view(), device_theCells_.get(), device_nCells_, device_isOuterHitOfCell_.get(), nhits, false);
113  }
114 
115  kernel_find_ntuplets(hh.view(),
116  device_theCells_.get(),
118  device_theCellTracks_.get(),
119  tuples_d,
121  quality_d,
123  if (params_.doStats_)
124  kernel_mark_used(hh.view(), device_theCells_.get(), device_nCells_);
125 
126  cms::cuda::finalizeBulk(device_hitTuple_apc_, tuples_d);
127 
128  // remove duplicates (tracks that share a doublet)
129  kernel_earlyDuplicateRemover(device_theCells_.get(), device_nCells_, tuples_d, quality_d);
130 
131  kernel_countMultiplicity(tuples_d, quality_d, device_tupleMultiplicity_.get());
132  cms::cuda::launchFinalize(device_tupleMultiplicity_.get(), cudaStream);
133  kernel_fillMultiplicity(tuples_d, quality_d, device_tupleMultiplicity_.get());
134 
135  if (nhits > 1 && params_.lateFishbone_) {
136  gpuPixelDoublets::fishbone(
137  hh.view(), device_theCells_.get(), device_nCells_, device_isOuterHitOfCell_.get(), nhits, true);
138  }
139 
140  if (params_.doStats_) {
141  kernel_checkOverflows(tuples_d,
143  device_hitToTuple_.get(),
145  device_theCells_.get(),
148  device_theCellTracks_.get(),
150  nhits,
152  counters_);
153  }
154 }
155 
156 template <>
157 void CAHitNtupletGeneratorKernelsCPU::classifyTuples(HitsOnCPU const &hh, TkSoA *tracks_d, cudaStream_t cudaStream) {
158  auto const *tuples_d = &tracks_d->hitIndices;
159  auto *quality_d = tracks_d->qualityData();
160 
161  // classify tracks based on kinematics
162  kernel_classifyTracks(tuples_d, tracks_d, params_.cuts_, quality_d);
163 
164  if (params_.lateFishbone_) {
165  // apply fishbone cleaning to good tracks
166  kernel_fishboneCleaner(device_theCells_.get(), device_nCells_, quality_d);
167  }
168 
169  // remove duplicates (tracks that share a doublet)
170  kernel_fastDuplicateRemover(device_theCells_.get(), device_nCells_, tuples_d, tracks_d);
171 
172  // fill hit->track "map"
174  kernel_countHitInTracks(tuples_d, quality_d, device_hitToTuple_.get());
175  cms::cuda::launchFinalize(device_hitToTuple_.get(), cudaStream);
176  kernel_fillHitInTracks(tuples_d, quality_d, device_hitToTuple_.get());
177  }
178 
179  // remove duplicates (tracks that share a hit)
180  if (params_.doSharedHitCut_) {
181  kernel_sharedHitCleaner(
182  hh.view(), tuples_d, tracks_d, quality_d, params_.minHitsForSharingCut_, device_hitToTuple_.get());
183  }
184 
185  if (params_.doStats_) {
186  // counters (add flag???)
187  kernel_doStatsForHitInTracks(device_hitToTuple_.get(), counters_);
188  kernel_doStatsForTracks(tuples_d, quality_d, counters_);
189  }
190 
191 #ifdef DUMP_GPU_TK_TUPLES
192  static std::atomic<int> iev(0);
193  ++iev;
194  kernel_print_found_ntuplets(hh.view(), tuples_d, tracks_d, quality_d, device_hitToTuple_.get(), 100, iev);
195 #endif
196 }
cAHitNtupletGenerator::Params::earlyFishbone_
const bool earlyFishbone_
Definition: CAHitNtupletGeneratorKernels.h:107
iev
const HitContainer *__restrict__ const TkSoA *__restrict__ const Quality *__restrict__ const CAHitNtupletGeneratorKernelsGPU::HitToTuple *__restrict__ uint32_t int iev
Definition: CAHitNtupletGeneratorKernelsImpl.h:544
CAHitNtupletGeneratorKernels::device_theCellTracksContainer_
caConstants::CellTracks * device_theCellTracksContainer_
Definition: CAHitNtupletGeneratorKernels.h:196
CAHitNtupletGeneratorKernels::device_hitTuple_apc_
cms::cuda::AtomicPairCounter * device_hitTuple_apc_
Definition: CAHitNtupletGeneratorKernels.h:205
cAHitNtupletGenerator::Params::minHitsForSharingCut_
const uint16_t minHitsForSharingCut_
Definition: CAHitNtupletGeneratorKernels.h:103
GPUCACell::CellNeighbors
caConstants::CellNeighbors CellNeighbors
Definition: GPUCACell.h:26
cms::cuda::stream
cudaStream_t stream
Definition: HistoContainer.h:57
gather_cfg.cout
cout
Definition: gather_cfg.py:144
CAHitNtupletGeneratorKernels::params_
Params const & params_
Definition: CAHitNtupletGeneratorKernels.h:211
TrackingRecHit2DHeterogeneous
Definition: TrackingRecHit2DHeterogeneous.h:8
cms::cuda::assert
assert(be >=bs)
CAHitNtupletGeneratorKernels::device_theCellTracks_
unique_ptr< caConstants::CellTracksVector > device_theCellTracks_
Definition: CAHitNtupletGeneratorKernels.h:195
cAHitNtupletGenerator::Params::dcaCutInnerTriplet_
const float dcaCutInnerTriplet_
Definition: CAHitNtupletGeneratorKernels.h:119
CAHitNtupletGeneratorKernels::device_theCellNeighbors_
unique_ptr< caConstants::CellNeighborsVector > device_theCellNeighbors_
Definition: CAHitNtupletGeneratorKernels.h:193
TrackingRecHit2DSOAView
Definition: TrackingRecHit2DSOAView.h:15
CAHitNtupletGeneratorKernels::device_theCells_
unique_ptr< GPUCACell[]> device_theCells_
Definition: CAHitNtupletGeneratorKernels.h:198
CAHitNtupletGeneratorKernels::launchKernels
void launchKernels(HitsOnCPU const &hh, TkSoA *tuples_d, cudaStream_t cudaStream)
Definition: CAHitNtupletGeneratorKernels.cc:77
CAHitNtupletGeneratorKernels::device_nCells_
uint32_t * device_nCells_
Definition: CAHitNtupletGeneratorKernels.h:200
CAHitNtupletGeneratorKernels::device_tupleMultiplicity_
unique_ptr< TupleMultiplicity > device_tupleMultiplicity_
Definition: CAHitNtupletGeneratorKernels.h:207
CAHitNtupletGeneratorKernels::device_hitToTuple_apc_
cms::cuda::AtomicPairCounter * device_hitToTuple_apc_
Definition: CAHitNtupletGeneratorKernels.h:203
cAHitNtupletGenerator::Params::idealConditions_
const bool idealConditions_
Definition: CAHitNtupletGeneratorKernels.h:109
cAHitNtupletGenerator::Params::lateFishbone_
const bool lateFishbone_
Definition: CAHitNtupletGeneratorKernels.h:108
cAHitNtupletGenerator::Params::doSharedHitCut_
const bool doSharedHitCut_
Definition: CAHitNtupletGeneratorKernels.h:114
counters
const caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple cms::cuda::AtomicPairCounter const GPUCACell *__restrict__ const uint32_t *__restrict__ const gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell *__restrict__ uint32_t uint32_t CAHitNtupletGeneratorKernelsGPU::Counters * counters
Definition: CAHitNtupletGeneratorKernelsImpl.h:43
cAHitNtupletGenerator::Params::maxNumberOfDoublets_
const uint32_t maxNumberOfDoublets_
Definition: CAHitNtupletGeneratorKernels.h:102
CAHitNtupletGeneratorKernels::device_theCellNeighborsContainer_
caConstants::CellNeighbors * device_theCellNeighborsContainer_
Definition: CAHitNtupletGeneratorKernels.h:194
cAHitNtupletGenerator::Params::minHitsPerNtuplet_
const uint32_t minHitsPerNtuplet_
Definition: CAHitNtupletGeneratorKernels.h:101
CAHitNtupletGeneratorKernels::device_hitToTuple_
unique_ptr< HitToTuple > device_hitToTuple_
Definition: CAHitNtupletGeneratorKernels.h:202
cAHitNtupletGenerator::Params::hardCurvCut_
const float hardCurvCut_
Definition: CAHitNtupletGeneratorKernels.h:118
CAHitNtupletGeneratorKernels::classifyTuples
void classifyTuples(HitsOnCPU const &hh, TkSoA *tuples_d, cudaStream_t cudaStream)
Definition: CAHitNtupletGeneratorKernels.cc:157
cAHitNtupletGenerator::Params::dcaCutOuterTriplet_
const float dcaCutOuterTriplet_
Definition: CAHitNtupletGeneratorKernels.h:120
caConstants::maxNumOfActiveDoublets
constexpr uint32_t maxNumOfActiveDoublets
Definition: CAConstants.h:40
nhits
Definition: HIMultiTrackSelector.h:42
gpuPixelDoublets::nPairsForQuadruplets
constexpr int nPairsForQuadruplets
Definition: gpuPixelDoublets.h:10
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
gpuPixelDoublets::nActualPairs
uint32_t CellNeighborsVector CellTracksVector TrackingRecHit2DSOAView const *__restrict__ GPUCACell::OuterHitOfCell int nActualPairs
Definition: gpuPixelDoublets.h:99
TrackSoAHeterogeneousT
Definition: TrackSoAHeterogeneousT.h:14
CAHitNtupletGeneratorKernels::device_isOuterHitOfCell_
unique_ptr< GPUCACell::OuterHitOfCell[]> device_isOuterHitOfCell_
Definition: CAHitNtupletGeneratorKernels.h:199
hh
const auto & hh
Definition: CAHitNtupletGeneratorKernelsImpl.h:455
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
cAHitNtupletGenerator::Params::cuts_
QualityCuts cuts_
Definition: CAHitNtupletGeneratorKernels.h:123
cAHitNtupletGenerator::Params::doPtCut_
const bool doPtCut_
Definition: CAHitNtupletGeneratorKernels.h:113
cAHitNtupletGenerator::Params::includeJumpingForwardDoublets_
const bool includeJumpingForwardDoublets_
Definition: CAHitNtupletGeneratorKernels.h:106
cAHitNtupletGenerator::Params::CAThetaCutForward_
const float CAThetaCutForward_
Definition: CAHitNtupletGeneratorKernels.h:117
cms::cuda::VecArray
Definition: VecArray.h:14
CAHitNtupletGeneratorKernels::fillHitDetIndices
void fillHitDetIndices(HitsView const *hv, TkSoA *tuples_d, cudaStream_t cudaStream)
Definition: CAHitNtupletGeneratorKernels.cc:9
cAHitNtupletGenerator::Params::doZ0Cut_
const bool doZ0Cut_
Definition: CAHitNtupletGeneratorKernels.h:112
CAHitNtupletGeneratorKernels::printCounters
static void printCounters(Counters const *counters)
Definition: CAHitNtupletGeneratorKernels.cc:4
gpuPixelDoublets::nPairsForTriplets
constexpr int nPairsForTriplets
Definition: gpuPixelDoublets.h:11
cAHitNtupletGenerator::Counters
Definition: CAHitNtupletGeneratorKernels.h:12
gpuPixelDoublets::nPairs
constexpr int nPairs
Definition: gpuPixelDoublets.h:12
CAHitNtupletGeneratorKernelsImpl.h
TrackSoAHeterogeneousT::hitIndices
HitContainer hitIndices
Definition: TrackSoAHeterogeneousT.h:53
TrackSoAHeterogeneousT::qualityData
constexpr const Quality * qualityData() const
Definition: TrackSoAHeterogeneousT.h:30
CAHitNtupletGeneratorKernels::cellStorage_
unique_ptr< unsigned char[]> cellStorage_
Definition: CAHitNtupletGeneratorKernels.h:192
TrackSoAHeterogeneousT::detIndices
HitContainer detIndices
Definition: TrackSoAHeterogeneousT.h:54
CAHitNtupletGeneratorKernels::buildDoublets
void buildDoublets(HitsOnCPU const &hh, cudaStream_t stream)
Definition: CAHitNtupletGeneratorKernels.cc:14
cAHitNtupletGenerator::Params::doClusterCut_
const bool doClusterCut_
Definition: CAHitNtupletGeneratorKernels.h:111
pixelGPUConstants::maxNumberOfHits
constexpr uint32_t maxNumberOfHits
Definition: gpuClusteringConstants.h:14
CAHitNtupletGeneratorKernels::counters_
Counters * counters_
Definition: CAHitNtupletGeneratorKernels.h:189
cAHitNtupletGenerator::Params::doStats_
const bool doStats_
Definition: CAHitNtupletGeneratorKernels.h:110
cAHitNtupletGenerator::Params::ptmin_
const float ptmin_
Definition: CAHitNtupletGeneratorKernels.h:115
cAHitNtupletGenerator::Params::CAThetaCutBarrel_
const float CAThetaCutBarrel_
Definition: CAHitNtupletGeneratorKernels.h:116