CMS 3D CMS Logo

AlpakaESTestData.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_AlpakaTest_interface_AlpakaESTestData_h
2 #define HeterogeneousCore_AlpakaTest_interface_AlpakaESTestData_h
3 
10 
11 namespace cms::alpakatest {
12  // PortableCollection-based model
16 
17  // Template-over-device model
18  template <typename TDev>
20  public:
23 
25 
26  Buffer buffer() { return buffer_; }
27  ConstBuffer buffer() const { return buffer_; }
28  ConstBuffer const_buffer() const { return buffer_; }
29 
30  int const* data() const { return buffer_.data(); }
31  auto size() const { return alpaka::getExtentProduct(buffer_); }
32 
33  private:
35  };
36 
37  // Template-over-device model with PortableCollection members
38  // Demonstrates indirection from one PortableCollection to the other
39  template <typename TDev>
41  public:
44 
45  class ConstView {
46  public:
47  constexpr ConstView(typename ECollection::ConstView e, typename EDataCollection::ConstView data)
48  : eView_(e), dataView_(data) {}
49 
50  constexpr auto size() const { return eView_.metadata().size(); }
51  constexpr int val(int i) const { return eView_.val(i); }
52  constexpr int val2(int i) const { return dataView_.val2(eView_.ind(i)); }
53 
54  private:
55  typename ECollection::ConstView eView_;
56  typename EDataCollection::ConstView dataView_;
57  };
58 
59  AlpakaESTestDataE(size_t size, size_t dataSize) : e_(size), data_(dataSize) {}
60 
62 
63  ECollection const& e() const { return e_; }
64  EDataCollection const& data() const { return data_; }
65 
66  ConstView view() const { return const_view(); }
67  ConstView const_view() const { return ConstView(e_.const_view(), data_.const_view()); }
68 
69  private:
72  };
74 
75 } // namespace cms::alpakatest
76 
77 namespace cms::alpakatools {
78  // Explicit specializations are needed for the template-over-device model
79  //
80  // PortableCollection-based model gets these for free from PortableCollection itself
81 
82  template <>
83  struct CopyToDevice<cms::alpakatest::AlpakaESTestDataB<alpaka_common::DevHost>> {
84  template <typename TQueue>
86  // TODO: In principle associating the allocation to a queue is
87  // incorrect. Framework will keep the memory alive until the IOV
88  // ends. By that point all asynchronous activity using that
89  // memory has finished, and the memory could be marked as "free"
90  // in the allocator already by the host-side release of the
91  // memory. There could also be other, independent asynchronous
92  // activity going on that uses the same queue (since we don't
93  // retain the queue here), and at the time of host-side release
94  // the device-side release gets associated to the complemention
95  // of that activity (which has nothing to do with the memory here).
96  auto dstBuffer = cms::alpakatools::make_device_buffer<int[]>(queue, srcData.size());
97  alpaka::memcpy(queue, dstBuffer, srcData.buffer());
99  }
100  };
101 
102  template <>
104  template <typename TQueue>
105  static auto copyAsync(TQueue& queue, cms::alpakatest::AlpakaESTestDataEHost const& srcData) {
108  using TDevice = alpaka::Dev<TQueue>;
110  EDataCopy::copyAsync(queue, srcData.data()));
111  }
112  };
113 } // namespace cms::alpakatools
114 
115 #endif
AlpakaESTestDataE(ECollection e, EDataCollection data)
cms::alpakatools::const_device_buffer< TDev, int[]> ConstBuffer
PortableCollection< AlpakaESTestSoAE, TDev > ECollection
EDataCollection const & data() const
constexpr ConstView(typename ECollection::ConstView e, typename EDataCollection::ConstView data)
void copyAsync(device::unique_ptr< T > &dst, const host::unique_ptr< T > &src, cudaStream_t stream)
Definition: copyAsync.h:20
ECollection const & e() const
PortableCollection< AlpakaESTestSoAEData, TDev > EDataCollection
static auto copyAsync(TQueue &queue, cms::alpakatest::AlpakaESTestDataEHost const &srcData)
Namespace of DDCMS conversion namespace.
AlpakaESTestDataE(size_t size, size_t dataSize)
typename traits::PortableCollectionTrait< T, TDev >::CollectionType PortableCollection
cms::alpakatools::device_buffer< TDev, int[]> Buffer
static auto copyAsync(TQueue &queue, cms::alpakatest::AlpakaESTestDataB< alpaka_common::DevHost > const &srcData)
typename detail::buffer_type< TDev, T >::type device_buffer
Definition: memory.h:169
def move(src, dest)
Definition: eostools.py:511
alpaka::ViewConst< device_buffer< TDev, T > > const_device_buffer
Definition: memory.h:172