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 "FWCore/Utilities/interface/stringize.h"
0007 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/global/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/alpaka/AlpakaESTestData.h"
0013 
0014 #include "TestAlgo.h"
0015 
0016 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0017   /**
0018    * This class is primarily for consuming AlpakaESTestDataEDevice
0019    * ESProduct. It also demonstrates a proof-of-concept for
0020    * backend-specific configuration parameters.
0021    */
0022   class TestAlpakaGlobalProducerOffset : public global::EDProducer<> {
0023   public:
0024     TestAlpakaGlobalProducerOffset(edm::ParameterSet const& config)
0025         : esToken_(esConsumes()),
0026           deviceToken_{produces()},
0027           x_(config.getParameter<edm::ParameterSet>("xvalue").getParameter<double>(
0028               EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE))) {}
0029 
0030     void produce(edm::StreamID, device::Event& iEvent, device::EventSetup const& iSetup) const override {
0031       auto const& esData = iSetup.getData(esToken_);
0032 
0033       portabletest::TestDeviceCollection deviceProduct{esData->metadata().size(), iEvent.queue()};
0034 
0035       // run the algorithm, potentially asynchronously
0036       algo_.fill(iEvent.queue(), deviceProduct, x_);
0037 
0038       iEvent.emplace(deviceToken_, std::move(deviceProduct));
0039     }
0040 
0041     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0042       edm::ParameterSetDescription desc;
0043 
0044       // TODO: if this becomes an accepted pattern, we could look into
0045       // simplifying the definition (also this use case has additional
0046       // constraints not in a general PSet)
0047       edm::ParameterSetDescription psetX;
0048       psetX.add<double>("alpaka_serial_sync", 0.);
0049       psetX.add<double>("alpaka_cuda_async", 0.);
0050       psetX.add<double>("alpaka_rocm_async", 0.);
0051       desc.add("xvalue", psetX);
0052 
0053       descriptions.addWithDefaultLabel(desc);
0054     }
0055 
0056   private:
0057     device::ESGetToken<AlpakaESTestDataADevice, AlpakaESTestRecordA> const esToken_;
0058     device::EDPutToken<portabletest::TestDeviceCollection> const deviceToken_;
0059 
0060     TestAlgo const algo_{};
0061 
0062     double const x_;
0063   };
0064 
0065 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0066 
0067 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h"
0068 DEFINE_FWK_ALPAKA_MODULE(TestAlpakaGlobalProducerOffset);