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 "HeterogeneousCore/AlpakaCore/interface/alpaka/stream/SynchronizingEDProducer.h"
0007 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDPutToken.h"
0008 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0009 
0010 #include "TestAlgo.h"
0011 
0012 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0013   /**
0014    * This class demonstrates a stream EDProducer that
0015    * - produces a device EDProduct (that can get transferred to host automatically)
0016    * - synchronizes in a non-blocking way with the ExternalWork module
0017    *   ability (via the SynchronizingEDProcucer base class)
0018    */
0019   class TestAlpakaStreamSynchronizingProducerToDevice : public stream::SynchronizingEDProducer<> {
0020   public:
0021     TestAlpakaStreamSynchronizingProducerToDevice(edm::ParameterSet const& iConfig)
0022         : SynchronizingEDProducer<>(iConfig),
0023           putToken_{produces()},
0024           size_{iConfig.getParameter<edm::ParameterSet>("size").getParameter<int32_t>(
0025               EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE))} {}
0026 
0027     void acquire(device::Event const& iEvent, device::EventSetup const& iSetup) override {
0028       deviceProduct_ = std::make_unique<portabletest::TestDeviceCollection>(size_, iEvent.queue());
0029 
0030       // run the algorithm, potentially asynchronously
0031       algo_.fill(iEvent.queue(), *deviceProduct_);
0032     }
0033 
0034     void produce(device::Event& iEvent, device::EventSetup const& iSetup) override {
0035       iEvent.put(putToken_, std::move(deviceProduct_));
0036     }
0037 
0038     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0039       edm::ParameterSetDescription desc;
0040 
0041       edm::ParameterSetDescription psetSize;
0042       psetSize.add<int32_t>("alpaka_serial_sync");
0043       psetSize.add<int32_t>("alpaka_cuda_async");
0044       psetSize.add<int32_t>("alpaka_rocm_async");
0045       desc.add("size", psetSize);
0046 
0047       descriptions.addWithDefaultLabel(desc);
0048     }
0049 
0050   private:
0051     const device::EDPutToken<portabletest::TestDeviceCollection> putToken_;
0052     const int32_t size_;
0053 
0054     // implementation of the algorithm
0055     TestAlgo algo_;
0056 
0057     std::unique_ptr<portabletest::TestDeviceCollection> deviceProduct_;
0058   };
0059 
0060 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0061 
0062 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h"
0063 DEFINE_FWK_ALPAKA_MODULE(TestAlpakaStreamSynchronizingProducerToDevice);