CMS 3D CMS Logo

PortableCollection.h
Go to the documentation of this file.
1 #ifndef DataFormats_Portable_interface_alpaka_PortableDeviceCollection_h
2 #define DataFormats_Portable_interface_alpaka_PortableDeviceCollection_h
3 
4 #include <optional>
5 
6 #include <alpaka/alpaka.hpp>
7 
14 
16 
17 #if defined ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
18  // ... or any other CPU-based accelerators
19 
20  // generic SoA-based product in host memory
21  template <typename T>
23 
24 #else
25 
26  // generic SoA-based product in device memory
27  template <typename T>
29 
30 #endif // ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
31 
32 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
33 
34 namespace traits {
35 
36  // specialise the trait for the device provided by the ALPAKA_ACCELERATOR_NAMESPACE
37  template <typename T>
40  };
41 
42 } // namespace traits
43 
44 namespace cms::alpakatools {
45  template <typename TLayout, typename TDevice>
46  struct CopyToHost<PortableDeviceCollection<TLayout, TDevice>> {
47  template <typename TQueue>
48  static auto copyAsync(TQueue& queue, PortableDeviceCollection<TLayout, TDevice> const& srcData) {
49  PortableHostCollection<TLayout> dstData(srcData->metadata().size(), queue);
50  alpaka::memcpy(queue, dstData.buffer(), srcData.buffer());
51  return dstData;
52  }
53  };
54 
55  template <typename TLayout>
57  template <typename TQueue>
58  static auto copyAsync(TQueue& queue, PortableHostCollection<TLayout> const& srcData) {
59  using TDevice = typename alpaka::trait::DevType<TQueue>::type;
60  PortableDeviceCollection<TLayout, TDevice> dstData(srcData->metadata().size(), queue);
61  alpaka::memcpy(queue, dstData.buffer(), srcData.buffer());
62  return dstData;
63  }
64  };
65 } // namespace cms::alpakatools
66 
67 #endif // DataFormats_Portable_interface_alpaka_PortableDeviceCollection_h
static auto copyAsync(TQueue &queue, PortableDeviceCollection< TLayout, TDevice > const &srcData)
static auto copyAsync(TQueue &queue, PortableHostCollection< TLayout > const &srcData)
long double T