Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:23

0001 #include <cuda_runtime.h>
0002 
0003 #include "CUDADataFormats/BeamSpot/interface/BeamSpotCUDA.h"
0004 #include "CUDADataFormats/Common/interface/Product.h"
0005 #include "CUDADataFormats/SiPixelCluster/interface/SiPixelClustersCUDA.h"
0006 #include "CUDADataFormats/SiPixelDigi/interface/SiPixelDigisCUDA.h"
0007 #include "CUDADataFormats/TrackingRecHit/interface/TrackingRecHitSoADevice.h"
0008 #include "DataFormats/Common/interface/Handle.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include "FWCore/Framework/interface/global/EDProducer.h"
0013 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0016 #include "FWCore/Utilities/interface/InputTag.h"
0017 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0018 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0019 #include "HeterogeneousCore/CUDACore/interface/ScopedContext.h"
0020 #include "RecoLocalTracker/Records/interface/TkPixelCPERecord.h"
0021 #include "RecoLocalTracker/SiPixelRecHits/interface/PixelCPEBase.h"
0022 #include "RecoLocalTracker/SiPixelRecHits/interface/PixelCPEFast.h"
0023 #include "Geometry/CommonTopologies/interface/SimplePixelTopology.h"
0024 
0025 #include "PixelRecHitGPUKernel.h"
0026 
0027 template <typename TrackerTraits>
0028 class SiPixelRecHitCUDAT : public edm::global::EDProducer<> {
0029 public:
0030   explicit SiPixelRecHitCUDAT(const edm::ParameterSet& iConfig);
0031   ~SiPixelRecHitCUDAT() override = default;
0032 
0033   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0034 
0035 private:
0036   void produce(edm::StreamID streamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
0037 
0038   const edm::ESGetToken<PixelClusterParameterEstimator, TkPixelCPERecord> cpeToken_;
0039   const edm::EDGetTokenT<cms::cuda::Product<BeamSpotCUDA>> tBeamSpot;
0040   const edm::EDGetTokenT<cms::cuda::Product<SiPixelClustersCUDA>> token_;
0041   const edm::EDGetTokenT<cms::cuda::Product<SiPixelDigisCUDA>> tokenDigi_;
0042   const edm::EDPutTokenT<cms::cuda::Product<TrackingRecHitSoADevice<TrackerTraits>>> tokenHit_;
0043 
0044   const pixelgpudetails::PixelRecHitGPUKernel<TrackerTraits> gpuAlgo_;
0045 };
0046 
0047 template <typename TrackerTraits>
0048 SiPixelRecHitCUDAT<TrackerTraits>::SiPixelRecHitCUDAT(const edm::ParameterSet& iConfig)
0049     : cpeToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("CPE")))),
0050       tBeamSpot(consumes<cms::cuda::Product<BeamSpotCUDA>>(iConfig.getParameter<edm::InputTag>("beamSpot"))),
0051       token_(consumes<cms::cuda::Product<SiPixelClustersCUDA>>(iConfig.getParameter<edm::InputTag>("src"))),
0052       tokenDigi_(consumes<cms::cuda::Product<SiPixelDigisCUDA>>(iConfig.getParameter<edm::InputTag>("src"))),
0053       tokenHit_(produces<cms::cuda::Product<TrackingRecHitSoADevice<TrackerTraits>>>()) {}
0054 
0055 template <typename TrackerTraits>
0056 void SiPixelRecHitCUDAT<TrackerTraits>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0057   edm::ParameterSetDescription desc;
0058 
0059   desc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpotCUDA"));
0060   desc.add<edm::InputTag>("src", edm::InputTag("siPixelClustersPreSplittingCUDA"));
0061 
0062   std::string cpe = "PixelCPEFast";
0063   cpe += TrackerTraits::nameModifier;
0064   desc.add<std::string>("CPE", cpe);
0065 
0066   descriptions.addWithDefaultLabel(desc);
0067 }
0068 
0069 template <typename TrackerTraits>
0070 void SiPixelRecHitCUDAT<TrackerTraits>::produce(edm::StreamID streamID,
0071                                                 edm::Event& iEvent,
0072                                                 const edm::EventSetup& es) const {
0073   PixelCPEFast<TrackerTraits> const* fcpe = dynamic_cast<const PixelCPEFast<TrackerTraits>*>(&es.getData(cpeToken_));
0074   if (not fcpe) {
0075     throw cms::Exception("Configuration") << "SiPixelRecHitCUDA can only use a CPE of type PixelCPEFast";
0076   }
0077 
0078   edm::Handle<cms::cuda::Product<SiPixelClustersCUDA>> hclusters;
0079   iEvent.getByToken(token_, hclusters);
0080 
0081   cms::cuda::ScopedContextProduce ctx{*hclusters};
0082   auto const& clusters = ctx.get(*hclusters);
0083 
0084   edm::Handle<cms::cuda::Product<SiPixelDigisCUDA>> hdigis;
0085   iEvent.getByToken(tokenDigi_, hdigis);
0086   auto const& digis = ctx.get(*hdigis);
0087 
0088   edm::Handle<cms::cuda::Product<BeamSpotCUDA>> hbs;
0089   iEvent.getByToken(tBeamSpot, hbs);
0090   auto const& bs = ctx.get(*hbs);
0091 
0092   ctx.emplace(iEvent,
0093               tokenHit_,
0094               gpuAlgo_.makeHitsAsync(digis, clusters, bs, fcpe->getGPUProductAsync(ctx.stream()), ctx.stream()));
0095 }
0096 
0097 using SiPixelRecHitCUDAPhase1 = SiPixelRecHitCUDAT<pixelTopology::Phase1>;
0098 DEFINE_FWK_MODULE(SiPixelRecHitCUDAPhase1);
0099 
0100 using SiPixelRecHitCUDAPhase2 = SiPixelRecHitCUDAT<pixelTopology::Phase2>;
0101 DEFINE_FWK_MODULE(SiPixelRecHitCUDAPhase2);
0102 
0103 using SiPixelRecHitCUDAHIonPhase1 = SiPixelRecHitCUDAT<pixelTopology::HIonPhase1>;
0104 DEFINE_FWK_MODULE(SiPixelRecHitCUDAHIonPhase1);