CMS 3D CMS Logo

TestCUDAProducerGPUEW.cc
Go to the documentation of this file.
8 
16 
18 
19 class TestCUDAProducerGPUEW : public edm::stream::EDProducer<edm::ExternalWork> {
20 public:
21  explicit TestCUDAProducerGPUEW(edm::ParameterSet const& iConfig);
22  ~TestCUDAProducerGPUEW() override = default;
23 
24  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
25 
26  void acquire(edm::Event const& iEvent,
27  edm::EventSetup const& iSetup,
28  edm::WaitingTaskWithArenaHolder waitingTaskHolder) override;
29  void produce(edm::Event& iEvent, edm::EventSetup const& iSetup) override;
30 
31 private:
39 };
40 
42  : label_{iConfig.getParameter<std::string>("@module_label")},
43  srcToken_{consumes<cms::cuda::Product<cms::cudatest::Thing>>(iConfig.getParameter<edm::InputTag>("src"))},
44  dstToken_{produces<cms::cuda::Product<cms::cudatest::Thing>>()} {
46  if (cs->enabled()) {
47  hostData_ = cms::cuda::make_host_noncached_unique<float>();
48  }
49 }
50 
53  desc.add<edm::InputTag>("src", edm::InputTag());
54  descriptions.addWithDefaultLabel(desc);
55  descriptions.setComment(
56  "This EDProducer is part of the TestCUDAProducer* family. It models a GPU algorithm this is not the first "
57  "algorithm in the chain of the GPU EDProducers, and that transfers some data from GPU to CPU and thus needs to "
58  "synchronize GPU and CPU. The synchronization is implemented with the ExternalWork extension. Produces "
59  "cms::cuda::Product<cms::cuda::Thing>.");
60 }
61 
63  edm::EventSetup const& iSetup,
64  edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
65  edm::LogVerbatim("TestCUDAProducerGPUEW") << label_ << " TestCUDAProducerGPUEW::acquire begin event "
66  << iEvent.id().event() << " stream " << iEvent.streamID();
67 
68  auto const& in = iEvent.get(srcToken_);
69  cms::cuda::ScopedContextAcquire ctx{in, std::move(waitingTaskHolder), ctxState_};
70  cms::cudatest::Thing const& input = ctx.get(in);
71 
72  devicePtr_ = gpuAlgo_.runAlgo(label_, input.get(), ctx.stream());
73  // Mimick the need to transfer some of the GPU data back to CPU to
74  // be used for something within this module, or to be put in the
75  // event.
76  cudaCheck(
77  cudaMemcpyAsync(hostData_.get(), devicePtr_.get() + 10, sizeof(float), cudaMemcpyDeviceToHost, ctx.stream()));
78  edm::LogVerbatim("TestCUDAProducerGPUEW") << label_ << " TestCUDAProducerGPUEW::acquire end event "
79  << iEvent.id().event() << " stream " << iEvent.streamID();
80 }
81 
83  edm::LogVerbatim("TestCUDAProducerGPUEW")
84  << label_ << " TestCUDAProducerGPUEW::produce begin event " << iEvent.id().event() << " stream "
85  << iEvent.streamID() << " 10th element " << *hostData_;
86 
88 
89  ctx.emplace(iEvent, dstToken_, std::move(devicePtr_));
90 
91  edm::LogVerbatim("TestCUDAProducerGPUEW") << label_ << " TestCUDAProducerGPUEW::produce end event "
92  << iEvent.id().event() << " stream " << iEvent.streamID();
93 }
94 
Log< level::Info, true > LogVerbatim
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void acquire(edm::Event const &iEvent, edm::EventSetup const &iSetup, edm::WaitingTaskWithArenaHolder waitingTaskHolder) override
TestCUDAProducerGPUEW(edm::ParameterSet const &iConfig)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< T, impl::HostDeleter > unique_ptr
cms::cuda::device::unique_ptr< float[]> devicePtr_
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
static std::string const input
Definition: EdmProvDump.cc:47
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
~TestCUDAProducerGPUEW() override=default
void setComment(std::string const &value)
edm::EDPutTokenT< cms::cuda::Product< cms::cudatest::Thing > > const dstToken_
cms::cuda::host::noncached::unique_ptr< float > hostData_
TestCUDAProducerGPUKernel gpuAlgo_
cms::cuda::device::unique_ptr< float[]> runAlgo(const std::string &label, cudaStream_t stream) const
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
void produce(edm::Event &iEvent, edm::EventSetup const &iSetup) override
edm::EDGetTokenT< cms::cuda::Product< cms::cudatest::Thing > > const srcToken_
cms::cuda::ContextState ctxState_
def move(src, dest)
Definition: eostools.py:511