CMS 3D CMS Logo

SiPixelDigisSoAFromCUDA.cc
Go to the documentation of this file.
13 
14 class SiPixelDigisSoAFromCUDA : public edm::stream::EDProducer<edm::ExternalWork> {
15 public:
16  explicit SiPixelDigisSoAFromCUDA(const edm::ParameterSet& iConfig);
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 
31 
32  int nDigis_;
33 };
34 
36  : digiGetToken_(consumes<cms::cuda::Product<SiPixelDigisCUDA>>(iConfig.getParameter<edm::InputTag>("src"))),
37  digiPutToken_(produces<SiPixelDigisSoA>()) {}
38 
41  desc.add<edm::InputTag>("src", edm::InputTag("siPixelClustersCUDA"));
42  descriptions.addWithDefaultLabel(desc);
43 }
44 
46  const edm::EventSetup& iSetup,
47  edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
48  // Do the transfer in a CUDA stream parallel to the computation CUDA stream
49  cms::cuda::ScopedContextAcquire ctx{iEvent.streamID(), std::move(waitingTaskHolder)};
50 
51  const auto& gpuDigis = ctx.get(iEvent, digiGetToken_);
52 
53  nDigis_ = gpuDigis.nDigis();
54  store_ = gpuDigis.copyAllToHostAsync(ctx.stream());
55 }
56 
58  // The following line copies the data from the pinned host memory to
59  // regular host memory. In principle that feels unnecessary (why not
60  // just use the pinned host memory?). There are a few arguments for
61  // doing it though
62  // - Now can release the pinned host memory back to the (caching) allocator
63  // * if we'd like to keep the pinned memory, we'd need to also
64  // keep the CUDA stream around as long as that, or allow pinned
65  // host memory to be allocated without a CUDA stream
66  // - What if a CPU algorithm would produce the same SoA? We can't
67  // use cudaMallocHost without a GPU...
68 
70 
71  iEvent.emplace(digiPutToken_, nDigis_, tmp_view.pdigi(), tmp_view.rawIdArr(), tmp_view.adc(), tmp_view.clus());
72 
73  store_.reset();
74 }
75 
76 // 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
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
Namespace of DDCMS conversion namespace.
cms::cuda::host::unique_ptr< uint16_t[]> store_
edm::EDGetTokenT< cms::cuda::Product< SiPixelDigisCUDA > > digiGetToken_
HLT enums.
std::unique_ptr< T, impl::HostDeleter > unique_ptr
~SiPixelDigisSoAFromCUDA() override=default
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
def move(src, dest)
Definition: eostools.py:511