File indexing completed on 2024-04-06 12:15:44
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 TestCUDAProducerGPU : public edm::global::EDProducer<> {
0015 public:
0016 explicit TestCUDAProducerGPU(const edm::ParameterSet& iConfig);
0017 ~TestCUDAProducerGPU() override = default;
0018
0019 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0020
0021 void produce(edm::StreamID streamID, edm::Event& iEvent, edm::EventSetup const& iSetup) const override;
0022
0023 private:
0024 std::string const label_;
0025 edm::EDGetTokenT<cms::cuda::Product<cms::cudatest::Thing>> const srcToken_;
0026 edm::EDPutTokenT<cms::cuda::Product<cms::cudatest::Thing>> const dstToken_;
0027 TestCUDAProducerGPUKernel const gpuAlgo_;
0028 };
0029
0030 TestCUDAProducerGPU::TestCUDAProducerGPU(edm::ParameterSet const& iConfig)
0031 : label_(iConfig.getParameter<std::string>("@module_label")),
0032 srcToken_(consumes<cms::cuda::Product<cms::cudatest::Thing>>(iConfig.getParameter<edm::InputTag>("src"))),
0033 dstToken_(produces<cms::cuda::Product<cms::cudatest::Thing>>()) {}
0034
0035 void TestCUDAProducerGPU::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0036 edm::ParameterSetDescription desc;
0037 desc.add<edm::InputTag>("src", edm::InputTag())->setComment("Source of cms::cuda::Product<cms::cudatest::Thing>.");
0038 descriptions.addWithDefaultLabel(desc);
0039 descriptions.setComment(
0040 "This EDProducer is part of the TestCUDAProducer* family. It models a GPU algorithm this is not the first "
0041 "algorithm in the chain of the GPU EDProducers. Produces cms::cuda::Product<cms::cudatest::Thing>.");
0042 }
0043
0044 void TestCUDAProducerGPU::produce(edm::StreamID streamID, edm::Event& iEvent, edm::EventSetup const& iSetup) const {
0045 edm::LogVerbatim("TestCUDAProducerGPU") << label_ << " TestCUDAProducerGPU::produce begin event "
0046 << iEvent.id().event() << " stream " << iEvent.streamID();
0047
0048 auto const& in = iEvent.get(srcToken_);
0049 cms::cuda::ScopedContextProduce ctx{in};
0050 cms::cudatest::Thing const& input = ctx.get(in);
0051
0052 ctx.emplace(iEvent, dstToken_, cms::cudatest::Thing{gpuAlgo_.runAlgo(label_, input.get(), ctx.stream())});
0053
0054 edm::LogVerbatim("TestCUDAProducerGPU")
0055 << label_ << " TestCUDAProducerGPU::produce end event " << iEvent.id().event() << " stream " << iEvent.streamID();
0056 }
0057
0058 DEFINE_FWK_MODULE(TestCUDAProducerGPU);