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 
TestCUDAProducerGPUEW::devicePtr_
cms::cuda::device::unique_ptr< float[]> devicePtr_
Definition: TestCUDAProducerGPUEW.cc:37
TestCUDAProducerGPUEW::hostData_
cms::cuda::host::noncached::unique_ptr< float > hostData_
Definition: TestCUDAProducerGPUEW.cc:38
TestCUDAProducerGPUEW::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: TestCUDAProducerGPUEW.cc:51
TestCUDAProducerGPUEW::ctxState_
cms::cuda::ContextState ctxState_
Definition: TestCUDAProducerGPUEW.cc:36
input
static const std::string input
Definition: EdmProvDump.cc:48
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
TestCUDAProducerGPUKernel::runAlgo
cms::cuda::device::unique_ptr< float[]> runAlgo(const std::string &label, cudaStream_t stream) const
Definition: TestCUDAProducerGPUKernel.h:27
cms::cuda::ScopedContextProduce
Definition: ScopedContext.h:149
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:47
TestCUDAProducerGPUEW::gpuAlgo_
TestCUDAProducerGPUKernel gpuAlgo_
Definition: TestCUDAProducerGPUEW.cc:35
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm::EDPutTokenT
Definition: EDPutToken.h:33
cms::cuda::host::noncached::unique_ptr
std::unique_ptr< T, impl::HostDeleter > unique_ptr
Definition: host_noncached_unique_ptr.h:23
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
TestCUDAProducerGPUKernel.h
host_noncached_unique_ptr.h
edm::WaitingTaskWithArenaHolder
Definition: WaitingTaskWithArenaHolder.h:34
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TestCUDAProducerGPUEW::~TestCUDAProducerGPUEW
~TestCUDAProducerGPUEW() override=default
Service.h
TestCUDAProducerGPUEW::TestCUDAProducerGPUEW
TestCUDAProducerGPUEW(edm::ParameterSet const &iConfig)
Definition: TestCUDAProducerGPUEW.cc:41
TestCUDAProducerGPUEW
Definition: TestCUDAProducerGPUEW.cc:19
TestCUDAProducerGPUEW::dstToken_
const edm::EDPutTokenT< cms::cuda::Product< cms::cudatest::Thing > > dstToken_
Definition: TestCUDAProducerGPUEW.cc:34
ParameterSetDescription.h
TestCUDAProducerGPUEW::label_
const std::string label_
Definition: TestCUDAProducerGPUEW.cc:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
TestCUDAProducerGPUEW::srcToken_
const edm::EDGetTokenT< cms::cuda::Product< cms::cudatest::Thing > > srcToken_
Definition: TestCUDAProducerGPUEW.cc:33
cms::cuda::ContextState
Definition: ContextState.h:15
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
edm::ConfigurationDescriptions::setComment
void setComment(std::string const &value)
Definition: ConfigurationDescriptions.cc:48
recoMuon::in
Definition: RecoMuonEnumerators.h:6
TestCUDAProducerGPUEW::produce
void produce(edm::Event &iEvent, edm::EventSetup const &iSetup) override
Definition: TestCUDAProducerGPUEW.cc:82
cms::cudatest::Thing
Definition: Thing.h:8
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
cudaCheck.h
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::EventSetup
Definition: EventSetup.h:58
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
TestCUDAProducerGPUKernel
Definition: TestCUDAProducerGPUKernel.h:19
CUDAService.h
cms::cuda::ScopedContextAcquire
Definition: ScopedContext.h:101
Product.h
ContextState.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
cudaCheck
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
TestCUDAProducerGPUEW::acquire
void acquire(edm::Event const &iEvent, edm::EventSetup const &iSetup, edm::WaitingTaskWithArenaHolder waitingTaskHolder) override
Definition: TestCUDAProducerGPUEW.cc:62
Frameworkfwd.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
ScopedContext.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Thing.h
ParameterSet.h
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87