CMS 3D CMS Logo

TestCUDAProducerGPUtoCPU.cc
Go to the documentation of this file.
7 
13 
15 
16 class TestCUDAProducerGPUtoCPU : public edm::stream::EDProducer<edm::ExternalWork> {
17 public:
18  explicit TestCUDAProducerGPUtoCPU(edm::ParameterSet const& iConfig);
19  ~TestCUDAProducerGPUtoCPU() override = default;
20 
21  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
22 
23  void acquire(edm::Event const& iEvent,
24  edm::EventSetup const& iSetup,
25  edm::WaitingTaskWithArenaHolder waitingTaskHolder) override;
26 
27  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
28 
29 private:
34 };
35 
37  : label_{iConfig.getParameter<std::string>("@module_label")},
38  srcToken_{consumes<cms::cuda::Product<cms::cudatest::Thing>>(iConfig.getParameter<edm::InputTag>("src"))},
39  dstToken_{produces<int>()} {}
40 
43  desc.add<edm::InputTag>("src", edm::InputTag())->setComment("Source for cms::cuda::Product<cms::cudatest::Thing>.");
44  descriptions.addWithDefaultLabel(desc);
45  descriptions.setComment(
46  "This EDProducer is part of the TestCUDAProducer* family. It models the GPU->CPU data transfer and formatting of "
47  "the data to legacy data format. Produces int, to be compatible with TestCUDAProducerCPU.");
48 }
49 
51  edm::EventSetup const& iSetup,
52  edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
53  edm::LogVerbatim("TestCUDAProducerGPUtoCPU") << label_ << " TestCUDAProducerGPUtoCPU::acquire begin event "
54  << iEvent.id().event() << " stream " << iEvent.streamID();
55 
56  auto const& in = iEvent.get(srcToken_);
57  cms::cuda::ScopedContextAcquire ctx{in, std::move(waitingTaskHolder)};
58  cms::cudatest::Thing const& device = ctx.get(in);
59 
60  buffer_ = cms::cuda::make_host_unique<float[]>(TestCUDAProducerGPUKernel::NUM_VALUES, ctx.stream());
61  // Enqueue async copy, continue in produce once finished
62  cudaCheck(cudaMemcpyAsync(buffer_.get(),
63  device.get(),
65  cudaMemcpyDeviceToHost,
66  ctx.stream()));
67 
68  edm::LogVerbatim("TestCUDAProducerGPUtoCPU") << label_ << " TestCUDAProducerGPUtoCPU::acquire end event "
69  << iEvent.id().event() << " stream " << iEvent.streamID();
70 }
71 
73  edm::LogVerbatim("TestCUDAProducerGPUtoCPU") << label_ << " TestCUDAProducerGPUtoCPU::produce begin event "
74  << iEvent.id().event() << " stream " << iEvent.streamID();
75 
76  int counter = 0;
77  for (int i = 0; i < TestCUDAProducerGPUKernel::NUM_VALUES; ++i) {
78  counter += buffer_[i];
79  }
80  buffer_.reset(); // not so nice, but no way around?
81 
82  iEvent.emplace(dstToken_, counter);
83 
84  edm::LogVerbatim("TestCUDAProducerGPUtoCPU")
85  << label_ << " TestCUDAProducerGPUtoCPU::produce end event " << iEvent.id().event() << " stream "
86  << iEvent.streamID() << " result " << counter;
87 }
88 
counter
Definition: counter.py:1
mps_fire.i
i
Definition: mps_fire.py:355
TestCUDAProducerGPUtoCPU::~TestCUDAProducerGPUtoCPU
~TestCUDAProducerGPUtoCPU() override=default
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
TestCUDAProducerGPUtoCPU::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: TestCUDAProducerGPUtoCPU.cc:72
edm::EDGetTokenT
Definition: EDGetToken.h:33
TestCUDAProducerGPUtoCPU::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: TestCUDAProducerGPUtoCPU.cc:41
edm::EDPutTokenT< int >
TestCUDAProducerGPUtoCPU::buffer_
cms::cuda::host::unique_ptr< float[]> buffer_
Definition: TestCUDAProducerGPUtoCPU.cc:33
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
TestCUDAProducerGPUtoCPU::TestCUDAProducerGPUtoCPU
TestCUDAProducerGPUtoCPU(edm::ParameterSet const &iConfig)
Definition: TestCUDAProducerGPUtoCPU.cc:36
TestCUDAProducerGPUKernel.h
edm::WaitingTaskWithArenaHolder
Definition: WaitingTaskWithArenaHolder.h:31
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
host_unique_ptr.h
TestCUDAProducerGPUtoCPU
Definition: TestCUDAProducerGPUtoCPU.cc:16
TestCUDAProducerGPUKernel::NUM_VALUES
static constexpr int NUM_VALUES
Definition: TestCUDAProducerGPUKernel.h:21
TestCUDAProducerGPUtoCPU::dstToken_
const edm::EDPutTokenT< int > dstToken_
Definition: TestCUDAProducerGPUtoCPU.cc:32
ParameterSetDescription.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
TestCUDAProducerGPUtoCPU::acquire
void acquire(edm::Event const &iEvent, edm::EventSetup const &iSetup, edm::WaitingTaskWithArenaHolder waitingTaskHolder) override
Definition: TestCUDAProducerGPUtoCPU.cc:50
edm::ConfigurationDescriptions::setComment
void setComment(std::string const &value)
Definition: ConfigurationDescriptions.cc:48
recoMuon::in
Definition: RecoMuonEnumerators.h:6
cms::cudatest::Thing
Definition: Thing.h:8
iEvent
int iEvent
Definition: GenABIO.cc:224
TestCUDAProducerGPUtoCPU::label_
const std::string label_
Definition: TestCUDAProducerGPUtoCPU.cc:30
TestCUDAProducerGPUtoCPU::srcToken_
const edm::EDGetTokenT< cms::cuda::Product< cms::cudatest::Thing > > srcToken_
Definition: TestCUDAProducerGPUtoCPU.cc:31
edm::LogVerbatim
Definition: MessageLogger.h:297
cudaCheck.h
edm::stream::EDProducer
Definition: EDProducer.h:38
counter
static std::atomic< unsigned int > counter
Definition: SharedResourceNames.cc:15
edm::EventSetup
Definition: EventSetup.h:57
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
cms::cuda::ScopedContextAcquire
Definition: ScopedContext.h:101
Product.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
cudaCheck
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:62
Frameworkfwd.h
cms::cudatest::Thing::get
const float * get() const
Definition: Thing.h:13
cms::cuda::host::unique_ptr
std::unique_ptr< T, impl::HostDeleter > unique_ptr
Definition: host_unique_ptr.h:21
ScopedContext.h
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