CMS 3D CMS Logo

PortableCollection.h
Go to the documentation of this file.
1 #ifndef DataFormats_Portable_interface_PortableCollection_h
2 #define DataFormats_Portable_interface_PortableCollection_h
3 
4 #include <alpaka/alpaka.hpp>
5 
10 
11 namespace traits {
12 
13  // trait for a generic SoA-based product
14  template <typename T, typename TDev, typename = std::enable_if_t<alpaka::isDevice<TDev>>>
17  };
18 
19  // specialise for host device
20  template <typename T>
23  };
24 
25  // trait for a generic multi-SoA-based product
26  template <typename TDev, typename T0, typename... Args>
28  using CollectionType = PortableDeviceMultiCollection<TDev, T0, Args...>;
29  };
30 
31  // specialise for host device
32  template <typename T0, typename... Args>
35  };
36 
37 } // namespace traits
38 
39 // type alias for a generic SoA-based product
40 template <typename T, typename TDev, typename = std::enable_if_t<alpaka::isDevice<TDev>>>
42 
43 // type alias for a generic SoA-based product
44 template <typename TDev, typename T0, typename... Args>
45 using PortableMultiCollection = typename traits::PortableMultiCollectionTrait<TDev, T0, Args...>::CollectionType;
46 
47 // define how to copy PortableCollection between host and device
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 TDev, typename T0, typename... Args>
60  struct CopyToHost<PortableDeviceMultiCollection<TDev, T0, Args...>> {
61  template <typename TQueue>
62  static auto copyAsync(TQueue& queue, PortableDeviceMultiCollection<TDev, T0, Args...> const& srcData) {
63  PortableHostMultiCollection<T0, Args...> dstData(srcData.sizes(), queue);
64  alpaka::memcpy(queue, dstData.buffer(), srcData.buffer());
65  return dstData;
66  }
67  };
68 
69  template <typename TLayout>
71  template <typename TQueue>
72  static auto copyAsync(TQueue& queue, PortableHostCollection<TLayout> const& srcData) {
73  using TDevice = typename alpaka::trait::DevType<TQueue>::type;
74  PortableDeviceCollection<TLayout, TDevice> dstData(srcData->metadata().size(), queue);
75  alpaka::memcpy(queue, dstData.buffer(), srcData.buffer());
76  return dstData;
77  }
78  };
79 
80  template <typename TDev, typename T0, typename... Args>
81  struct CopyToDevice<PortableHostMultiCollection<TDev, T0, Args...>> {
82  template <typename TQueue>
83  static auto copyAsync(TQueue& queue, PortableHostMultiCollection<TDev, T0, Args...> const& srcData) {
84  using TDevice = typename alpaka::trait::DevType<TQueue>::type;
85  PortableDeviceMultiCollection<TDev, T0, Args...> dstData(srcData.sizes(), queue);
86  alpaka::memcpy(queue, dstData.buffer(), srcData.buffer());
87  return dstData;
88  }
89  };
90 } // namespace cms::alpakatools
91 
92 #endif // DataFormats_Portable_interface_PortableCollection_h
static auto copyAsync(TQueue &queue, PortableHostMultiCollection< TDev, T0, Args... > const &srcData)
typename traits::PortableMultiCollectionTrait< TDev, T0, Args... >::CollectionType PortableMultiCollection
static auto copyAsync(TQueue &queue, PortableDeviceCollection< TLayout, TDevice > const &srcData)
static auto copyAsync(TQueue &queue, PortableHostCollection< TLayout > const &srcData)
static auto copyAsync(TQueue &queue, PortableDeviceMultiCollection< TDev, T0, Args... > const &srcData)
typename traits::PortableCollectionTrait< T, TDev >::CollectionType PortableCollection
alpaka::DevCpu DevHost
Definition: config.h:37
long double T