CMS 3D CMS Logo

EcalCPURecHitProducer.cc
Go to the documentation of this file.
1 //#define ECAL_RECO_CUDA_DEBUG
2 
3 #ifdef ECAL_RECO_CUDA_DEBUG
4 #include <iostream>
5 #endif
6 
7 // framework
9 
15 
17 
18 // algorithm specific
19 
21 
23 
24 class EcalCPURecHitProducer : public edm::stream::EDProducer<edm::ExternalWork> {
25 public:
26  explicit EcalCPURecHitProducer(edm::ParameterSet const& ps);
27  ~EcalCPURecHitProducer() override = default;
29 
30 private:
32  void produce(edm::Event&, edm::EventSetup const&) override;
33 
34 private:
39 
42 };
43 
46 
47  desc.add<edm::InputTag>("recHitsInLabelEB", edm::InputTag{"ecalRecHitProducerGPU", "EcalRecHitsEB"});
48  desc.add<edm::InputTag>("recHitsInLabelEE", edm::InputTag{"ecalRecHitProducerGPU", "EcalRecHitsEE"});
49  desc.add<std::string>("recHitsOutLabelEB", "EcalRecHitsEB");
50  desc.add<std::string>("recHitsOutLabelEE", "EcalRecHitsEE");
51  desc.add<bool>("containsTimingInformation", false);
52 
53  confDesc.addWithDefaultLabel(desc);
54 }
55 
57  : recHitsInEBToken_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("recHitsInLabelEB"))},
58  recHitsInEEToken_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("recHitsInLabelEE"))},
59  recHitsOutEBToken_{produces<OutputProduct>(ps.getParameter<std::string>("recHitsOutLabelEB"))},
60  recHitsOutEEToken_{produces<OutputProduct>(ps.getParameter<std::string>("recHitsOutLabelEE"))},
61  containsTimingInformation_{ps.getParameter<bool>("containsTimingInformation")} {}
62 
64  edm::EventSetup const& setup,
66  // retrieve data/ctx
67  auto const& ebRecHitsProduct = event.get(recHitsInEBToken_);
68  auto const& eeRecHitsProduct = event.get(recHitsInEEToken_);
69  cms::cuda::ScopedContextAcquire ctx{ebRecHitsProduct, std::move(taskHolder)};
70  auto const& ebRecHits = ctx.get(ebRecHitsProduct);
71  auto const& eeRecHits = ctx.get(eeRecHitsProduct);
72 
73  // resize the output buffers
74  recHitsEB_.resize(ebRecHits.size);
75  recHitsEE_.resize(eeRecHits.size);
76 
77 #ifdef ECAL_RECO_CUDA_DEBUG
78  std::cout << " [EcalCPURecHitProducer::acquire] ebRecHits.size = " << ebRecHits.size << std::endl;
79  std::cout << " [EcalCPURecHitProducer::acquire] eeRecHits.size = " << eeRecHits.size << std::endl;
80 #endif
81 
82  // enqeue transfers
83  cudaCheck(cudaMemcpyAsync(recHitsEB_.did.data(),
84  ebRecHits.did.get(),
85  recHitsEB_.did.size() * sizeof(uint32_t),
86  cudaMemcpyDeviceToHost,
87  ctx.stream()));
88  cudaCheck(cudaMemcpyAsync(recHitsEE_.did.data(),
89  eeRecHits.did.get(),
90  recHitsEE_.did.size() * sizeof(uint32_t),
91  cudaMemcpyDeviceToHost,
92  ctx.stream()));
93  //
94  // ./CUDADataFormats/EcalRecHitSoA/interface/RecoTypes.h:using StorageScalarType = float;
95  //
96 
97  cudaCheck(cudaMemcpyAsync(recHitsEB_.energy.data(),
98  ebRecHits.energy.get(),
100  cudaMemcpyDeviceToHost,
101  ctx.stream()));
102  cudaCheck(cudaMemcpyAsync(recHitsEE_.energy.data(),
103  eeRecHits.energy.get(),
105  cudaMemcpyDeviceToHost,
106  ctx.stream()));
107 
108  cudaCheck(cudaMemcpyAsync(recHitsEB_.chi2.data(),
109  ebRecHits.chi2.get(),
111  cudaMemcpyDeviceToHost,
112  ctx.stream()));
113  cudaCheck(cudaMemcpyAsync(recHitsEE_.chi2.data(),
114  eeRecHits.chi2.get(),
116  cudaMemcpyDeviceToHost,
117  ctx.stream()));
118 
119  cudaCheck(cudaMemcpyAsync(recHitsEB_.extra.data(),
120  ebRecHits.extra.get(),
121  recHitsEB_.extra.size() * sizeof(uint32_t),
122  cudaMemcpyDeviceToHost,
123  ctx.stream()));
124  cudaCheck(cudaMemcpyAsync(recHitsEE_.extra.data(),
125  eeRecHits.extra.get(),
126  recHitsEE_.extra.size() * sizeof(uint32_t),
127  cudaMemcpyDeviceToHost,
128  ctx.stream()));
129 
130  cudaCheck(cudaMemcpyAsync(recHitsEB_.flagBits.data(),
131  ebRecHits.flagBits.get(),
132  recHitsEB_.flagBits.size() * sizeof(uint32_t),
133  cudaMemcpyDeviceToHost,
134  ctx.stream()));
135  cudaCheck(cudaMemcpyAsync(recHitsEE_.flagBits.data(),
136  eeRecHits.flagBits.get(),
137  recHitsEE_.flagBits.size() * sizeof(uint32_t),
138  cudaMemcpyDeviceToHost,
139  ctx.stream()));
140 
141 #ifdef ECAL_RECO_CUDA_DEBUG
142  for (unsigned int ieb = 0; ieb < ebRecHits.size; ieb++) {
143  if (recHitsEB_.extra[ieb] != 0)
144  std::cout << " [ " << ieb << " :: " << ebRecHits.size << " ] [ " << recHitsEB_.did[ieb]
145  << " ] eb extra = " << recHitsEB_.extra[ieb] << std::endl;
146  }
147 
148  for (unsigned int ieb = 0; ieb < ebRecHits.size; ieb++) {
149  if (recHitsEB_.energy[ieb] != 0)
150  std::cout << " [ " << ieb << " :: " << ebRecHits.size << " ] [ " << recHitsEB_.did[ieb]
151  << " ] eb energy = " << recHitsEB_.energy[ieb] << std::endl;
152  }
153 
154  for (unsigned int iee = 0; iee < eeRecHits.size; iee++) {
155  if (recHitsEE_.energy[iee] != 0)
156  std::cout << " [ " << iee << " :: " << eeRecHits.size << " ] [ " << recHitsEE_.did[iee]
157  << " ] ee energy = " << recHitsEE_.energy[iee] << std::endl;
158  }
159 #endif
160 }
161 
163  // put into event
164  event.emplace(recHitsOutEBToken_, std::move(recHitsEB_));
165  event.emplace(recHitsOutEEToken_, std::move(recHitsEE_));
166 }
167 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< InputProduct > recHitsInEEToken_
void acquire(edm::Event const &, edm::EventSetup const &, edm::WaitingTaskWithArenaHolder) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
StoragePolicy::template StorageSelector< reco::StorageScalarType >::type chi2
Definition: EcalRecHit.h:25
edm::EDPutTokenT< OutputProduct > recHitsOutEBToken_
StoragePolicy::template StorageSelector< uint32_t >::type did
Definition: EcalRecHit.h:30
std::enable_if< std::is_same< U, ::calo::common::tags::Vec >::value, void >::type resize(size_t size)
Definition: EcalRecHit.h:33
static void fillDescriptions(edm::ConfigurationDescriptions &)
float StorageScalarType
Definition: RecoTypes.h:8
StoragePolicy::template StorageSelector< reco::StorageScalarType >::type energy
Definition: EcalRecHit.h:22
EcalCPURecHitProducer(edm::ParameterSet const &ps)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
~EcalCPURecHitProducer() override=default
edm::EDPutTokenT< OutputProduct > recHitsOutEEToken_
edm::EDGetTokenT< InputProduct > recHitsInEBToken_
void produce(edm::Event &, edm::EventSetup const &) override
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
StoragePolicy::template StorageSelector< uint32_t >::type extra
Definition: EcalRecHit.h:27
StoragePolicy::template StorageSelector< uint32_t >::type flagBits
Definition: EcalRecHit.h:29