CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiPixelDigisSoAFromCUDA.cc
Go to the documentation of this file.
13 
14 class SiPixelDigisSoAFromCUDA : public edm::stream::EDProducer<edm::ExternalWork> {
15 public:
17  ~SiPixelDigisSoAFromCUDA() override = default;
18 
19  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
20 
21 private:
22  void acquire(const edm::Event& iEvent,
23  const edm::EventSetup& iSetup,
24  edm::WaitingTaskWithArenaHolder waitingTaskHolder) override;
25  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
26 
29 
34 
35  int nDigis_;
36 };
37 
39  : digiGetToken_(consumes<cms::cuda::Product<SiPixelDigisCUDA>>(iConfig.getParameter<edm::InputTag>("src"))),
40  digiPutToken_(produces<SiPixelDigisSoA>()) {}
41 
44  desc.add<edm::InputTag>("src", edm::InputTag("siPixelClustersCUDA"));
45  descriptions.addWithDefaultLabel(desc);
46 }
47 
49  const edm::EventSetup& iSetup,
50  edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
51  // Do the transfer in a CUDA stream parallel to the computation CUDA stream
52  cms::cuda::ScopedContextAcquire ctx{iEvent.streamID(), std::move(waitingTaskHolder)};
53 
54  const auto& gpuDigis = ctx.get(iEvent, digiGetToken_);
55 
56  nDigis_ = gpuDigis.nDigis();
57  pdigi_ = gpuDigis.pdigiToHostAsync(ctx.stream());
58  rawIdArr_ = gpuDigis.rawIdArrToHostAsync(ctx.stream());
59  adc_ = gpuDigis.adcToHostAsync(ctx.stream());
60  clus_ = gpuDigis.clusToHostAsync(ctx.stream());
61 }
62 
64  // The following line copies the data from the pinned host memory to
65  // regular host memory. In principle that feels unnecessary (why not
66  // just use the pinned host memory?). There are a few arguments for
67  // doing it though
68  // - Now can release the pinned host memory back to the (caching) allocator
69  // * if we'd like to keep the pinned memory, we'd need to also
70  // keep the CUDA stream around as long as that, or allow pinned
71  // host memory to be allocated without a CUDA stream
72  // - What if a CPU algorithm would produce the same SoA? We can't
73  // use cudaMallocHost without a GPU...
74  iEvent.emplace(digiPutToken_, nDigis_, pdigi_.get(), rawIdArr_.get(), adc_.get(), clus_.get());
75 
76  pdigi_.reset();
77  rawIdArr_.reset();
78  adc_.reset();
79  clus_.reset();
80 }
81 
82 // define as framework plugin
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
void acquire(const edm::Event &iEvent, const edm::EventSetup &iSetup, edm::WaitingTaskWithArenaHolder waitingTaskHolder) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
cms::cuda::host::unique_ptr< uint32_t[]> pdigi_
cms::cuda::host::unique_ptr< int32_t[]> clus_
SiPixelDigisSoAFromCUDA(const edm::ParameterSet &iConfig)
edm::EDPutTokenT< SiPixelDigisSoA > digiPutToken_
int iEvent
Definition: GenABIO.cc:224
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
def move
Definition: eostools.py:511
ParameterDescriptionBase * add(U const &iLabel, T const &value)
cms::cuda::host::unique_ptr< uint32_t[]> rawIdArr_
OrphanHandle< PROD > emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
Definition: Event.h:433
edm::EDGetTokenT< cms::cuda::Product< SiPixelDigisCUDA > > digiGetToken_
StreamID streamID() const
Definition: Event.h:98
std::unique_ptr< T, impl::HostDeleter > unique_ptr
~SiPixelDigisSoAFromCUDA() override=default
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
cms::cuda::host::unique_ptr< uint16_t[]> adc_