CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Types
CAHitNtupletGeneratorKernelsCPU< TrackerTraits > Class Template Reference

#include <CAHitNtupletGeneratorKernels.h>

Inheritance diagram for CAHitNtupletGeneratorKernelsCPU< TrackerTraits >:
CAHitNtupletGeneratorKernels< cms::cudacompat::CPUTraits, TrackerTraits >

Public Member Functions

void allocateOnGPU (int32_t nHits, cudaStream_t stream)
 
void buildDoublets (const HitsConstView &hh, int32_t offsetBPIX2, cudaStream_t stream)
 
void classifyTuples (const HitsConstView &hh, TkSoAView &track_view, cudaStream_t cudaStream)
 
void launchKernels (const HitsConstView &hh, TkSoAView &track_view, cudaStream_t cudaStream)
 
- Public Member Functions inherited from CAHitNtupletGeneratorKernels< cms::cudacompat::CPUTraits, TrackerTraits >
void allocateOnGPU (int32_t nHits, cudaStream_t stream)
 
void buildDoublets (const HitsConstView &hh, cudaStream_t stream)
 
 CAHitNtupletGeneratorKernels (Params const &params)
 
void classifyTuples (const HitsConstView &hh, TkSoAView &track_view, cudaStream_t cudaStream)
 
void cleanup (cudaStream_t cudaStream)
 
void launchKernels (const HitsConstView &hh, TkSoAView &track_view, cudaStream_t cudaStream)
 
void setCounters (Counters *counters)
 
TupleMultiplicity const * tupleMultiplicity () const
 
 ~CAHitNtupletGeneratorKernels ()=default
 

Static Public Member Functions

static void printCounters (Counters const *counters)
 
- Static Public Member Functions inherited from CAHitNtupletGeneratorKernels< cms::cudacompat::CPUTraits, TrackerTraits >
static void printCounters (Counters const *counters)
 

Private Types

using CAParams = caHitNtupletGenerator::CAParamsT< TrackerTraits >
 
using CellNeighborsVector = caStructures::CellNeighborsVectorT< TrackerTraits >
 
using CellTracksVector = caStructures::CellTracksVectorT< TrackerTraits >
 
using Counters = caHitNtupletGenerator::Counters
 
using HitContainer = typename TrackSoA< TrackerTraits >::HitContainer
 
using HitsConstView = TrackingRecHitSoAConstView< TrackerTraits >
 
using HitToTuple = caStructures::HitToTupleT< TrackerTraits >
 
using TkSoAView = TrackSoAView< TrackerTraits >
 
using TupleMultiplicity = caStructures::TupleMultiplicityT< TrackerTraits >
 

Additional Inherited Members

- Public Types inherited from CAHitNtupletGeneratorKernels< cms::cudacompat::CPUTraits, TrackerTraits >
using CACell = GPUCACellT< TrackerTraits >
 
using CAParams = caHitNtupletGenerator::CAParamsT< TrackerTraits >
 
using CellNeighbors = caStructures::CellNeighborsT< TrackerTraits >
 
using CellNeighborsVector = caStructures::CellNeighborsVectorT< TrackerTraits >
 
using CellTracks = caStructures::CellTracksT< TrackerTraits >
 
using CellTracksVector = caStructures::CellTracksVectorT< TrackerTraits >
 
using Counters = caHitNtupletGenerator::Counters
 
using HitContainer = typename TrackSoA< TrackerTraits >::HitContainer
 
using HitsConstView = TrackingRecHitSoAConstView< TrackerTraits >
 
using HitsView = TrackingRecHitSoAView< TrackerTraits >
 
using HitToTuple = caStructures::HitToTupleT< TrackerTraits >
 
using OuterHitOfCell = caStructures::OuterHitOfCellT< TrackerTraits >
 
using OuterHitOfCellContainer = caStructures::OuterHitOfCellContainerT< TrackerTraits >
 
