CMS 3D CMS Logo

TestAlpakaESProducerA.cc
Go to the documentation of this file.
12 
20  public:
21  class HostBuffer {
22  public:
25 
27 
28  ConstBuffer buffer() const { return buffer_; }
29 
30  private:
32  };
33 
35  {
37  token_ = cc.consumes();
38  }
39  {
41  hostToken_ = cc.consumes();
42  }
43  }
44 
45  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
47  descriptions.addWithDefaultLabel(desc);
48  }
49 
50  std::optional<HostBuffer> produceHost(AlpakaESTestRecordA const& iRecord) {
51  auto const& input = iRecord.get(token_);
52 
53  int const size = 10;
54  // TODO: cached allocation?
55  auto buffer = cms::alpakatools::make_host_buffer<int[], Platform>(size);
56  for (int i = 0; i < size; ++i) {
57  buffer[i] = i * input.value();
58  }
59  return HostBuffer(std::move(buffer));
60  }
61 
62  std::optional<AlpakaESTestDataA> produceDevice(device::Record<AlpakaESTestRecordA> const& iRecord) {
63  auto hostHandle = iRecord.getTransientHandle(hostToken_);
64  // TODO: In principle associating the allocation to a queue is
65  // incorrect. Framework will keep the memory alive until the IOV
66  // ends. By that point all asynchronous activity using that
67  // memory has finished, and the memory could be marked as "free"
68  // in the allocator already by the host-side release of the
69  // memory. There could also be other, independent asynchronous
70  // activity going on that uses the same queue (since we don't
71  // retain the queue here), and at the time of host-side release
72  // the device-side release gets associated to the complemention
73  // of that activity (which has nothing to do with the memory here).
74  auto buffer =
75  cms::alpakatools::make_device_buffer<int[]>(iRecord.queue(), alpaka::getExtentProduct(hostHandle->buffer()));
76  alpaka::memcpy(iRecord.queue(), buffer, hostHandle->buffer());
78  }
79 
80  private:
83  };
84 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
85 
86 DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(TestAlpakaESProducerA);
87 // for the temporary host data
size
Write out results.
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
cms::alpakatools::const_device_buffer< DevHost, int[]> ConstBuffer
cms::alpakatools::device_buffer< DevHost, int[]> Buffer
std::optional< HostBuffer > produceHost(AlpakaESTestRecordA const &iRecord)
static std::string const input
Definition: EdmProvDump.cc:50
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::ESGetToken< HostBuffer, AlpakaESTestRecordA > hostToken_
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:102
auto setWhatProduced(T *iThis, edm::es::Label const &label={})
Definition: ESProducer.h:28
#define DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(type)
Definition: ModuleFactory.h:9
edm::ESGetToken< cms::alpakatest::ESTestDataA, AlpakaESTestRecordA > token_
std::optional< AlpakaESTestDataA > produceDevice(device::Record< AlpakaESTestRecordA > const &iRecord)
typename detail::buffer_type< TDev, T >::type device_buffer
Definition: memory.h:166
edm::ESTransientHandle< TProduct > getTransientHandle(edm::ESGetToken< TProduct, TDepRecord > const &iToken) const
Definition: Record.h:58
def move(src, dest)
Definition: eostools.py:511
alpaka::ViewConst< device_buffer< TDev, T > > const_device_buffer
Definition: memory.h:169