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 "DataFormats/TestObjects/interface/ToyProducts.h"
0003 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0006 #include "FWCore/Utilities/interface/InputTag.h"
0007 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/stream/EDProducer.h"
0008 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDPutToken.h"
0009 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESGetToken.h"
0010 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0011 #include "HeterogeneousCore/AlpakaTest/interface/AlpakaESTestRecords.h"
0012 #include "HeterogeneousCore/AlpakaTest/interface/AlpakaESTestData.h"
0013 
0014 #include "TestAlgo.h"
0015 
0016 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0017   /**
0018    * This class demonstrates a stream EDProducer that
0019    * - consumes a host EDProduct
0020    * - consumes a device ESProduct
0021    * - produces a device EDProduct (that can get transferred to host automatically)
0022    */
0023   class TestAlpakaStreamProducer : public stream::EDProducer<> {
0024   public:
0025     TestAlpakaStreamProducer(edm::ParameterSet const& config) : size_{config.getParameter<int32_t>("size")} {
0026       getToken_ = consumes(config.getParameter<edm::InputTag>("source"));
0027       esToken_ = esConsumes();
0028       devicePutToken_ = produces();
0029     }
0030 
0031     void produce(device::Event& iEvent, device::EventSetup const& iSetup) override {
0032       [[maybe_unused]] auto inpData = iEvent.getHandle(getToken_);
0033       [[maybe_unused]] auto const& esData = iSetup.getData(esToken_);
0034 
0035       auto deviceProduct = std::make_unique<portabletest::TestDeviceCollection>(size_, alpaka::getDev(iEvent.queue()));
0036 
0037       // run the algorithm, potentially asynchronously
0038       algo_.fill(iEvent.queue(), *deviceProduct);
0039 
0040       iEvent.put(devicePutToken_, std::move(deviceProduct));
0041     }
0042 
0043     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0044       edm::ParameterSetDescription desc;
0045       desc.add<edm::InputTag>("source");
0046       desc.add<int32_t>("size");
0047       descriptions.addWithDefaultLabel(desc);
0048     }
0049 
0050   private:
0051     edm::EDGetTokenT<edmtest::IntProduct> getToken_;
0052     device::ESGetToken<cms::alpakatest::AlpakaESTestDataB<Device>, AlpakaESTestRecordB> esToken_;
0053     device::EDPutToken<portabletest::TestDeviceCollection> devicePutToken_;
0054     const int32_t size_;
0055 
0056     // implementation of the algorithm
0057     TestAlgo algo_;
0058   };
0059 
0060 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0061 
0062 #include "HeterogeneousCore/AlpakaCore/interface/MakerMacros.h"
0063 DEFINE_FWK_ALPAKA_MODULE(TestAlpakaStreamProducer);