Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-30 04:10:32

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         : putToken_{produces()},
0023           size_{iConfig.getParameter<edm::ParameterSet>("size").getParameter<int32_t>(
0024               EDM_STRINGIZE(ALPAKA_ACCELERATOR_NAMESPACE))} {}
0025 
0026     void acquire(device::Event const& iEvent, device::EventSetup const& iSetup) override {
0027       deviceProduct_ = std::make_unique<portabletest::TestDeviceCollection>(size_, iEvent.queue());
0028 
0029       // run the algorithm, potentially asynchronously
0030       algo_.fill(iEvent.queue(), *deviceProduct_);
0031     }
0032 
0033     void produce(device::Event& iEvent, device::EventSetup const& iSetup) override {
0034       iEvent.put(putToken_, std::move(deviceProduct_));
0035     }
0036 
0037     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0038       edm::ParameterSetDescription desc;
0039 
0040       edm::ParameterSetDescription psetSize;
0041       psetSize.add<int32_t>("alpaka_serial_sync");
0042       psetSize.add<int32_t>("alpaka_cuda_async");
0043       psetSize.add<int32_t>("alpaka_rocm_async");
0044       desc.add("size", psetSize);
0045 
0046       descriptions.addWithDefaultLabel(desc);
0047     }
0048 
0049   private:
0050     const device::EDPutToken<portabletest::TestDeviceCollection> putToken_;
0051     const int32_t size_;
0052 
0053     // implementation of the algorithm
0054     TestAlgo algo_;
0055 
0056     std::unique_ptr<portabletest::TestDeviceCollection> deviceProduct_;
0057   };
0058 
0059 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0060 
0061 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h"
0062 DEFINE_FWK_ALPAKA_MODULE(TestAlpakaStreamSynchronizingProducerToDevice);