Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-01-20 02:57:44

0001 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0002 #include "FWCore/Utilities/interface/ESGetToken.h"
0003 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESProducer.h"
0004 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ModuleFactory.h"
0005 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0006 #include "HeterogeneousCore/AlpakaInterface/interface/host.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/alpaka/AlpakaESTestData.h"
0011 
0012 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0013   /**
0014    * This class demonstrates an ESProducer that uses the
0015    * PortableCollection-based data model, and that consumes a standard
0016    * host ESProduct and converts the data into PortableCollection, and
0017    * implicitly transfers the data product to device
0018    */
0019   class TestAlpakaESProducerA : public ESProducer {
0020   public:
0021     TestAlpakaESProducerA(edm::ParameterSet const& iConfig) : ESProducer(iConfig) {
0022       auto cc = setWhatProduced(this);
0023       token_ = cc.consumes();
0024     }
0025 
0026     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0027       edm::ParameterSetDescription desc;
0028       descriptions.addWithDefaultLabel(desc);
0029     }
0030 
0031     std::unique_ptr<AlpakaESTestDataAHost> produce(AlpakaESTestRecordA const& iRecord) {
0032       auto const& input = iRecord.get(token_);
0033 
0034       int const size = 10;
0035       // TODO: pinned allocation?
0036       // TODO: cached allocation?
0037       auto product = std::make_unique<AlpakaESTestDataAHost>(size, cms::alpakatools::host());
0038       for (int i = 0; i < size; ++i) {
0039         product->view()[i].z() = input.value() - i;
0040       }
0041       return product;
0042     }
0043 
0044   private:
0045     edm::ESGetToken<cms::alpakatest::ESTestDataA, AlpakaESTestRecordA> token_;
0046   };
0047 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0048 
0049 DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(TestAlpakaESProducerA);