Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-11-24 00:02:10

0001 #ifndef DataFormats_Portable_interface_alpaka_PortableDeviceCollection_h
0002 #define DataFormats_Portable_interface_alpaka_PortableDeviceCollection_h
0003 
0004 #include <optional>
0005 
0006 #include <alpaka/alpaka.hpp>
0007 
0008 #include "DataFormats/Portable/interface/PortableCollection.h"
0009 #include "DataFormats/Portable/interface/PortableHostCollection.h"
0010 #include "DataFormats/Portable/interface/PortableDeviceCollection.h"
0011 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0012 #include "HeterogeneousCore/AlpakaInterface/interface/TransferToHost.h"
0013 
0014 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0015 
0016 #if defined ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
0017   // ... or any other CPU-based accelerators
0018 
0019   // generic SoA-based product in host memory
0020   template <typename T>
0021   using PortableCollection = ::PortableHostCollection<T>;
0022 
0023 #else
0024 
0025   // generic SoA-based product in device memory
0026   template <typename T>
0027   using PortableCollection = ::PortableDeviceCollection<T, Device>;
0028 
0029 #endif  // ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
0030 
0031 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0032 
0033 namespace traits {
0034 
0035   // specialise the trait for the device provided by the ALPAKA_ACCELERATOR_NAMESPACE
0036   template <typename T>
0037   class PortableCollectionTrait<T, ALPAKA_ACCELERATOR_NAMESPACE::Device> {
0038     using CollectionType = ALPAKA_ACCELERATOR_NAMESPACE::PortableCollection<T>;
0039   };
0040 
0041 }  // namespace traits
0042 
0043 namespace cms::alpakatools {
0044   // TODO: Is this the right place for the specialization? Or should it be in PortableDeviceProduct?
0045   template <typename T>
0046   struct TransferToHost<ALPAKA_ACCELERATOR_NAMESPACE::PortableCollection<T>> {
0047     using HostDataType = ::PortableHostCollection<T>;
0048 
0049     template <typename TQueue>
0050     static HostDataType transferAsync(TQueue& queue,
0051                                       ALPAKA_ACCELERATOR_NAMESPACE::PortableCollection<T> const& deviceData) {
0052       HostDataType hostData(deviceData->metadata().size(), queue);
0053       alpaka::memcpy(queue, hostData.buffer(), deviceData.buffer());
0054       return hostData;
0055     }
0056   };
0057 }  // namespace cms::alpakatools
0058 
0059 #endif  // DataFormats_Portable_interface_alpaka_PortableDeviceCollection_h