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    * - 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(config.getParameter<edm::ESInputTag>("eventSetupSource"))),
0025           deviceToken_{produces()},
0026           deviceTokenMulti2_{produces()},
0027           deviceTokenMulti3_{produces()},
0028           size_{config.getParameter<edm::ParameterSet>("size").getParameter<int32_t>(
0029               EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE))},
0030           size2_{config.getParameter<edm::ParameterSet>("size").getParameter<int32_t>(
0031               EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE))},
0032           size3_{config.getParameter<edm::ParameterSet>("size").getParameter<int32_t>(
0033               EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE))} {}
0034 
0035     void produce(edm::StreamID, device::Event& iEvent, device::EventSetup const& iSetup) const override {
0036       [[maybe_unused]] auto const& esData = iSetup.getData(esToken_);
0037 
0038       portabletest::TestDeviceCollection deviceProduct{size_, iEvent.queue()};
0039       portabletest::TestDeviceMultiCollection2 deviceProductMulti2{{{size_, size2_}}, iEvent.queue()};
0040       portabletest::TestDeviceMultiCollection3 deviceProductMulti3{{{size_, size2_, size3_}}, iEvent.queue()};
0041 
0042       // run the algorithm, potentially asynchronously
0043       algo_.fill(iEvent.queue(), deviceProduct);
0044       algo_.fillMulti2(iEvent.queue(), deviceProductMulti2);
0045       algo_.fillMulti3(iEvent.queue(), deviceProductMulti3);
0046 
0047       iEvent.emplace(deviceToken_, std::move(deviceProduct));
0048       iEvent.emplace(deviceTokenMulti2_, std::move(deviceProductMulti2));
0049       iEvent.emplace(deviceTokenMulti3_, std::move(deviceProductMulti3));
0050     }
0051 
0052     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0053       edm::ParameterSetDescription desc;
0054       desc.add("eventSetupSource", edm::ESInputTag{});
0055 
0056       edm::ParameterSetDescription psetSize;
0057       psetSize.add<int32_t>("alpaka_serial_sync");
0058       psetSize.add<int32_t>("alpaka_cuda_async");
0059       psetSize.add<int32_t>("alpaka_rocm_async");
0060       desc.add("size", psetSize);
0061 
0062       descriptions.addWithDefaultLabel(desc);
0063     }
0064 
0065   private:
0066     const device::ESGetToken<AlpakaESTestDataADevice, AlpakaESTestRecordA> esToken_;
0067     const device::EDPutToken<portabletest::TestDeviceCollection> deviceToken_;
0068     const device::EDPutToken<portabletest::TestDeviceMultiCollection2> deviceTokenMulti2_;
0069     const device::EDPutToken<portabletest::TestDeviceMultiCollection3> deviceTokenMulti3_;
0070     const int32_t size_;
0071     const int32_t size2_;
0072     const int32_t size3_;
0073 
0074     // implementation of the algorithm
0075     TestAlgo algo_;
0076   };
0077 
0078 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0079 
0080 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h"
0081 DEFINE_FWK_ALPAKA_MODULE(TestAlpakaGlobalProducer);