Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/PortableTestObjects/interface/alpaka/TestDeviceCollection.h"
0002 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0005 #include "FWCore/Utilities/interface/InputTag.h"
0006 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/global/EDProducer.h"
0007 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDPutToken.h"
0008 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESGetToken.h"
0009 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0010 #include "HeterogeneousCore/AlpakaTest/interface/AlpakaESTestRecords.h"
0011 #include "HeterogeneousCore/AlpakaTest/interface/alpaka/AlpakaESTestData.h"
0012 
0013 #include "TestAlgo.h"
0014 
0015 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0016   /**
0017    * This class demonstrates a global EDProducer that
0018    * - consumes a device ESProduct
0019    * - consumes a device EDProduct
0020    * - produces a device EDProduct (that can get transferred to host automatically)
0021    */
0022   class TestAlpakaGlobalProducerE : public global::EDProducer<> {
0023   public:
0024     TestAlpakaGlobalProducerE(edm::ParameterSet const& config)
0025         : esToken_(esConsumes(config.getParameter<edm::ESInputTag>("eventSetupSource"))),
0026           getToken_(consumes(config.getParameter<edm::InputTag>("source"))),
0027           getTokenMulti2_(consumes(config.getParameter<edm::InputTag>("source"))),
0028           getTokenMulti3_(consumes(config.getParameter<edm::InputTag>("source"))),
0029           putToken_{produces()},
0030           putTokenMulti2_{produces()},
0031           putTokenMulti3_{produces()} {}
0032 
0033     void produce(edm::StreamID, device::Event& iEvent, device::EventSetup const& iSetup) const override {
0034       auto const& esData = iSetup.getData(esToken_);
0035       auto const& input = iEvent.get(getToken_);
0036       auto const& inputMulti2 = iEvent.get(getTokenMulti2_);
0037       auto const& inputMulti3 = iEvent.get(getTokenMulti3_);
0038 
0039       // run the algorithm, potentially asynchronously
0040       auto deviceProduct = algo_.update(iEvent.queue(), input, esData);
0041       auto deviceProductMulti2 = algo_.updateMulti2(iEvent.queue(), inputMulti2, esData);
0042       auto deviceProductMulti3 = algo_.updateMulti3(iEvent.queue(), inputMulti3, esData);
0043 
0044       iEvent.emplace(putToken_, std::move(deviceProduct));
0045       iEvent.emplace(putTokenMulti2_, std::move(deviceProductMulti2));
0046       iEvent.emplace(putTokenMulti3_, std::move(deviceProductMulti3));
0047     }
0048 
0049     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0050       edm::ParameterSetDescription desc;
0051       desc.add("eventSetupSource", edm::ESInputTag{});
0052       desc.add("source", edm::InputTag{});
0053 
0054       descriptions.addWithDefaultLabel(desc);
0055     }
0056 
0057   private:
0058     const device::ESGetToken<AlpakaESTestDataEDevice, AlpakaESTestRecordC> esToken_;
0059     const device::EDGetToken<portabletest::TestDeviceCollection> getToken_;
0060     const device::EDGetToken<portabletest::TestDeviceMultiCollection2> getTokenMulti2_;
0061     const device::EDGetToken<portabletest::TestDeviceMultiCollection3> getTokenMulti3_;
0062     const device::EDPutToken<portabletest::TestDeviceCollection> putToken_;
0063     const device::EDPutToken<portabletest::TestDeviceMultiCollection2> putTokenMulti2_;
0064     const device::EDPutToken<portabletest::TestDeviceMultiCollection3> putTokenMulti3_;
0065 
0066     // implementation of the algorithm
0067     TestAlgo algo_;
0068   };
0069 
0070 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0071 
0072 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h"
0073 DEFINE_FWK_ALPAKA_MODULE(TestAlpakaGlobalProducerE);