CMS 3D CMS Logo

SiPixelRecHitSoAFromCUDA.cc
Go to the documentation of this file.
1 #include <cuda_runtime.h>
2 
3 #include <fmt/printf.h>
4 
26 
27 class SiPixelRecHitSoAFromCUDA : public edm::stream::EDProducer<edm::ExternalWork> {
28 public:
29  explicit SiPixelRecHitSoAFromCUDA(const edm::ParameterSet& iConfig);
30  ~SiPixelRecHitSoAFromCUDA() override = default;
31 
32  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
34 
35 private:
36  void acquire(edm::Event const& iEvent,
37  edm::EventSetup const& iSetup,
38  edm::WaitingTaskWithArenaHolder waitingTaskHolder) override;
39  void produce(edm::Event& iEvent, edm::EventSetup const& iSetup) override;
40 
44 
45  uint32_t nHits_;
46  uint32_t nMaxModules_;
47 
51 };
52 
54  : hitsTokenGPU_(
55  consumes<cms::cuda::Product<TrackingRecHit2DGPU>>(iConfig.getParameter<edm::InputTag>("pixelRecHitSrc"))),
56  hitsPutTokenCPU_(produces<TrackingRecHit2DCPU>()),
57  hostPutToken_(produces<HMSstorage>()) {}
58 
61  desc.add<edm::InputTag>("pixelRecHitSrc", edm::InputTag("siPixelRecHitsPreSplittingCUDA"));
62  descriptions.addWithDefaultLabel(desc);
63 }
64 
66  edm::EventSetup const& iSetup,
67  edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
68  cms::cuda::Product<TrackingRecHit2DGPU> const& inputDataWrapped = iEvent.get(hitsTokenGPU_);
69  cms::cuda::ScopedContextAcquire ctx{inputDataWrapped, std::move(waitingTaskHolder)};
70  auto const& inputData = ctx.get(inputDataWrapped);
71 
72  nHits_ = inputData.nHits();
73  LogDebug("SiPixelRecHitSoAFromCUDA") << "copying to cpu SoA" << inputData.nHits() << " Hits";
74 
75  if (0 == nHits_)
76  return;
77  nMaxModules_ = inputData.nMaxModules();
78  store32_ = inputData.store32ToHostAsync(ctx.stream());
79  store16_ = inputData.store16ToHostAsync(ctx.stream());
80  hitsModuleStart_ = inputData.hitsModuleStartToHostAsync(ctx.stream());
81 }
82 
84  auto hmsp = std::make_unique<uint32_t[]>(nMaxModules_ + 1);
85 
86  if (nHits_ > 0)
87  std::copy(hitsModuleStart_.get(), hitsModuleStart_.get() + nMaxModules_ + 1, hmsp.get());
88 
89  iEvent.emplace(hostPutToken_, std::move(hmsp));
90  iEvent.emplace(hitsPutTokenCPU_, store32_.get(), store16_.get(), hitsModuleStart_.get(), nHits_);
91 }
92 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
~SiPixelRecHitSoAFromCUDA() override=default
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDPutTokenT< TrackingRecHit2DCPU > hitsPutTokenCPU_
void produce(edm::Event &iEvent, edm::EventSetup const &iSetup) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
const edm::EDPutTokenT< HMSstorage > hostPutToken_
void acquire(edm::Event const &iEvent, edm::EventSetup const &iSetup, edm::WaitingTaskWithArenaHolder waitingTaskHolder) override
const edm::EDGetTokenT< cms::cuda::Product< TrackingRecHit2DGPU > > hitsTokenGPU_
cms::cuda::host::unique_ptr< uint16_t[]> store16_
Namespace of DDCMS conversion namespace.
HLT enums.
SiPixelRecHitSoAFromCUDA(const edm::ParameterSet &iConfig)
std::unique_ptr< T, impl::HostDeleter > unique_ptr
cms::cuda::host::unique_ptr< float[]> store32_
cms::cuda::host::unique_ptr< uint32_t[]> hitsModuleStart_
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)