Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:42

0001 #include "FWCore/Framework/interface/ESTransientHandle.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/Utilities/interface/ESGetToken.h"
0004 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESProducer.h"
0005 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ModuleFactory.h"
0006 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0007 #include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
0008 #include "HeterogeneousCore/AlpakaTest/interface/AlpakaESTestRecords.h"
0009 #include "HeterogeneousCore/AlpakaTest/interface/ESTestData.h"
0010 #include "HeterogeneousCore/AlpakaTest/interface/AlpakaESTestData.h"
0011 
0012 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0013   /**
0014    * This class demonstrates an ESProducer that uses the
0015    * template-over-device data model, and that consumes a standard
0016    * host ESProduct and converts the data into an Alpaka buffer that
0017    * is then moved into an object of a class that is templated over
0018    * the device type, and implicitly transfers the data product to
0019    * device
0020    *
0021    * This class also tests the explicit label for ESProducts works
0022    */
0023   class TestAlpakaESProducerB : public ESProducer {
0024   public:
0025     TestAlpakaESProducerB(edm::ParameterSet const& iConfig) : ESProducer(iConfig) {
0026       auto cc = setWhatProduced(this, iConfig.getParameter<std::string>("explicitLabel"));
0027       token_ = cc.consumes();
0028     }
0029 
0030     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0031       edm::ParameterSetDescription desc;
0032       desc.add("explicitLabel", std::string{});
0033       descriptions.addWithDefaultLabel(desc);
0034     }
0035 
0036     std::optional<cms::alpakatest::AlpakaESTestDataB<DevHost>> produce(AlpakaESTestRecordB const& iRecord) {
0037       auto const& input = iRecord.get(token_);
0038 
0039       int const size = 5;
0040       // TODO: cached allocation?
0041       auto buffer = cms::alpakatools::make_host_buffer<int[], Platform>(size);
0042       for (int i = 0; i < size; ++i) {
0043         buffer[i] = i + input.value();
0044       }
0045       return cms::alpakatest::AlpakaESTestDataB<DevHost>(std::move(buffer));
0046     }
0047 
0048   private:
0049     edm::ESGetToken<cms::alpakatest::ESTestDataB, AlpakaESTestRecordB> token_;
0050   };
0051 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0052 
0053 DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(TestAlpakaESProducerB);