CMS 3D CMS Logo

EcalRawToDigiGPU.cc
Go to the documentation of this file.
14 
15 #include "DeclsForKernels.h"
16 #include "UnpackGPU.h"
17 
18 class EcalRawToDigiGPU : public edm::stream::EDProducer<edm::ExternalWork> {
19 public:
20  explicit EcalRawToDigiGPU(edm::ParameterSet const& ps);
21  ~EcalRawToDigiGPU() override = default;
23 
24 private:
26  void produce(edm::Event&, edm::EventSetup const&) override;
27 
28 private:
33 
35 
36  std::vector<int> fedsToUnpack_;
37 
41 };
42 
45 
46  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
47  std::vector<int> feds(54);
48  for (uint32_t i = 0; i < 54; ++i)
49  feds[i] = i + 601;
50  desc.add<std::vector<int>>("FEDs", feds);
51  desc.add<uint32_t>("maxChannelsEB", 61200);
52  desc.add<uint32_t>("maxChannelsEE", 14648);
53  desc.add<std::string>("digisLabelEB", "ebDigis");
54  desc.add<std::string>("digisLabelEE", "eeDigis");
55 
56  std::string label = "ecalRawToDigiGPU";
57  confDesc.add(label, desc);
58 }
59 
61  : rawDataToken_{consumes<FEDRawDataCollection>(ps.getParameter<edm::InputTag>("InputLabel"))},
62  digisEBToken_{produces<OutputProduct>(ps.getParameter<std::string>("digisLabelEB"))},
63  digisEEToken_{produces<OutputProduct>(ps.getParameter<std::string>("digisLabelEE"))},
64  eMappingToken_{esConsumes<ecal::raw::ElectronicsMappingGPU, EcalMappingElectronicsRcd>()},
65  fedsToUnpack_{ps.getParameter<std::vector<int>>("FEDs")} {
66  config_.maxChannelsEB = ps.getParameter<uint32_t>("maxChannelsEB");
67  config_.maxChannelsEE = ps.getParameter<uint32_t>("maxChannelsEE");
68 }
69 
71  edm::EventSetup const& setup,
73  // raii
74  cms::cuda::ScopedContextAcquire ctx{event.streamID(), std::move(holder), cudaState_};
75 
76  // conditions
78  auto const& eMappingProduct = eMappingHandle->getProduct(ctx.stream());
79 
80  // bundle up conditions
82 
83  // event data
85  event.getByToken(rawDataToken_, rawDataHandle);
86 
87  // scratch
88  ecal::raw::ScratchDataGPU scratchGPU = {cms::cuda::make_device_unique<uint32_t[]>(2, ctx.stream())};
89 
90  // make a first iteration over the FEDs to compute the total buffer size
91  uint32_t size = 0;
92  uint32_t feds = 0;
93  for (auto const& fed : fedsToUnpack_) {
94  auto const& data = rawDataHandle->FEDData(fed);
95  auto const nbytes = data.size();
96 
97  // skip empty FEDs
98  if (nbytes < globalFieds::EMPTYEVENTSIZE)
99  continue;
100 
101  size += nbytes;
102  ++feds;
103  }
104 
105  // input cpu data
106  ecal::raw::InputDataCPU inputCPU = {cms::cuda::make_host_unique<unsigned char[]>(size, ctx.stream()),
107  cms::cuda::make_host_unique<uint32_t[]>(feds, ctx.stream()),
108  cms::cuda::make_host_unique<int[]>(feds, ctx.stream())};
109 
110  // input data gpu
111  ecal::raw::InputDataGPU inputGPU = {cms::cuda::make_device_unique<unsigned char[]>(size, ctx.stream()),
112  cms::cuda::make_device_unique<uint32_t[]>(feds, ctx.stream()),
113  cms::cuda::make_device_unique<int[]>(feds, ctx.stream())};
114 
115  // output cpu
116  outputCPU_ = {cms::cuda::make_host_unique<uint32_t[]>(2, ctx.stream())};
117  // initialize the number of channels
118  outputCPU_.nchannels[0] = 0;
119  outputCPU_.nchannels[1] = 0;
120 
121  // output gpu
122  outputGPU_.allocate(config_, ctx.stream());
123 
124  // iterate over FEDs to fill the cpu buffer
125  uint32_t currentCummOffset = 0;
126  uint32_t counter = 0;
127  for (auto const& fed : fedsToUnpack_) {
128  auto const& data = rawDataHandle->FEDData(fed);
129  auto const nbytes = data.size();
130 
131  // skip empty FEDs
132  if (nbytes < globalFieds::EMPTYEVENTSIZE)
133  continue;
134 
135  // copy raw data into plain buffer
136  std::memcpy(inputCPU.data.get() + currentCummOffset, data.data(), nbytes);
137  // set the offset in bytes from the start
138  inputCPU.offsets[counter] = currentCummOffset;
139  inputCPU.feds[counter] = fed;
140 
141  // this is the current offset into the vector
142  currentCummOffset += nbytes;
143  ++counter;
144  }
145  assert(currentCummOffset == size);
146  assert(counter == feds);
147 
148  // unpack if at least one FED has data
149  if (counter > 0) {
151  inputCPU, inputGPU, outputGPU_, scratchGPU, outputCPU_, conditions, ctx.stream(), counter, currentCummOffset);
152  }
153 }
154 
157 
158  // get the number of channels
161 
164 
165  // reset ptrs that are carried as members
166  outputCPU_.nchannels.reset();
167 }
168 
size
Write out results.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void entryPoint(InputDataCPU const &, InputDataGPU &, OutputDataGPU &, ScratchDataGPU &, OutputDataCPU &, ConditionsProducts const &, cudaStream_t, uint32_t const, uint32_t const)
EcalRawToDigiGPU(edm::ParameterSet const &ps)
edm::ESGetToken< ecal::raw::ElectronicsMappingGPU, EcalMappingElectronicsRcd > eMappingToken_
host::impl::make_host_unique_selector< T >::non_array make_host_unique()
std::vector< int > fedsToUnpack_
static void fillDescriptions(edm::ConfigurationDescriptions &)
cms::cuda::host::unique_ptr< unsigned char[]> data
edm::EDPutTokenT< OutputProduct > digisEEToken_
assert(be >=bs)
void produce(edm::Event &, edm::EventSetup const &) override
char const * label
ecal::raw::OutputDataGPU outputGPU_
ecal::raw::ConfigurationParameters config_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
cms::cuda::ContextState cudaState_
ecal::raw::OutputDataCPU outputCPU_
DigisCollection<::calo::common::DevStoragePolicy > digisEE
DigisCollection<::calo::common::DevStoragePolicy > digisEB
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void acquire(edm::Event const &, edm::EventSetup const &, edm::WaitingTaskWithArenaHolder) override
cms::cuda::host::unique_ptr< uint32_t[]> offsets
~EcalRawToDigiGPU() override=default
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
static std::atomic< unsigned int > counter
cms::cuda::host::unique_ptr< int[]> feds
cms::cuda::host::unique_ptr< uint32_t[]> nchannels
edm::EDGetTokenT< FEDRawDataCollection > rawDataToken_
device::impl::make_device_unique_selector< T >::non_array make_device_unique(cudaStream_t stream)
void allocate(ConfigurationParameters const &config, cudaStream_t cudaStream)
Product const & getProduct(cudaStream_t) const
edm::EDPutTokenT< OutputProduct > digisEBToken_
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1