Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:44

0001 #include "CUDADataFormats/Common/interface/Product.h"
0002 #include "CUDADataFormats/PortableTestObjects/interface/TestDeviceCollection.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/stream/EDProducer.h"
0007 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0010 #include "FWCore/Utilities/interface/EDGetToken.h"
0011 #include "FWCore/Utilities/interface/InputTag.h"
0012 #include "FWCore/Utilities/interface/StreamID.h"
0013 #include "HeterogeneousCore/CUDACore/interface/ScopedContext.h"
0014 
0015 #include "TestAlgo.h"
0016 
0017 class TestPortableProducerCUDA : public edm::stream::EDProducer<> {
0018 public:
0019   TestPortableProducerCUDA(edm::ParameterSet const& config)
0020       : deviceToken_{produces()}, size_{config.getParameter<int32_t>("size")} {}
0021 
0022   void produce(edm::Event& event, edm::EventSetup const&) override {
0023     // create a context based on the EDM stream number
0024     cms::cuda::ScopedContextProduce ctx(event.streamID());
0025 
0026     // run the algorithm, potentially asynchronously
0027     cudatest::TestDeviceCollection deviceProduct{size_, ctx.stream()};
0028     algo_.fill(deviceProduct, ctx.stream());
0029 
0030     // put the asynchronous product into the event without waiting
0031     ctx.emplace(event, deviceToken_, std::move(deviceProduct));
0032   }
0033 
0034   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0035     edm::ParameterSetDescription desc;
0036     desc.add<int32_t>("size");
0037     descriptions.addWithDefaultLabel(desc);
0038   }
0039 
0040 private:
0041   const edm::EDPutTokenT<cms::cuda::Product<cudatest::TestDeviceCollection>> deviceToken_;
0042   const int32_t size_;
0043 
0044   // implementation of the algorithm
0045   cudatest::TestAlgo algo_;
0046 };
0047 
0048 #include "FWCore/Framework/interface/MakerMacros.h"
0049 DEFINE_FWK_MODULE(TestPortableProducerCUDA);