Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:22

0001 #ifndef DataFormats_TrackSoA_interface_alpaka_TracksSoACollection_h
0002 #define DataFormats_TrackSoA_interface_alpaka_TracksSoACollection_h
0003 
0004 #include <type_traits>
0005 
0006 #include <alpaka/alpaka.hpp>
0007 
0008 #include "DataFormats/Portable/interface/alpaka/PortableCollection.h"
0009 #include "DataFormats/TrackSoA/interface/TracksDevice.h"
0010 #include "DataFormats/TrackSoA/interface/TracksHost.h"
0011 #include "Geometry/CommonTopologies/interface/SimplePixelTopology.h"
0012 #include "HeterogeneousCore/AlpakaInterface/interface/AssertDeviceMatchesHostCollection.h"
0013 #include "HeterogeneousCore/AlpakaInterface/interface/CopyToHost.h"
0014 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0015 
0016 // TODO: The class is created via inheritance of the PortableCollection.
0017 // This is generally discouraged, and should be done via composition.
0018 // See: https://github.com/cms-sw/cmssw/pull/40465#discussion_r1067364306
0019 
0020 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0021 
0022   template <typename TrackerTraits>
0023   using TracksSoACollection = std::conditional_t<std::is_same_v<Device, alpaka::DevCpu>,
0024                                                  TracksHost<TrackerTraits>,
0025                                                  TracksDevice<TrackerTraits, Device>>;
0026 
0027   //Classes definition for Phase1/Phase2/HIonPhase1, to make the classes_def lighter. Not actually used in the code.
0028   namespace pixelTrack {
0029     using TracksSoACollectionPhase1 = TracksSoACollection<pixelTopology::Phase1>;
0030     using TracksSoACollectionPhase2 = TracksSoACollection<pixelTopology::Phase2>;
0031     using TracksSoACollectionHIonPhase1 = TracksSoACollection<pixelTopology::HIonPhase1>;
0032   }  // namespace pixelTrack
0033 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0034 
0035 namespace cms::alpakatools {
0036   template <typename TrackerTraits, typename TDevice>
0037   struct CopyToHost<TracksDevice<TrackerTraits, TDevice>> {
0038     template <typename TQueue>
0039     static auto copyAsync(TQueue& queue, TracksDevice<TrackerTraits, TDevice> const& deviceData) {
0040       ::TracksHost<TrackerTraits> hostData(queue);
0041       alpaka::memcpy(queue, hostData.buffer(), deviceData.buffer());
0042 #ifdef GPU_DEBUG
0043       printf("TracksSoACollection: I'm copying to host.\n");
0044 #endif
0045       return hostData;
0046     }
0047   };
0048 }  // namespace cms::alpakatools
0049 
0050 ASSERT_DEVICE_MATCHES_HOST_COLLECTION(pixelTrack::TracksSoACollectionPhase1, pixelTrack::TracksHostPhase1);
0051 ASSERT_DEVICE_MATCHES_HOST_COLLECTION(pixelTrack::TracksSoACollectionPhase2, pixelTrack::TracksHostPhase2);
0052 ASSERT_DEVICE_MATCHES_HOST_COLLECTION(pixelTrack::TracksSoACollectionHIonPhase1, pixelTrack::TracksHostHIonPhase1);
0053 
0054 #endif  // DataFormats_TrackSoA_interface_alpaka_TracksSoACollection_h