using Params = caHitNtupletGenerator::ParamsT< TrackerTraits >
 
using Quality = pixelTrack::Quality
 
using QualityCuts = pixelTrack::QualityCutsT< TrackerTraits >
 
using TkSoAView = TrackSoAView< TrackerTraits >
 
using TrackerTraits = TrackerTraits
 
using Traits = cms::cudacompat::CPUTraits
 
using TupleMultiplicity = caStructures::TupleMultiplicityT< TrackerTraits >
 
using unique_ptr = typename Traits::template unique_ptr< T >
 
- Protected Member Functions inherited from CAHitNtupletGeneratorKernels< cms::cudacompat::CPUTraits, TrackerTraits >
uint32_t nDoubletBlocks (uint32_t blockSize)
 Compute the number of doublet blocks for block size. More...
 
uint32_t nQuadrupletBlocks (uint32_t blockSize)
 Compute the number of quadruplet blocks for block size. More...
 
- Protected Attributes inherited from CAHitNtupletGeneratorKernels< cms::cudacompat::CPUTraits, TrackerTraits >
unique_ptr< unsigned char[]> cellStorage_
 
Counterscounters_
 
unique_ptr< HitToTupledevice_hitToTuple_
 
cms::cuda::AtomicPairCounterdevice_hitToTuple_apc_
 
unique_ptr< uint32_t[]> device_hitToTupleStorage_
 
cms::cuda::AtomicPairCounterdevice_hitTuple_apc_
 
unique_ptr< OuterHitOfCellContainer[]> device_isOuterHitOfCell_
 
uint32_t * device_nCells_
 
unique_ptr< cms::cuda::AtomicPairCounter::c_type[]> device_storage_
 
unique_ptr< CellNeighborsVectordevice_theCellNeighbors_
 
CellNeighborsdevice_theCellNeighborsContainer_
 
unique_ptr< CACell[]> device_theCells_
 
unique_ptr< CellTracksVectordevice_theCellTracks_
 
CellTracksdevice_theCellTracksContainer_
 
unique_ptr< TupleMultiplicitydevice_tupleMultiplicity_
 
HitToTuple::View hitToTupleView_
 
OuterHitOfCell isOuterHitOfCell_
 
Params params_
 
const uint32_t paramsMaxDoubletes3Quarters_
 Intermediate result avoiding repeated computations. More...
 

Detailed Description

template<typename TrackerTraits>
class CAHitNtupletGeneratorKernelsCPU< TrackerTraits >

Definition at line 315 of file CAHitNtupletGeneratorKernels.h.

Member Typedef Documentation

◆ CAParams

Definition at line 319 of file CAHitNtupletGeneratorKernels.h.

◆ CellNeighborsVector

Definition at line 323 of file CAHitNtupletGeneratorKernels.h.

◆ CellTracksVector

Definition at line 325 of file CAHitNtupletGeneratorKernels.h.

◆ Counters

template<typename TrackerTraits >
using CAHitNtupletGeneratorKernelsCPU< TrackerTraits >::Counters = caHitNtupletGenerator::Counters
private

Definition at line 318 of file CAHitNtupletGeneratorKernels.h.

◆ HitContainer

template<typename TrackerTraits >
using CAHitNtupletGeneratorKernelsCPU< TrackerTraits >::HitContainer = typename TrackSoA<TrackerTraits>::HitContainer
private

Definition at line 321 of file CAHitNtupletGeneratorKernels.h.

◆ HitsConstView

Definition at line 328 of file CAHitNtupletGeneratorKernels.h.

◆ HitToTuple

Definition at line 324 of file CAHitNtupletGeneratorKernels.h.

◆ TkSoAView

template<typename TrackerTraits >
using CAHitNtupletGeneratorKernelsCPU< TrackerTraits >::TkSoAView = TrackSoAView<TrackerTraits>
private

Definition at line 329 of file CAHitNtupletGeneratorKernels.h.

