Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-30 23:27:57

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