Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 #include <cmath>
0013 
0014 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0015   /**
0016    * This class demonstrates an ESProducer that uses the
0017    * PortableCollection-based data model, and that consumes a standard
0018    * host ESProduct and converts the data into PortableCollection, and
0019    * implicitly transfers the data product to device
0020    */
0021   class TestAlpakaESProducerE : public ESProducer {
0022   public:
0023     TestAlpakaESProducerE(edm::ParameterSet const& iConfig) : ESProducer(iConfig) {
0024       auto cc = setWhatProduced(this);
0025       token_ = cc.consumes();
0026     }
0027 
0028     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0029       edm::ParameterSetDescription desc;
0030       descriptions.addWithDefaultLabel(desc);
0031     }
0032 
0033     std::optional<AlpakaESTestDataEHost> produce(AlpakaESTestRecordC const& iRecord) {
0034       auto const& input = iRecord.get(token_);
0035 
0036       int const edatasize = 2;
0037       AlpakaESTestDataEHost::EDataCollection data(edatasize, cms::alpakatools::host());
0038       for (int i = 0; i < edatasize; ++i) {
0039         data.view()[i].val2() = i * 10 + 1;
0040       }
0041 
0042       int const esize = 5;
0043       // TODO: pinned allocation?
0044       // TODO: cached allocation?
0045       AlpakaESTestDataEHost::ECollection e(esize, cms::alpakatools::host());
0046       for (int i = 0; i < esize; ++i) {
0047         e.view()[i].val() = std::abs(input.value()) + i * 2;
0048         e.view()[i].ind() = i % edatasize;
0049       }
0050       return AlpakaESTestDataEHost(std::move(e), std::move(data));
0051     }
0052 
0053   private:
0054     edm::ESGetToken<cms::alpakatest::ESTestDataC, AlpakaESTestRecordC> token_;
0055   };
0056 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0057 
0058 DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(TestAlpakaESProducerE);