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 
27 
28 template <typename TrackerTraits>
29 class SiPixelRecHitSoAFromCUDAT : public edm::stream::EDProducer<edm::ExternalWork> {
30 public:
31  explicit SiPixelRecHitSoAFromCUDAT(const edm::ParameterSet& iConfig);
32  ~SiPixelRecHitSoAFromCUDAT() override = default;
33 
34  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
38 
39 private:
40  void acquire(edm::Event const& iEvent,
41  edm::EventSetup const& iSetup,
42  edm::WaitingTaskWithArenaHolder waitingTaskHolder) override;
43  void produce(edm::Event& iEvent, edm::EventSetup const& iSetup) override;
44 
48 
49  uint32_t nHits_;
51 };
52 
53 template <typename TrackerTraits>
55  : hitsTokenGPU_(consumes(iConfig.getParameter<edm::InputTag>("pixelRecHitSrc"))),
56  hitsPutTokenCPU_(produces<HitsOnHost>()),
57  hostPutToken_(produces<HMSstorage>()) {}
58 
59 template <typename TrackerTraits>
62  desc.add<edm::InputTag>("pixelRecHitSrc", edm::InputTag("siPixelRecHitsPreSplittingCUDA"));
63 
64  descriptions.addWithDefaultLabel(desc);
65 }
66 
67 template <typename TrackerTraits>
69  edm::EventSetup const& iSetup,
70  edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
71  cms::cuda::Product<HitsOnDevice> const& inputDataWrapped = iEvent.get(hitsTokenGPU_);
72  cms::cuda::ScopedContextAcquire ctx{inputDataWrapped, std::move(waitingTaskHolder)};
73  auto const& inputData = ctx.get(inputDataWrapped);
74 
75  nHits_ = inputData.nHits();
76  hits_h_ = HitsOnHost(nHits_, ctx.stream());
77  cudaCheck(cudaMemcpyAsync(hits_h_.buffer().get(),
78  inputData.const_buffer().get(),
79  inputData.bufferSize(),
80  cudaMemcpyDeviceToHost,
81  ctx.stream())); // Copy data from Device to Host
82  LogDebug("SiPixelRecHitSoAFromCUDA") << "copying to cpu SoA" << inputData.nHits() << " Hits";
83 }
84 
85 template <typename TrackerTraits>
87  auto hmsp = std::make_unique<uint32_t[]>(TrackerTraits::numberOfModules + 1);
88 
89  if (nHits_ > 0)
90  std::copy(hits_h_.view().hitsModuleStart().begin(), hits_h_.view().hitsModuleStart().end(), hmsp.get());
91 
92  iEvent.emplace(hostPutToken_, std::move(hmsp));
93  iEvent.emplace(hitsPutTokenCPU_, std::move(hits_h_));
94 }
95 
98 
101 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
const edm::EDPutTokenT< HitsOnHost > hitsPutTokenCPU_
~SiPixelRecHitSoAFromCUDAT() override=default
constexpr uint16_t numberOfModules
void produce(edm::Event &iEvent, edm::EventSetup const &iSetup) override
int iEvent
Definition: GenABIO.cc:224
SiPixelRecHitSoAFromCUDAT(const edm::ParameterSet &iConfig)
const edm::EDGetTokenT< cms::cuda::Product< HitsOnDevice > > hitsTokenGPU_
const edm::EDPutTokenT< HMSstorage > hostPutToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void acquire(edm::Event const &iEvent, edm::EventSetup const &iSetup, edm::WaitingTaskWithArenaHolder waitingTaskHolder) override
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)