◆ TupleMultiplicity

Definition at line 326 of file CAHitNtupletGeneratorKernels.h.

Member Function Documentation

◆ allocateOnGPU()

template<typename TrackerTraits >
void CAHitNtupletGeneratorKernelsCPU< TrackerTraits >::allocateOnGPU ( int32_t  nHits,
cudaStream_t  stream 
)

Definition at line 11 of file CAHitNtupletGeneratorKernelsAlloc.cc.

References cms::cuda::assert(), gather_cfg::cout, cudaCheck, nHits, cms::cuda::stream, svgfig::template(), and relativeConstraints::value.

11  {
13 #endif
14  // ALLOCATIONS FOR THE INTERMEDIATE RESULTS (STAYS ON WORKER)
17 
18  this->device_theCellNeighbors_ = Traits::template make_unique<CellNeighborsVector>(stream);
19  this->device_theCellTracks_ = Traits::template make_unique<CellTracksVector>(stream);
20 
21 #ifdef GPU_DEBUG
22  std::cout << "Allocation for tuple building. N hits " << nHits << std::endl;
23 #endif
24 
25  nHits++; // storage requires one more counter;
26  assert(nHits > 0);
27  this->device_hitToTuple_ = Traits::template make_unique<HitToTuple>(stream);
28  this->device_hitToTupleStorage_ = Traits::template make_unique<typename HitToTuple::Counter[]>(nHits, stream);
29  this->hitToTupleView_.assoc = this->device_hitToTuple_.get();
30  this->hitToTupleView_.offStorage = this->device_hitToTupleStorage_.get();
32 
33  this->device_tupleMultiplicity_ = Traits::template make_unique<TupleMultiplicity>(stream);
34 
35  this->device_storage_ = Traits::template make_unique<cms::cuda::AtomicPairCounter::c_type[]>(3, stream);
36 
37  this->device_hitTuple_apc_ = (cms::cuda::AtomicPairCounter*)this->device_storage_.get();
38  this->device_hitToTuple_apc_ = (cms::cuda::AtomicPairCounter*)this->device_storage_.get() + 1;
39  this->device_nCells_ = (uint32_t*)(this->device_storage_.get() + 2);
40 
41  // FIXME: consider collapsing these 3 in one adhoc kernel
43  cudaCheck(cudaMemsetAsync(this->device_nCells_, 0, sizeof(uint32_t), stream));
44  } else {
45  *(this->device_nCells_) = 0;
46  }
47  cms::cuda::launchZero(this->device_tupleMultiplicity_.get(), stream);
48  cms::cuda::launchZero(this->hitToTupleView_, stream); // we may wish to keep it in the edm
49 #ifdef GPU_DEBUG
50  cudaDeviceSynchronize();
51  cudaCheck(cudaGetLastError());
52 #endif
53 }
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
assert(be >=bs)
__device__ __host__ Counters get() const
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits

◆ buildDoublets()

template<typename TrackerTraits >
void CAHitNtupletGeneratorKernelsCPU< TrackerTraits >::buildDoublets ( const HitsConstView hh,
int32_t  offsetBPIX2,
cudaStream_t  stream 
)

Definition at line 17 of file CAHitNtupletGeneratorKernels.cc.

References gpuPixelDoublets::assert(), gather_cfg::cout, gpuPixelDoublets::hh, SiStripPI::max, gpuPixelDoublets::nActualPairs, nhits, phase1PixelTopology::nPairs, and mitigatedMETSequence_cff::U.

