CMS 3D CMS Logo

SiPixelRecHitFromCUDA.cc
Go to the documentation of this file.
1 #include <cuda_runtime.h>
2 
3 #include <fmt/printf.h>
4 
26 
27 class SiPixelRecHitFromCUDA : public edm::stream::EDProducer<edm::ExternalWork> {
28 public:
29  explicit SiPixelRecHitFromCUDA(const edm::ParameterSet& iConfig);
30  ~SiPixelRecHitFromCUDA() override = default;
31 
32  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
33 
35 
36 private:
37  void acquire(edm::Event const& iEvent,
38  edm::EventSetup const& iSetup,
39  edm::WaitingTaskWithArenaHolder waitingTaskHolder) override;
40  void produce(edm::Event& iEvent, edm::EventSetup const& iSetup) override;
41 
47 
48  uint32_t nHits_;
51 };
52 
54  : geomToken_(esConsumes()),
55  hitsToken_(
56  consumes<cms::cuda::Product<TrackingRecHit2DCUDA>>(iConfig.getParameter<edm::InputTag>("pixelRecHitSrc"))),
57  clusterToken_(consumes<SiPixelClusterCollectionNew>(iConfig.getParameter<edm::InputTag>("src"))),
58  rechitsPutToken_(produces<SiPixelRecHitCollection>()),
59  hostPutToken_(produces<HMSstorage>()) {}
60 
63  desc.add<edm::InputTag>("pixelRecHitSrc", edm::InputTag("siPixelRecHitsPreSplittingCUDA"));
64  desc.add<edm::InputTag>("src", edm::InputTag("siPixelClustersPreSplitting"));
65  descriptions.addWithDefaultLabel(desc);
66 }
67 
69  edm::EventSetup const& iSetup,
70  edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
71  cms::cuda::Product<TrackingRecHit2DCUDA> const& inputDataWrapped = iEvent.get(hitsToken_);
72  cms::cuda::ScopedContextAcquire ctx{inputDataWrapped, std::move(waitingTaskHolder)};
73  auto const& inputData = ctx.get(inputDataWrapped);
74 
75  nHits_ = inputData.nHits();
76 
77  LogDebug("SiPixelRecHitFromCUDA") << "converting " << nHits_ << " Hits";
78 
79  if (0 == nHits_)
80  return;
81  store32_ = inputData.localCoordToHostAsync(ctx.stream());
82  hitsModuleStart_ = inputData.hitsModuleStartToHostAsync(ctx.stream());
83 }
84 
86  // allocate a buffer for the indices of the clusters
87  auto hmsp = std::make_unique<uint32_t[]>(gpuClustering::maxNumModules + 1);
88 
91 
92  if (0 == nHits_) {
94  iEvent.emplace(hostPutToken_, std::move(hmsp));
95  return;
96  }
97 
99  // wrap the buffer in a HostProduct, and move it to the Event, without reallocating the buffer or affecting hitsModuleStart
100  iEvent.emplace(hostPutToken_, std::move(hmsp));
101 
102  auto xl = store32_.get();
103  auto yl = xl + nHits_;
104  auto xe = yl + nHits_;
105  auto ye = xe + nHits_;
106 
107  const TrackerGeometry* geom = &es.getData(geomToken_);
108 
110  auto const& input = *hclusters;
111 
112  constexpr uint32_t maxHitsInModule = gpuClustering::maxHitsInModule();
113 
114  int numberOfDetUnits = 0;
115  int numberOfClusters = 0;
116  for (auto const& dsv : input) {
117  numberOfDetUnits++;
118  unsigned int detid = dsv.detId();
119  DetId detIdObject(detid);
120  const GeomDetUnit* genericDet = geom->idToDetUnit(detIdObject);
121  auto gind = genericDet->index();
122  const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>(genericDet);
123  assert(pixDet);
124  SiPixelRecHitCollection::FastFiller recHitsOnDetUnit(output, detid);
125  auto fc = hitsModuleStart_[gind];
126  auto lc = hitsModuleStart_[gind + 1];
127  auto nhits = lc - fc;
128 
129  assert(lc > fc);
130  LogDebug("SiPixelRecHitFromCUDA") << "in det " << gind << ": conv " << nhits << " hits from " << dsv.size()
131  << " legacy clusters" << ' ' << fc << ',' << lc;
132  if (nhits > maxHitsInModule)
133  edm::LogWarning("SiPixelRecHitFromCUDA") << fmt::sprintf(
134  "Too many clusters %d in module %d. Only the first %d hits will be converted", nhits, gind, maxHitsInModule);
136 
137  LogDebug("SiPixelRecHitFromCUDA") << "in det " << gind << "conv " << nhits << " hits from " << dsv.size()
138  << " legacy clusters" << ' ' << lc << ',' << fc;
139 
140  if (0 == nhits)
141  continue;
142  auto jnd = [&](int k) { return fc + k; };
143  assert(nhits <= dsv.size());
144  if (nhits != dsv.size()) {
145  edm::LogWarning("GPUHits2CPU") << "nhits!= nclus " << nhits << ' ' << dsv.size();
146  }
147  for (auto const& clust : dsv) {
148  assert(clust.originalId() >= 0);
149  assert(clust.originalId() < dsv.size());
150  if (clust.originalId() >= nhits)
151  continue;
152  auto ij = jnd(clust.originalId());
154  continue; // overflow...
155  LocalPoint lp(xl[ij], yl[ij]);
156  LocalError le(xe[ij], 0, ye[ij]);
158 
159  numberOfClusters++;
160 
161  /* cpu version.... (for reference)
162  std::tuple<LocalPoint, LocalError, SiPixelRecHitQuality::QualWordType> tuple = cpe_->getParameters( clust, *genericDet );
163  LocalPoint lp( std::get<0>(tuple) );
164  LocalError le( std::get<1>(tuple) );
165  SiPixelRecHitQuality::QualWordType rqw( std::get<2>(tuple) );
166  */
167 
168  // Create a persistent edm::Ref to the cluster
170  // Make a RecHit and add it to the DetSet
171  SiPixelRecHit hit(lp, le, rqw, *genericDet, cluster);
172  //
173  // Now save it =================
174  recHitsOnDetUnit.push_back(hit);
175  // =============================
176 
177  LogDebug("SiPixelRecHitFromCUDA") << "cluster " << numberOfClusters << " at " << lp << ' ' << le;
178 
179  } // <-- End loop on Clusters
180 
181  // LogDebug("SiPixelRecHitGPU")
182  LogDebug("SiPixelRecHitFromCUDA") << "found " << recHitsOnDetUnit.size() << " RecHits on " << detid;
183 
184  } // <-- End loop on DetUnits
185 
186  LogDebug("SiPixelRecHitFromCUDA") << "found " << numberOfDetUnits << " dets, " << numberOfClusters << " clusters";
187 
189 }
190 
ConfigurationDescriptions.h
SiPixelRecHitFromCUDA::hostPutToken_
const edm::EDPutTokenT< HMSstorage > hostPutToken_
Definition: SiPixelRecHitFromCUDA.cc:46
SiPixelRecHitFromCUDA::hitsToken_
const edm::EDGetTokenT< cms::cuda::Product< TrackingRecHit2DCUDA > > hitsToken_
Definition: SiPixelRecHitFromCUDA.cc:43
pixelCPEforGPU.h
Handle.h
gpuClustering::maxHitsInModule
constexpr uint32_t maxHitsInModule()
Definition: gpuClusteringConstants.h:27
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
TrackerGeometry.h
GeomDet
Definition: GeomDet.h:27
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
min
T min(T a, T b)
Definition: MathUtil.h:58
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::EDPutTokenT
Definition: EDPutToken.h:33
TrackingRecHit2DHeterogeneous.h
SiPixelRecHitFromCUDA::store32_
cms::cuda::host::unique_ptr< float[]> store32_
Definition: SiPixelRecHitFromCUDA.cc:49
SiPixelCluster.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
edmNew::makeRefTo
edm::Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type > makeRefTo(const HandleT &iHandle, typename HandleT::element_type::value_type::const_iterator itIter)
Definition: DetSetVectorNew.h:689
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
TrackingRecHit2DHeterogeneous
Definition: TrackingRecHit2DHeterogeneous.h:8
SiPixelRecHitFromCUDA::SiPixelRecHitFromCUDA
SiPixelRecHitFromCUDA(const edm::ParameterSet &iConfig)
Definition: SiPixelRecHitFromCUDA.cc:53
cms::cuda::assert
assert(be >=bs)
EDProducer.h
HostProduct.h
GeomDet::index
int index() const
Definition: GeomDet.h:83
SiPixelCluster
Pixel cluster – collection of neighboring pixels above threshold.
Definition: SiPixelCluster.h:28
SiPixelRecHitFromCUDA::acquire
void acquire(edm::Event const &iEvent, edm::EventSetup const &iSetup, edm::WaitingTaskWithArenaHolder waitingTaskHolder) override
Definition: SiPixelRecHitFromCUDA.cc:68
edmNew::DetSetVector::FastFiller::push_back
void push_back(data_type const &d)
Definition: DetSetVectorNew.h:274
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
SiPixelRecHit
Our base class.
Definition: SiPixelRecHit.h:23
edm::Ref
Definition: AssociativeIterator.h:58
DetId
Definition: DetId.h:17
edm::WaitingTaskWithArenaHolder
Definition: WaitingTaskWithArenaHolder.h:34
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SiPixelRecHitFromCUDA
Definition: SiPixelRecHitFromCUDA.cc:27
SiPixelRecHitFromCUDA::hitsModuleStart_
cms::cuda::host::unique_ptr< uint32_t[]> hitsModuleStart_
Definition: SiPixelRecHitFromCUDA.cc:50
SiPixelRecHitQuality::QualWordType
unsigned int QualWordType
Definition: SiPixelRecHitQuality.h:9
PixelGeomDetUnit
Definition: PixelGeomDetUnit.h:15
TrackingRecHit2DSOAView::maxHits
static constexpr uint32_t maxHits()
Definition: TrackingRecHit2DSOAView.h:17
benchmark_cfg.fc
fc
Definition: benchmark_cfg.py:15
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
dqmdumpme.k
k
Definition: dqmdumpme.py:60
Point3DBase< float, LocalTag >
ParameterSetDescription.h
nhits
Definition: HIMultiTrackSelector.h:42
gpuClustering::maxNumModules
constexpr uint16_t maxNumModules
Definition: gpuClusteringConstants.h:29
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
SiPixelRecHitFromCUDA::~SiPixelRecHitFromCUDA
~SiPixelRecHitFromCUDA() override=default
SiPixelRecHitFromCUDA::produce
void produce(edm::Event &iEvent, edm::EventSetup const &iSetup) override
Definition: SiPixelRecHitFromCUDA.cc:85
TrackerDigiGeometryRecord.h
SiPixelRecHitCollection.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
HostProduct
Definition: HostProduct.h:8
Event.h
LocalError
Definition: LocalError.h:12
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:58
SiPixelRecHitFromCUDA::rechitsPutToken_
const edm::EDPutTokenT< SiPixelRecHitCollection > rechitsPutToken_
Definition: SiPixelRecHitFromCUDA.cc:45
SiPixelRecHitFromCUDA::geomToken_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
Definition: SiPixelRecHitFromCUDA.cc:42
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord >
SiPixelRecHitFromCUDA::clusterToken_
const edm::EDGetTokenT< SiPixelClusterCollectionNew > clusterToken_
Definition: SiPixelRecHitFromCUDA.cc:44
InputTag.h
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
edmNew::DetSetVector::FastFiller::size
size_type size() const
Definition: DetSetVectorNew.h:267
cms::cuda::ScopedContextAcquire
Definition: ScopedContext.h:101
Product.h
edmNew::DetSetVector
Definition: DetSetNew.h:13
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
cms::cuda::host::unique_ptr
std::unique_ptr< T, impl::HostDeleter > unique_ptr
Definition: host_unique_ptr.h:21
cms::cuda::Product
Definition: Product.h:34
ScopedContext.h
PixelGeomDetUnit.h
ecalDigis_cff.cuda
cuda
Definition: ecalDigis_cff.py:35
EventSetup.h
SiPixelRecHitFromCUDA::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: SiPixelRecHitFromCUDA.cc:61
edmNew::DetSetVector::FastFiller
Definition: DetSetVectorNew.h:202
ParameterSet.h
SiPixelRecHitFromCUDA::nHits_
uint32_t nHits_
Definition: SiPixelRecHitFromCUDA.cc:48
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
DetSetVectorNew.h
edm::InputTag
Definition: InputTag.h:15
hit
Definition: SiStripHitEffFromCalibTree.cc:88
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21
TrackerGeometry
Definition: TrackerGeometry.h:14