Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DataFormats_TrackingRecHitSoA_interface_TrackingRecHitSoADevice_h
0002 #define DataFormats_TrackingRecHitSoA_interface_TrackingRecHitSoADevice_h
0003 
0004 #include <cstdint>
0005 
0006 #include <alpaka/alpaka.hpp>
0007 
0008 #include "DataFormats/Portable/interface/PortableDeviceCollection.h"
0009 #include "DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsHost.h"
0010 #include "DataFormats/TrackingRecHitSoA/interface/TrackingRecHitsSoA.h"
0011 
0012 template <typename TrackerTraits, typename TDev>
0013 class TrackingRecHitDevice : public PortableDeviceCollection<TrackingRecHitLayout<TrackerTraits>, TDev> {
0014 public:
0015   using hitSoA = TrackingRecHitSoA<TrackerTraits>;
0016 
0017   // Need to decorate the class with the inherited portable accessors being now a template
0018   using PortableDeviceCollection<TrackingRecHitLayout<TrackerTraits>, TDev>::view;
0019   using PortableDeviceCollection<TrackingRecHitLayout<TrackerTraits>, TDev>::const_view;
0020   using PortableDeviceCollection<TrackingRecHitLayout<TrackerTraits>, TDev>::buffer;
0021 
0022   TrackingRecHitDevice() = default;
0023 
0024   // Constructor which specifies the SoA size, number of BPIX1 hits, and the modules entry points
0025   template <typename TQueue>
0026   explicit TrackingRecHitDevice(TQueue queue, uint32_t nHits, int32_t offsetBPIX2, uint32_t const* hitsModuleStart)
0027       : PortableDeviceCollection<TrackingRecHitLayout<TrackerTraits>, TDev>(nHits, queue), offsetBPIX2_{offsetBPIX2} {
0028     const auto device = alpaka::getDev(queue);
0029 
0030     auto start_h = cms::alpakatools::make_device_view(device, hitsModuleStart, TrackerTraits::numberOfModules + 1);
0031     auto start_d =
0032         cms::alpakatools::make_device_view(device, view().hitsModuleStart().data(), TrackerTraits::numberOfModules + 1);
0033     alpaka::memcpy(queue, start_d, start_h);
0034 
0035     auto off_h = cms::alpakatools::make_host_view(offsetBPIX2_);
0036     auto off_d = cms::alpakatools::make_device_view(device, view().offsetBPIX2());
0037     alpaka::memcpy(queue, off_d, off_h);
0038   }
0039 
0040   uint32_t nHits() const { return view().metadata().size(); }
0041 
0042   int32_t offsetBPIX2() const { return offsetBPIX2_; }
0043 
0044   uint32_t const* hitsModuleStart() const { return view().hitsModuleStart().data(); }
0045 
0046   // asynchronously update the information cached within the class itself from the information on the device
0047   template <typename TQueue>
0048   void updateFromDevice(TQueue queue) {
0049     auto off_h = cms::alpakatools::make_host_view(offsetBPIX2_);
0050     auto off_d = cms::alpakatools::make_device_view(alpaka::getDev(queue), view().offsetBPIX2());
0051     alpaka::memcpy(queue, off_h, off_d);
0052   }
0053 
0054 private:
0055   // offsetBPIX2 is used on host functions so is useful to have it also stored in the class and not only in the layout
0056   int32_t offsetBPIX2_ = 0;
0057 };
0058 
0059 #endif  // DataFormats_RecHits_interface_TrackingRecHitSoADevice_h