CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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;
23 
24 private:
26  void produce(edm::Event&, edm::EventSetup const&) override;
27 
28 private:
33 
35 
36  const uint32_t maxFedSize_;
37  std::vector<int> fedsToUnpack_;
38 
42 };
43 
46 
47  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
48  desc.add<uint32_t>("maxFedSize", ecal::raw::nbytes_per_fed_max);
49  std::vector<int> feds(54);
50  for (uint32_t i = 0; i < 54; ++i)
51  feds[i] = i + 601;
52  desc.add<std::vector<int>>("FEDs", feds);
53  desc.add<uint32_t>("maxChannelsEB", 61200);
54  desc.add<uint32_t>("maxChannelsEE", 14648);
55  desc.add<std::string>("digisLabelEB", "ebDigis");
56  desc.add<std::string>("digisLabelEE", "eeDigis");
57 
58  std::string label = "ecalRawToDigiGPU";
59  confDesc.add(label, desc);
60 }
61 
63  : rawDataToken_{consumes<FEDRawDataCollection>(ps.getParameter<edm::InputTag>("InputLabel"))},
64  digisEBToken_{produces<OutputProduct>(ps.getParameter<std::string>("digisLabelEB"))},
65  digisEEToken_{produces<OutputProduct>(ps.getParameter<std::string>("digisLabelEE"))},
66  eMappingToken_{esConsumes<ecal::raw::ElectronicsMappingGPU, EcalMappingElectronicsRcd>()},
67  maxFedSize_{ps.getParameter<uint32_t>("maxFedSize")},
68  fedsToUnpack_{ps.getParameter<std::vector<int>>("FEDs")} {
69  config_.maxChannelsEB = ps.getParameter<uint32_t>("maxChannelsEB");
70  config_.maxChannelsEE = ps.getParameter<uint32_t>("maxChannelsEE");
71 }
72 
74 
76  edm::EventSetup const& setup,
78  // raii
79  cms::cuda::ScopedContextAcquire ctx{event.streamID(), std::move(holder), cudaState_};
80 
81  // conditions
83  auto const& eMappingProduct = eMappingHandle->getProduct(ctx.stream());
84 
85  // bundle up conditions
87 
88  // event data
90  event.getByToken(rawDataToken_, rawDataHandle);
91 
92  // scratch
93  ecal::raw::ScratchDataGPU scratchGPU = {cms::cuda::make_device_unique<uint32_t[]>(2, ctx.stream())};
94 
95  // input cpu data
96  ecal::raw::InputDataCPU inputCPU = {
97  cms::cuda::make_host_unique<unsigned char[]>(ecal::raw::nfeds_max * maxFedSize_, ctx.stream()),
98  cms::cuda::make_host_unique<uint32_t[]>(ecal::raw::nfeds_max, ctx.stream()),
100 
101  // input data gpu
102  ecal::raw::InputDataGPU inputGPU = {
103  cms::cuda::make_device_unique<unsigned char[]>(ecal::raw::nfeds_max * maxFedSize_, ctx.stream()),
104  cms::cuda::make_device_unique<uint32_t[]>(ecal::raw::nfeds_max, ctx.stream()),
106 
107  // output cpu
108  outputCPU_ = {cms::cuda::make_host_unique<uint32_t[]>(2, ctx.stream())};
109  // initialize the number of channels
110  outputCPU_.nchannels[0] = 0;
111  outputCPU_.nchannels[1] = 0;
112 
113  // output gpu
114  outputGPU_.allocate(config_, ctx.stream());
115 
116  // iterate over feds
117  // TODO: another idea
118  // - loop over all feds to unpack and enqueue cuda memcpy
119  // - accumulate the sizes
120  // - after the loop launch cuda memcpy for sizes
121  // - enqueue the kernel
122  uint32_t currentCummOffset = 0;
123  uint32_t counter = 0;
124  for (auto const& fed : fedsToUnpack_) {
125  auto const& data = rawDataHandle->FEDData(fed);
126  auto const nbytes = data.size();
127 
128  // skip empty feds
129  if (nbytes < ecal::raw::empty_event_size)
130  continue;
131 
132  // copy raw data into plain buffer
133  std::memcpy(inputCPU.data.get() + currentCummOffset, data.data(), nbytes);
134  // set the offset in bytes from the start
135  inputCPU.offsets[counter] = currentCummOffset;
136  inputCPU.feds[counter] = fed;
137 
138  // this is the current offset into the vector
139  currentCummOffset += nbytes;
140  ++counter;
141  }
142 
143  // unpack if at least one FED has data
144  if (counter > 0) {
146  inputCPU, inputGPU, outputGPU_, scratchGPU, outputCPU_, conditions, ctx.stream(), counter, currentCummOffset);
147  }
148 }
149 
152 
153  // get the number of channels
154  outputGPU_.digisEB.size = outputCPU_.nchannels[0];
155  outputGPU_.digisEE.size = outputCPU_.nchannels[1];
156 
157  ctx.emplace(event, digisEBToken_, std::move(outputGPU_.digisEB));
158  ctx.emplace(event, digisEEToken_, std::move(outputGPU_.digisEE));
159 
160  // reset ptrs that are carried as members
161  outputCPU_.nchannels.reset();
162 }
163 
constexpr uint32_t nbytes_per_fed_max
void entryPoint(InputDataCPU const &, InputDataGPU &, OutputDataGPU &, ScratchDataGPU &, OutputDataCPU &, ConditionsProducts const &, cudaStream_t, uint32_t const, uint32_t const)
EcalRawToDigiGPU(edm::ParameterSet const &ps)
const uint32_t maxFedSize_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ESGetToken< ecal::raw::ElectronicsMappingGPU, EcalMappingElectronicsRcd > eMappingToken_
constexpr uint32_t nfeds_max
std::vector< int > fedsToUnpack_
static void fillDescriptions(edm::ConfigurationDescriptions &)
edm::EDPutTokenT< OutputProduct > digisEEToken_
constexpr auto empty_event_size
void produce(edm::Event &, edm::EventSetup const &) override
char const * label
ecal::raw::OutputDataGPU outputGPU_
def move
Definition: eostools.py:511
ecal::raw::ConfigurationParameters config_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
cms::cuda::ContextState cudaState_
ecal::raw::OutputDataCPU outputCPU_
DigisCollection<::calo::common::DevStoragePolicy > digisEE
DigisCollection<::calo::common::DevStoragePolicy > digisEB
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void acquire(edm::Event const &, edm::EventSetup const &, edm::WaitingTaskWithArenaHolder) override
~EcalRawToDigiGPU() override
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
static std::atomic< unsigned int > counter
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)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
void allocate(ConfigurationParameters const &config, cudaStream_t cudaStream)
host::impl::make_host_unique_selector< T >::non_array make_host_unique(cudaStream_t stream)
edm::EDPutTokenT< OutputProduct > digisEBToken_