Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-07 02:51:59

0001 #include "DataFormats/Portable/interface/Product.h"
0002 #include "DataFormats/PortableTestObjects/interface/alpaka/TestDeviceCollection.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/stream/EDProducer.h"
0007 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0010 #include "FWCore/ServiceRegistry/interface/Service.h"
0011 #include "FWCore/Utilities/interface/EDGetToken.h"
0012 #include "FWCore/Utilities/interface/InputTag.h"
0013 #include "FWCore/Utilities/interface/StreamID.h"
0014 #include "HeterogeneousCore/AlpakaCore/interface/ScopedContext.h"
0015 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0016 #include "HeterogeneousCore/AlpakaServices/interface/alpaka/AlpakaService.h"
0017 
0018 #include "TestAlgo.h"
0019 
0020 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0021 
0022   class TestAlpakaProducer : public edm::stream::EDProducer<> {
0023   public:
0024     TestAlpakaProducer(edm::ParameterSet const& config)
0025         : deviceToken_{produces()}, size_{config.getParameter<int32_t>("size")} {}
0026 
0027     void beginStream(edm::StreamID) override {
0028       edm::Service<ALPAKA_TYPE_ALIAS(AlpakaService)> service;
0029       if (not service->enabled()) {
0030         throw cms::Exception("Configuration") << ALPAKA_TYPE_ALIAS_NAME(AlpakaService) << " is disabled.";
0031       }
0032     }
0033 
0034     void produce(edm::Event& event, edm::EventSetup const&) override {
0035       // create a context based on the EDM stream number
0036       cms::alpakatools::ScopedContextProduce<Queue> ctx(event.streamID());
0037 
0038       // run the algorithm, potentially asynchronously
0039       portabletest::TestDeviceCollection deviceProduct{size_, ctx.queue()};
0040       algo_.fill(ctx.queue(), deviceProduct);
0041 
0042       // put the asynchronous product into the event without waiting
0043       ctx.emplace(event, deviceToken_, std::move(deviceProduct));
0044     }
0045 
0046     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0047       edm::ParameterSetDescription desc;
0048       desc.add<int32_t>("size");
0049       descriptions.addWithDefaultLabel(desc);
0050     }
0051 
0052   private:
0053     const edm::EDPutTokenT<cms::alpakatools::Product<Queue, portabletest::TestDeviceCollection>> deviceToken_;
0054     const int32_t size_;
0055 
0056     // implementation of the algorithm
0057     TestAlgo algo_;
0058   };
0059 
0060 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0061 
0062 #include "HeterogeneousCore/AlpakaCore/interface/MakerMacros.h"
0063 DEFINE_FWK_ALPAKA_MODULE(TestAlpakaProducer);