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 
15 // This header is not used by PortableCollection, but is included here to automatically
16 // provide its content to users of ALPAKA_ACCELERATOR_NAMESPACE::PortableCollection.
18 
20 
21 #if defined ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
22  // ... or any other CPU-based accelerators
23 
24  // generic SoA-based product in host memory
25  template <typename T>
27 
28 #else
29 
30  // generic SoA-based product in device memory
31  template <typename T>
33 
34 #endif // ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
35 
36 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
37 
38 namespace traits {
39 
40  // specialise the trait for the device provided by the ALPAKA_ACCELERATOR_NAMESPACE
41  template <typename T>
44  };
45 
46 } // namespace traits
47 
48 namespace cms::alpakatools {
49  template <typename TLayout, typename TDevice>
50  struct CopyToHost<PortableDeviceCollection<TLayout, TDevice>> {
51  template <typename TQueue>
52  static auto copyAsync(TQueue& queue, PortableDeviceCollection<TLayout, TDevice> const& srcData) {
53  PortableHostCollection<TLayout> dstData(srcData->metadata().size(), queue);
54  alpaka::memcpy(queue, dstData.buffer(), srcData.buffer());
55  return dstData;
56  }
57  };
58 
59  template <typename TLayout>
61  template <typename TQueue>
62  static auto copyAsync(TQueue& queue, PortableHostCollection<TLayout> const& srcData) {
63  using TDevice = typename alpaka::trait::DevType<TQueue>::type;
64  PortableDeviceCollection<TLayout, TDevice> dstData(srcData->metadata().size(), queue);
65  alpaka::memcpy(queue, dstData.buffer(), srcData.buffer());
66  return dstData;
67  }
68  };
69 } // namespace cms::alpakatools
70 
71 #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)
typename traits::PortableCollectionTrait< T, TDev >::CollectionType PortableCollection
long double T