CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PixelVertexProducerCUDA.cc
Go to the documentation of this file.
1 #include <cuda_runtime.h>
2 
19 
20 #include "gpuVertexFinder.h"
21 
22 #undef PIXVERTEX_DEBUG_PRODUCE
23 
25 public:
27  ~PixelVertexProducerCUDA() override = default;
28 
29  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
30 
31 private:
32  void produceOnGPU(edm::StreamID streamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const;
33  void produceOnCPU(edm::StreamID streamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const;
34  void produce(edm::StreamID streamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
35 
36  bool onGPU_;
37 
42 
44 
45  // Tracking cuts before sending tracks to vertex algo
46  const float ptMin_;
47 };
48 
50  : onGPU_(conf.getParameter<bool>("onGPU")),
51  gpuAlgo_(conf.getParameter<bool>("oneKernel"),
52  conf.getParameter<bool>("useDensity"),
53  conf.getParameter<bool>("useDBSCAN"),
54  conf.getParameter<bool>("useIterative"),
55  conf.getParameter<int>("minT"),
56  conf.getParameter<double>("eps"),
57  conf.getParameter<double>("errmax"),
58  conf.getParameter<double>("chi2max")),
59  ptMin_(conf.getParameter<double>("PtMin")) // 0.5 GeV
60 {
61  if (onGPU_) {
63  consumes<cms::cuda::Product<PixelTrackHeterogeneous>>(conf.getParameter<edm::InputTag>("pixelTrackSrc"));
64  tokenGPUVertex_ = produces<ZVertexCUDAProduct>();
65  } else {
66  tokenCPUTrack_ = consumes<PixelTrackHeterogeneous>(conf.getParameter<edm::InputTag>("pixelTrackSrc"));
67  tokenCPUVertex_ = produces<ZVertexHeterogeneous>();
68  }
69 }
70 
73 
74  // Only one of these three algos can be used at once.
75  // Maybe this should become a Plugin Factory
76  desc.add<bool>("onGPU", true);
77  desc.add<bool>("oneKernel", true);
78  desc.add<bool>("useDensity", true);
79  desc.add<bool>("useDBSCAN", false);
80  desc.add<bool>("useIterative", false);
81 
82  desc.add<int>("minT", 2); // min number of neighbours to be "core"
83  desc.add<double>("eps", 0.07); // max absolute distance to cluster
84  desc.add<double>("errmax", 0.01); // max error to be "seed"
85  desc.add<double>("chi2max", 9.); // max normalized distance to cluster
86 
87  desc.add<double>("PtMin", 0.5);
88  desc.add<edm::InputTag>("pixelTrackSrc", edm::InputTag("pixelTracksCUDA"));
89 
90  auto label = "pixelVerticesCUDA";
91  descriptions.add(label, desc);
92 }
93 
96  const edm::EventSetup& iSetup) const {
98  iEvent.getByToken(tokenGPUTrack_, hTracks);
99 
100  cms::cuda::ScopedContextProduce ctx{*hTracks};
101  auto const* tracks = ctx.get(*hTracks).get();
102 
103  assert(tracks);
104 
105  ctx.emplace(iEvent, tokenGPUVertex_, gpuAlgo_.makeAsync(ctx.stream(), tracks, ptMin_));
106 }
107 
110  const edm::EventSetup& iSetup) const {
111  auto const* tracks = iEvent.get(tokenCPUTrack_).get();
112  assert(tracks);
113 
114 #ifdef PIXVERTEX_DEBUG_PRODUCE
115  auto const& tsoa = *tracks;
116  auto maxTracks = tsoa.stride();
117  std::cout << "size of SoA " << sizeof(tsoa) << " stride " << maxTracks << std::endl;
118 
119  int32_t nt = 0;
120  for (int32_t it = 0; it < maxTracks; ++it) {
121  auto nHits = tsoa.nHits(it);
122  assert(nHits == int(tsoa.hitIndices.size(it)));
123  if (nHits == 0)
124  break; // this is a guard: maybe we need to move to nTracks...
125  nt++;
126  }
127  std::cout << "found " << nt << " tracks in cpu SoA for Vertexing at " << tracks << std::endl;
128 #endif // PIXVERTEX_DEBUG_PRODUCE
129 
131 }
132 
134  if (onGPU_) {
135  produceOnGPU(streamID, iEvent, iSetup);
136  } else {
137  produceOnCPU(streamID, iEvent, iSetup);
138  }
139 }
140 
PixelVertexProducerCUDA(const edm::ParameterSet &iConfig)
edm::EDPutTokenT< ZVertexCUDAProduct > tokenGPUVertex_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDPutTokenT< ZVertexHeterogeneous > tokenCPUVertex_
edm::EDGetTokenT< cms::cuda::Product< PixelTrackHeterogeneous > > tokenGPUTrack_
void produceOnCPU(edm::StreamID streamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const
auto const & tracks
cannot be loose
ZVertexHeterogeneous make(TkSoA const *tksoa, float ptMin) const
assert(be >=bs)
char const * label
ptMin_(conf.getParameter< double >("ptMin"))
int iEvent
Definition: GenABIO.cc:224
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
void produce(edm::StreamID streamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
ParameterDescriptionBase * add(U const &iLabel, T const &value)
ZVertexHeterogeneous makeAsync(cudaStream_t stream, TkSoA const *tksoa, float ptMin) const
int nt
Definition: AMPTWrapper.h:42
void produceOnGPU(edm::StreamID streamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const
OrphanHandle< PROD > emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
Definition: Event.h:433
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t nHits
~PixelVertexProducerCUDA() override=default
edm::EDGetTokenT< PixelTrackHeterogeneous > tokenCPUTrack_
tuple cout
Definition: gather_cfg.py:144
const gpuVertexFinder::Producer gpuAlgo_