CMS 3D CMS Logo

TestAlpakaTranscriber.cc
Go to the documentation of this file.
1 #include <alpaka/alpaka.hpp>
2 
4 #include "DataFormats/PortableTestObjects/interface/TestHostCollection.h"
18 
20 
21  class TestAlpakaTranscriber : public edm::stream::EDProducer<edm::ExternalWork> {
22  public:
24  : deviceToken_{consumes(config.getParameter<edm::InputTag>("source"))}, hostToken_{produces()} {}
25 
27  // create a context reusing the same device and queue as the producer of the input collection
28  auto const& input = event.get(deviceToken_);
30 
31  portabletest::TestDeviceCollection const& deviceProduct = ctx.get(input);
32 
33  // allocate a host product based on the metadata of the device product
34  hostProduct_ = portabletest::TestHostCollection{deviceProduct->metadata().size(), ctx.queue()};
35 
36  // FIXME find a way to avoid the copy when the device product is actually a wrapped host prodict
37 
38  // copy the content of the device product to the host product
39  alpaka::memcpy(ctx.queue(), hostProduct_.buffer(), deviceProduct.const_buffer());
40 
41  // do not wait for the asynchronous operation to complete
42  }
43 
44  void produce(edm::Event& event, edm::EventSetup const&) override {
45  // produce() is called once the asynchronous operation has completed, so there is no need for an explicit wait
46  event.emplace(hostToken_, std::move(hostProduct_));
47  }
48 
49  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
51  desc.add<edm::InputTag>("source");
52  descriptions.addWithDefaultLabel(desc);
53  }
54 
55  private:
58 
59  // hold the output product between acquire() and produce()
61  };
62 
63 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
64 
66 DEFINE_FWK_ALPAKA_MODULE(TestAlpakaTranscriber);
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: config.py:1
static std::string const input
Definition: EdmProvDump.cc:50
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< cms::alpakatools::Product< Queue, portabletest::TestDeviceCollection > > deviceToken_
const edm::EDPutTokenT< portabletest::TestHostCollection > hostToken_
void acquire(edm::Event const &event, edm::EventSetup const &setup, edm::WaitingTaskWithArenaHolder task) override
void produce(edm::Event &event, edm::EventSetup const &) override
#define DEFINE_FWK_ALPAKA_MODULE(name)
Definition: MakerMacros.h:9
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1