19  {
20  using namespace gpuPixelDoublets;
21 
22  using GPUCACell = GPUCACellT<TrackerTraits>;
24  using CellNeighbors = typename GPUCACell::CellNeighbors;
25  using CellTracks = typename GPUCACell::CellTracks;
26  using OuterHitOfCellContainer = typename GPUCACell::OuterHitOfCellContainer;
27 
28  auto nhits = hh.nHits();
29 
30 #ifdef NTUPLE_DEBUG
31  std::cout << "building Doublets out of " << nhits << " Hits. BPIX2 offset is " << offsetBPIX2 << std::endl;
32 #endif
33 
34  // use "nhits" to heuristically dimension the workspace
35 
36  // no need to use the Traits allocations, since we know this is being compiled for the CPU
37  //this->device_isOuterHitOfCell_ = Traits::template make_unique<GPUCACell::OuterHitOfCell[]>(std::max(1U, nhits), stream);
38  this->device_isOuterHitOfCell_ = std::make_unique<OuterHitOfCellContainer[]>(std::max(1U, nhits));
39  assert(this->device_isOuterHitOfCell_.get());
40  this->isOuterHitOfCell_ = OuterHitOfCell{this->device_isOuterHitOfCell_.get(), offsetBPIX2};
41 
42  auto cellStorageSize = TrackerTraits::maxNumOfActiveDoublets * sizeof(CellNeighbors) +
43  TrackerTraits::maxNumOfActiveDoublets * sizeof(CellTracks);
44  // no need to use the Traits allocations, since we know this is being compiled for the CPU
45  //cellStorage_ = Traits::template make_unique<unsigned char[]>(cellStorageSize, stream);
46  this->cellStorage_ = std::make_unique<unsigned char[]>(cellStorageSize);
49  (CellTracks *)(this->cellStorage_.get() + TrackerTraits::maxNumOfActiveDoublets * sizeof(CellNeighbors));
50 
51  initDoublets<TrackerTraits>(this->isOuterHitOfCell_,
52  nhits,
53  this->device_theCellNeighbors_.get(),
55  this->device_theCellTracks_.get(),
57 
58  // no need to use the Traits allocations, since we know this is being compiled for the CPU
59  //this->device_theCells_ = Traits::template make_unique<GPUCACell[]>(this->params_.cellCuts_.maxNumberOfDoublets_, stream);
60  this->device_theCells_ = std::make_unique<GPUCACell[]>(this->params_.cellCuts_.maxNumberOfDoublets_);
61  if (0 == nhits)
62  return; // protect against empty events
63 
64  // take all layer pairs into account
65  auto nActualPairs = this->params_.nPairs();
66 
68 
69  getDoubletsFromHisto<TrackerTraits>(this->device_theCells_.get(),
70  this->device_nCells_,
71  this->device_theCellNeighbors_.get(),
72  this->device_theCellTracks_.get(),
73  hh,
74  this->isOuterHitOfCell_,
76  this->params_.cellCuts_);
77 }
caStructures::OuterHitOfCellContainerT< TrackerTraits > OuterHitOfCellContainer
caStructures::CellNeighborsT< TrackerTraits > CellNeighbors
Definition: gpuFishbone.h:20
assert(be >=bs)
caStructures::CellTracksT< TrackerTraits > CellTracks
Definition: gpuFishbone.h:22
uint32_t CellNeighborsVector< TrackerTraits > CellTracksVector< TrackerTraits > HitsConstView< TrackerTraits > OuterHitOfCell< TrackerTraits > int nActualPairs
caStructures::OuterHitOfCellT< TrackerTraits > OuterHitOfCell
TupleMultiplicity< TrackerTraits > const *__restrict__ TrackingRecHitSoAConstView< TrackerTraits > hh

◆ classifyTuples()

template<typename TrackerTraits >
void CAHitNtupletGeneratorKernelsCPU< TrackerTraits >::classifyTuples ( const HitsConstView hh,
TkSoAView track_view,
cudaStream_t  cudaStream 
)

Definition at line 144 of file CAHitNtupletGeneratorKernels.cc.

References caHitNtupletGeneratorKernels::hh, caHitNtupletGeneratorKernels::iev, CommonMethods::lock(), mutex, caHitNtupletGeneratorKernels::nhits, and caHitNtupletGeneratorKernels::tracks_view.

146  {
147  using namespace caHitNtupletGeneratorKernels;
148 
149  int32_t nhits = hh.metadata().size();
150 
151  // classify tracks based on kinematics
152  kernel_classifyTracks<TrackerTraits>(tracks_view, this->params_.qualityCuts_);
153  if (this->params_.lateFishbone_) {
154  // apply fishbone cleaning to good tracks
155  kernel_fishboneCleaner<TrackerTraits>(this->device_theCells_.get(), this->device_nCells_, tracks_view);
156  }
157 
158  // remove duplicates (tracks that share a doublet)
159  kernel_fastDuplicateRemover<TrackerTraits>(
161 
162  // fill hit->track "map"
163  if (this->params_.doSharedHitCut_ || this->params_.doStats_) {
164  kernel_countHitInTracks<TrackerTraits>(tracks_view, this->device_hitToTuple_.get());
165  cms::cuda::launchFinalize(this->hitToTupleView_, cudaStream);
166  kernel_fillHitInTracks<TrackerTraits>(tracks_view, this->device_hitToTuple_.get());
167  }
168 
169  // remove duplicates (tracks that share at least one hit)
170  if (this->params_.doSharedHitCut_) {
171  kernel_rejectDuplicate<TrackerTraits>(tracks_view,
173  this->params_.dupPassThrough_,
174  this->device_hitToTuple_.get());
175 
176  kernel_sharedHitCleaner<TrackerTraits>(hh,
177  tracks_view,
179  this->params_.dupPassThrough_,
180  this->device_hitToTuple_.get());
181  if (this->params_.useSimpleTripletCleaner_) {
182  kernel_simpleTripletCleaner<TrackerTraits>(tracks_view,
184  this->params_.dupPassThrough_,
185  this->device_hitToTuple_.get());
186  } else {
187  kernel_tripletCleaner<TrackerTraits>(tracks_view,
189  this->params_.dupPassThrough_,
190  this->device_hitToTuple_.get());
191  }
192  }
193 
194  if (this->params_.doStats_) {
195  std::lock_guard guard(lock_stat);
196  kernel_checkOverflows<TrackerTraits>(tracks_view,
197  this->device_tupleMultiplicity_.get(),
198  this->device_hitToTuple_.get(),
199  this->device_hitTuple_apc_,
200  this->device_theCells_.get(),
201  this->device_nCells_,
202  this->device_theCellNeighbors_.get(),
203  this->device_theCellTracks_.get(),
204  this->isOuterHitOfCell_,
205  nhits,
206  this->params_.cellCuts_.maxNumberOfDoublets_,
207  this->counters_);
208  }
209 
210  if (this->params_.doStats_) {
211  // counters (add flag???)
212  std::lock_guard guard(lock_stat);
213  kernel_doStatsForHitInTracks<TrackerTraits>(this->device_hitToTuple_.get(), this->counters_);
214  kernel_doStatsForTracks<TrackerTraits>(tracks_view, this->counters_);
215  }
216 
217 #ifdef DUMP_GPU_TK_TUPLES
218  static std::atomic<int> iev(0);
219  static std::mutex lock;
220  {
221  std::lock_guard<std::mutex> guard(lock);
222  ++iev;
223  kernel_print_found_ntuplets<TrackerTraits>(hh, tracks_view, this->device_hitToTuple_.get(), 0, 1000000, iev);
224  }
225 #endif
226 }
uint32_t const *__restrict__ TkSoAView< TrackerTraits > tracks_view
static std::mutex mutex
Definition: Proxy.cc:8
TkSoAView< TrackerTraits > HitToTuple< TrackerTraits > const *__restrict__ int32_t int32_t int iev
TupleMultiplicity< TrackerTraits > const *__restrict__ TrackingRecHitSoAConstView< TrackerTraits > hh

◆ launchKernels()

template<typename TrackerTraits >
void CAHitNtupletGeneratorKernelsCPU< TrackerTraits >::launchKernels ( const HitsConstView hh,
TkSoAView track_view,
cudaStream_t  cudaStream 
)

Definition at line 80 of file CAHitNtupletGeneratorKernels.cc.

References gather_cfg::cout, caHitNtupletGeneratorKernels::hh, caHitNtupletGeneratorKernels::nhits, and caHitNtupletGeneratorKernels::tracks_view.

82  {
83  using namespace caHitNtupletGeneratorKernels;
84 
85  // zero tuples
86  cms::cuda::launchZero(&tracks_view.hitIndices(), cudaStream);
87 
88  uint32_t nhits = hh.metadata().size();
89 
90 #ifdef NTUPLE_DEBUG
91  std::cout << "start tuple building. N hits " << nhits << std::endl;
92  if (nhits < 2)
93  std::cout << "too few hits " << nhits << std::endl;
94 #endif
95 
96  //
97  // applying conbinatoric cleaning such as fishbone at this stage is too expensive
98  //
99 
100  kernel_connect<TrackerTraits>(this->device_hitTuple_apc_,
101  this->device_hitToTuple_apc_, // needed only to be reset, ready for next kernel
102  hh,
103  this->device_theCells_.get(),
104  this->device_nCells_,
105  this->device_theCellNeighbors_.get(),
106  this->isOuterHitOfCell_,
107  this->params_.caParams_);
108 
109  if (nhits > 1 && this->params_.earlyFishbone_) {
110  gpuPixelDoublets::fishbone<TrackerTraits>(
111  hh, this->device_theCells_.get(), this->device_nCells_, this->isOuterHitOfCell_, nhits, false);
112  }
113 
114  kernel_find_ntuplets<TrackerTraits>(hh,
115  tracks_view,
116  this->device_theCells_.get(),
117  this->device_nCells_,
118  this->device_theCellTracks_.get(),
119  this->device_hitTuple_apc_,
120  this->params_.caParams_);
121  if (this->params_.doStats_)
122  kernel_mark_used(this->device_theCells_.get(), this->device_nCells_);
123 
124  cms::cuda::finalizeBulk(this->device_hitTuple_apc_, &tracks_view.hitIndices());
125 
126  kernel_fillHitDetIndices<TrackerTraits>(tracks_view, hh);
127  kernel_fillNLayers<TrackerTraits>(tracks_view, this->device_hitTuple_apc_);
128 
129  // remove duplicates (tracks that share a doublet)
130  kernel_earlyDuplicateRemover<TrackerTraits>(
132 
133  kernel_countMultiplicity<TrackerTraits>(tracks_view, this->device_tupleMultiplicity_.get());
134  cms::cuda::launchFinalize(this->device_tupleMultiplicity_.get(), cudaStream);
135  kernel_fillMultiplicity<TrackerTraits>(tracks_view, this->device_tupleMultiplicity_.get());
136 
137  if (nhits > 1 && this->params_.lateFishbone_) {
138  gpuPixelDoublets::fishbone<TrackerTraits>(
139  hh, this->device_theCells_.get(), this->device_nCells_, this->isOuterHitOfCell_, nhits, true);
140  }
141 }
uint32_t const *__restrict__ TkSoAView< TrackerTraits > tracks_view
TupleMultiplicity< TrackerTraits > const *__restrict__ TrackingRecHitSoAConstView< TrackerTraits > hh

◆ printCounters()

template<typename TrackerTraits >
void CAHitNtupletGeneratorKernelsCPU< TrackerTraits >::printCounters ( Counters const *  counters)
static

Definition at line 12 of file CAHitNtupletGeneratorKernels.cc.

References caHitNtupletGeneratorKernels::counters.

Referenced by CAHitNtupletGeneratorOnGPU< TrackerTraits >::endJob().

12  {
13  caHitNtupletGeneratorKernels::kernel_printCounters(counters);
14 }
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