Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:25

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/Frameworkfwd.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 #include "FWCore/Framework/interface/global/EDProducer.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0007 
0008 #include "CUDADataFormats/Common/interface/Product.h"
0009 #include "HeterogeneousCore/CUDACore/interface/ScopedContext.h"
0010 #include "HeterogeneousCore/CUDATest/interface/Thing.h"
0011 
0012 #include "TestCUDAProducerGPUKernel.h"
0013 
0014 class TestCUDAProducerGPUFirst : public edm::global::EDProducer<> {
0015 public:
0016   explicit TestCUDAProducerGPUFirst(edm::ParameterSet const& iConfig);
0017   ~TestCUDAProducerGPUFirst() override = default;
0018 
0019   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0020 
0021   void produce(edm::StreamID stream, edm::Event& iEvent, edm::EventSetup const& iSetup) const override;
0022 
0023 private:
0024   std::string const label_;
0025   edm::EDPutTokenT<cms::cuda::Product<cms::cudatest::Thing>> const dstToken_;
0026   TestCUDAProducerGPUKernel const gpuAlgo_;
0027 };
0028 
0029 TestCUDAProducerGPUFirst::TestCUDAProducerGPUFirst(edm::ParameterSet const& iConfig)
0030     : label_(iConfig.getParameter<std::string>("@module_label")),
0031       dstToken_{produces<cms::cuda::Product<cms::cudatest::Thing>>()} {}
0032 
0033 void TestCUDAProducerGPUFirst::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0034   edm::ParameterSetDescription desc;
0035   descriptions.addWithDefaultLabel(desc);
0036   descriptions.setComment(
0037       "This EDProducer is part of the TestCUDAProducer* family. It models a GPU algorithm this the first algorithm in "
0038       "the chain of the GPU EDProducers. Produces cms::cuda::Productcms::cudatest::Thing>.");
0039 }
0040 
0041 void TestCUDAProducerGPUFirst::produce(edm::StreamID streamID,
0042                                        edm::Event& iEvent,
0043                                        edm::EventSetup const& iSetup) const {
0044   edm::LogVerbatim("TestCUDAProducerGPUFirst") << label_ << " TestCUDAProducerGPUFirst::produce begin event "
0045                                                << iEvent.id().event() << " stream " << iEvent.streamID();
0046 
0047   cms::cuda::ScopedContextProduce ctx{streamID};
0048 
0049   cms::cuda::device::unique_ptr<float[]> output = gpuAlgo_.runAlgo(label_, ctx.stream());
0050   ctx.emplace(iEvent, dstToken_, std::move(output));
0051 
0052   edm::LogVerbatim("TestCUDAProducerGPUFirst") << label_ << " TestCUDAProducerGPUFirst::produce end event "
0053                                                << iEvent.id().event() << " stream " << iEvent.streamID();
0054 }
0055 
0056 DEFINE_FWK_MODULE(TestCUDAProducerGPUFirst);