Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-11-24 00:02:23

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    * - produces a device EDProduct (that can get transferred to host automatically)
0020    */
0021   class TestAlpakaGlobalProducer : public global::EDProducer<> {
0022   public:
0023     TestAlpakaGlobalProducer(edm::ParameterSet const& config)
0024         : esToken_(esConsumes()), deviceToken_{produces()}, size_{config.getParameter<int32_t>("size")} {}
0025 
0026     void produce(edm::StreamID, device::Event& iEvent, device::EventSetup const& iSetup) const override {
0027       [[maybe_unused]] auto const& esData = iSetup.getData(esToken_);
0028 
0029       portabletest::TestDeviceCollection deviceProduct{size_, alpaka::getDev(iEvent.queue())};
0030 
0031       // run the algorithm, potentially asynchronously
0032       algo_.fill(iEvent.queue(), deviceProduct);
0033 
0034       iEvent.emplace(deviceToken_, std::move(deviceProduct));
0035     }
0036 
0037     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0038       edm::ParameterSetDescription desc;
0039       desc.add<int32_t>("size");
0040       descriptions.addWithDefaultLabel(desc);
0041     }
0042 
0043   private:
0044     const device::ESGetToken<AlpakaESTestDataA, AlpakaESTestRecordA> esToken_;
0045     const device::EDPutToken<portabletest::TestDeviceCollection> deviceToken_;
0046     const int32_t size_;
0047 
0048     // implementation of the algorithm
0049     TestAlgo algo_;
0050   };
0051 
0052 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0053 
0054 #include "HeterogeneousCore/AlpakaCore/interface/MakerMacros.h"
0055 DEFINE_FWK_ALPAKA_MODULE(TestAlpakaGlobalProducer);