Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-11 23:31:37

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