CMS 3D CMS Logo

EcalPhase2DigiToGPUProducer.cc
Go to the documentation of this file.
5 
9 
12 
13 #include "DeclsForKernelsPhase2.h"
14 
15 class EcalPhase2DigiToGPUProducer : public edm::stream::EDProducer<edm::ExternalWork> {
16 public:
18  ~EcalPhase2DigiToGPUProducer() override = default;
19  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
20 
21  void acquire(edm::Event const& event, edm::EventSetup const& setup, edm::WaitingTaskWithArenaHolder holder) override;
22  void produce(edm::Event& evt, edm::EventSetup const& setup) override;
23 
24 private:
28  uint32_t size_;
29 
31 
33 };
34 
37 
38  desc.add<edm::InputTag>("BarrelDigis", edm::InputTag("simEcalUnsuppressedDigis", ""));
39  desc.add<std::string>("digisLabelEB", "ebDigis");
40 
41  descriptions.addWithDefaultLabel(desc);
42 }
43 
45  : digiCollectionToken_(consumes<EBDigiCollectionPh2>(ps.getParameter<edm::InputTag>("BarrelDigis"))),
46  digisCollectionToken_(produces<cms::cuda::Product<ecal::DigisCollection<calo::common::DevStoragePolicy>>>(
47  ps.getParameter<std::string>("digisLabelEB"))) {}
48 
50  edm::EventSetup const& setup,
52  cms::cuda::ScopedContextAcquire ctx{event.streamID(), std::move(holder), cudaState_};
53 
54  //input data from event
55  const auto& pdigis = event.get(digiCollectionToken_);
56 
57  size_ = pdigis.size();
58 
59  digis_.size = size_;
60  //allocate device pointers for output
61  digis_.ids = cms::cuda::make_device_unique<uint32_t[]>(size_, ctx.stream());
62  digis_.data = cms::cuda::make_device_unique<uint16_t[]>(size_ * EcalDataFrame_Ph2::MAXSAMPLES, ctx.stream());
63 
64  //allocate host pointers for holding product data and id vectors
65  auto idstmp = cms::cuda::make_host_unique<uint32_t[]>(size_, ctx.stream());
66  auto datatmp = cms::cuda::make_host_unique<uint16_t[]>(size_ * EcalDataFrame_Ph2::MAXSAMPLES, ctx.stream());
67 
68  //iterate over digis
69  uint32_t i = 0;
70  for (const auto& pdigi : pdigis) {
71  const int nSamples = pdigi.size();
72  //assign id to output vector
73  idstmp.get()[i] = pdigi.id();
74  //iterate over sample in digi
75  for (int sample = 0; sample < nSamples; ++sample) {
76  //get samples from input digi
77  EcalLiteDTUSample thisSample = pdigi[sample];
78  //assign adc data to output
79  datatmp.get()[i * nSamples + sample] = thisSample.raw();
80  }
81  ++i;
82  }
83 
84  //copy output vectors into member variable device pointers for the output struct
85 
86  cudaCheck(
87  cudaMemcpyAsync(digis_.ids.get(), idstmp.get(), size_ * sizeof(uint32_t), cudaMemcpyHostToDevice, ctx.stream()));
88  cudaCheck(cudaMemcpyAsync(digis_.data.get(),
89  datatmp.get(),
90  size_ * EcalDataFrame_Ph2::MAXSAMPLES * sizeof(uint16_t),
91  cudaMemcpyHostToDevice,
92  ctx.stream()));
93 }
94 
96  //get cuda context state for producer
98 
99  //emplace output in the context
101 }
102 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
uint16_t raw() const
get the raw word
const edm::EDPutTokenT< cms::cuda::Product< ecal::DigisCollection< calo::common::DevStoragePolicy > > > digisCollectionToken_
void acquire(edm::Event const &event, edm::EventSetup const &setup, edm::WaitingTaskWithArenaHolder holder) override
ecal::DigisCollection<::calo::common::DevStoragePolicy > digis_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< EBDigiCollectionPh2 > digiCollectionToken_
static constexpr int MAXSAMPLES
Namespace of DDCMS conversion namespace.
Definition: common.py:1
~EcalPhase2DigiToGPUProducer() override=default
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void produce(edm::Event &evt, edm::EventSetup const &setup) override
HLT enums.
EcalPhase2DigiToGPUProducer(const edm::ParameterSet &ps)
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
def move(src, dest)
Definition: eostools.py:511
Definition: Common.h:9
Definition: event.py:1