CMS 3D CMS Logo

PortableObject.h
Go to the documentation of this file.
1 #ifndef DataFormats_Portable_interface_PortableObject_h
2 #define DataFormats_Portable_interface_PortableObject_h
3 
4 #include <type_traits>
5 
6 #include <alpaka/alpaka.hpp>
7 
12 
13 namespace traits {
14 
15  // trait for a generic struct-based product
16  template <typename T, typename TDev, typename = std::enable_if_t<alpaka::isDevice<TDev>>>
19  };
20 
21  // specialise for host device
22  template <typename T>
25  };
26 
27 } // namespace traits
28 
29 // type alias for a generic struct-based product
30 template <typename T, typename TDev, typename = std::enable_if_t<alpaka::isDevice<TDev>>>
32 
33 // define how to copy PortableObject between host and device
34 namespace cms::alpakatools {
35  template <typename TProduct, typename TDevice>
36  struct CopyToHost<PortableDeviceObject<TProduct, TDevice>> {
37  template <typename TQueue>
38  static auto copyAsync(TQueue& queue, PortableDeviceObject<TProduct, TDevice> const& srcData) {
40  alpaka::memcpy(queue, dstData.buffer(), srcData.buffer());
41  return dstData;
42  }
43  };
44 
45  template <typename TProduct>
46  struct CopyToDevice<PortableHostObject<TProduct>> {
47  template <typename TQueue>
48  static auto copyAsync(TQueue& queue, PortableHostObject<TProduct> const& srcData) {
49  using TDevice = typename alpaka::trait::DevType<TQueue>::type;
51  alpaka::memcpy(queue, dstData.buffer(), srcData.buffer());
52  return dstData;
53  }
54  };
55 } // namespace cms::alpakatools
56 
57 #endif // DataFormats_Portable_interface_PortableObject_h
typename traits::PortableObjectTrait< T, TDev >::ProductType PortableObject
static auto copyAsync(TQueue &queue, PortableHostObject< TProduct > const &srcData)
static auto copyAsync(TQueue &queue, PortableDeviceObject< TProduct, TDevice > const &srcData)
alpaka::DevCpu DevHost
Definition: config.h:37
long double T