Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-05 02:48:05

0001 #ifndef RecoTracker_LSTCore_interface_LSTESData_h
0002 #define RecoTracker_LSTCore_interface_LSTESData_h
0003 
0004 #include "RecoTracker/LSTCore/interface/Common.h"
0005 #include "RecoTracker/LSTCore/interface/EndcapGeometryDevHostCollection.h"
0006 #include "RecoTracker/LSTCore/interface/ModulesHostCollection.h"
0007 #include "RecoTracker/LSTCore/interface/PixelMap.h"
0008 
0009 #include "HeterogeneousCore/AlpakaInterface/interface/CopyToDevice.h"
0010 
0011 #include <memory>
0012 
0013 namespace lst {
0014 
0015   template <typename TDev>
0016   struct LSTESData {
0017     uint16_t nModules;
0018     uint16_t nLowerModules;
0019     unsigned int nPixels;
0020     unsigned int nEndCapMap;
0021     // Using shared_ptr so that for the serial backend all streams can use the same data
0022     std::shared_ptr<const PortableMultiCollection<TDev, ModulesSoA, ModulesPixelSoA>> modules;
0023     std::shared_ptr<const PortableCollection<EndcapGeometryDevSoA, TDev>> endcapGeometry;
0024     // Host-side object that is shared between the LSTESData<TDev> objects for different devices
0025     std::shared_ptr<const PixelMap> pixelMapping;
0026 
0027     LSTESData(uint16_t const& nModulesIn,
0028               uint16_t const& nLowerModulesIn,
0029               unsigned int const& nPixelsIn,
0030               unsigned int const& nEndCapMapIn,
0031               std::shared_ptr<const PortableMultiCollection<TDev, ModulesSoA, ModulesPixelSoA>> modulesIn,
0032               std::shared_ptr<const PortableCollection<EndcapGeometryDevSoA, TDev>> endcapGeometryIn,
0033               std::shared_ptr<const PixelMap> const& pixelMappingIn)
0034         : nModules(nModulesIn),
0035           nLowerModules(nLowerModulesIn),
0036           nPixels(nPixelsIn),
0037           nEndCapMap(nEndCapMapIn),
0038           modules(std::move(modulesIn)),
0039           endcapGeometry(std::move(endcapGeometryIn)),
0040           pixelMapping(pixelMappingIn) {}
0041   };
0042 
0043   std::unique_ptr<LSTESData<alpaka_common::DevHost>> loadAndFillESHost(std::string& ptCutLabel);
0044 
0045 }  // namespace lst
0046 
0047 namespace cms::alpakatools {
0048 
0049   template <>
0050   struct CopyToDevice<lst::LSTESData<alpaka_common::DevHost>> {
0051     template <typename TQueue>
0052     static lst::LSTESData<alpaka::Dev<TQueue>> copyAsync(TQueue& queue,
0053                                                          lst::LSTESData<alpaka_common::DevHost> const& srcData) {
0054       using TDev = alpaka::Dev<TQueue>;
0055       std::shared_ptr<const PortableMultiCollection<TDev, lst::ModulesSoA, lst::ModulesPixelSoA>> deviceModules;
0056       std::shared_ptr<const PortableCollection<lst::EndcapGeometryDevSoA, TDev>> deviceEndcapGeometry;
0057 
0058       if constexpr (std::is_same_v<TDev, alpaka_common::DevHost>) {
0059         deviceModules = srcData.modules;
0060         deviceEndcapGeometry = srcData.endcapGeometry;
0061       } else {
0062         deviceModules = std::make_shared<PortableMultiCollection<TDev, lst::ModulesSoA, lst::ModulesPixelSoA>>(
0063             CopyToDevice<PortableHostMultiCollection<lst::ModulesSoA, lst::ModulesPixelSoA>>::copyAsync(
0064                 queue, *srcData.modules));
0065         deviceEndcapGeometry = std::make_shared<PortableCollection<lst::EndcapGeometryDevSoA, TDev>>(
0066             CopyToDevice<PortableHostCollection<lst::EndcapGeometryDevSoA>>::copyAsync(queue, *srcData.endcapGeometry));
0067       }
0068 
0069       return lst::LSTESData<alpaka::Dev<TQueue>>(srcData.nModules,
0070                                                  srcData.nLowerModules,
0071                                                  srcData.nPixels,
0072                                                  srcData.nEndCapMap,
0073                                                  std::move(deviceModules),
0074                                                  std::move(deviceEndcapGeometry),
0075                                                  srcData.pixelMapping);
0076     }
0077   };
0078 }  // namespace cms::alpakatools
0079 
0080 #endif