Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-04 01:26:14

0001 #include <cuda_runtime.h>
0002 
0003 #include <fmt/printf.h>
0004 
0005 #include "CUDADataFormats/Common/interface/HostProduct.h"
0006 #include "CUDADataFormats/Common/interface/Product.h"
0007 #include "CUDADataFormats/TrackingRecHit/interface/TrackingRecHit2DHeterogeneous.h"
0008 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0009 #include "DataFormats/Common/interface/Handle.h"
0010 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0011 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/Framework/interface/MakerMacros.h"
0015 #include "FWCore/Framework/interface/stream/EDProducer.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0020 #include "FWCore/Utilities/interface/InputTag.h"
0021 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0022 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0023 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0024 #include "HeterogeneousCore/CUDACore/interface/ScopedContext.h"
0025 #include "RecoLocalTracker/SiPixelRecHits/interface/pixelCPEforGPU.h"
0026 
0027 class SiPixelRecHitSoAFromCUDA : public edm::stream::EDProducer<edm::ExternalWork> {
0028 public:
0029   explicit SiPixelRecHitSoAFromCUDA(const edm::ParameterSet& iConfig);
0030   ~SiPixelRecHitSoAFromCUDA() override = default;
0031 
0032   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0033   using HMSstorage = HostProduct<uint32_t[]>;
0034 
0035 private:
0036   void acquire(edm::Event const& iEvent,
0037                edm::EventSetup const& iSetup,
0038                edm::WaitingTaskWithArenaHolder waitingTaskHolder) override;
0039   void produce(edm::Event& iEvent, edm::EventSetup const& iSetup) override;
0040 
0041   const edm::EDGetTokenT<cms::cuda::Product<TrackingRecHit2DGPU>> hitsTokenGPU_;  // CUDA hits
0042   const edm::EDPutTokenT<TrackingRecHit2DCPU> hitsPutTokenCPU_;
0043   const edm::EDPutTokenT<HMSstorage> hostPutToken_;
0044 
0045   uint32_t nHits_;
0046   uint32_t nMaxModules_;
0047 
0048   cms::cuda::host::unique_ptr<float[]> store32_;
0049   cms::cuda::host::unique_ptr<uint16_t[]> store16_;
0050   cms::cuda::host::unique_ptr<uint32_t[]> hitsModuleStart_;
0051 };
0052 
0053 SiPixelRecHitSoAFromCUDA::SiPixelRecHitSoAFromCUDA(const edm::ParameterSet& iConfig)
0054     : hitsTokenGPU_(
0055           consumes<cms::cuda::Product<TrackingRecHit2DGPU>>(iConfig.getParameter<edm::InputTag>("pixelRecHitSrc"))),
0056       hitsPutTokenCPU_(produces<TrackingRecHit2DCPU>()),
0057       hostPutToken_(produces<HMSstorage>()) {}
0058 
0059 void SiPixelRecHitSoAFromCUDA::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0060   edm::ParameterSetDescription desc;
0061   desc.add<edm::InputTag>("pixelRecHitSrc", edm::InputTag("siPixelRecHitsPreSplittingCUDA"));
0062   descriptions.addWithDefaultLabel(desc);
0063 }
0064 
0065 void SiPixelRecHitSoAFromCUDA::acquire(edm::Event const& iEvent,
0066                                        edm::EventSetup const& iSetup,
0067                                        edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
0068   cms::cuda::Product<TrackingRecHit2DGPU> const& inputDataWrapped = iEvent.get(hitsTokenGPU_);
0069   cms::cuda::ScopedContextAcquire ctx{inputDataWrapped, std::move(waitingTaskHolder)};
0070   auto const& inputData = ctx.get(inputDataWrapped);
0071 
0072   nHits_ = inputData.nHits();
0073   LogDebug("SiPixelRecHitSoAFromCUDA") << "copying to cpu SoA" << inputData.nHits() << " Hits";
0074 
0075   if (0 == nHits_)
0076     return;
0077   nMaxModules_ = inputData.nMaxModules();
0078   store32_ = inputData.store32ToHostAsync(ctx.stream());
0079   store16_ = inputData.store16ToHostAsync(ctx.stream());
0080   hitsModuleStart_ = inputData.hitsModuleStartToHostAsync(ctx.stream());
0081 }
0082 
0083 void SiPixelRecHitSoAFromCUDA::produce(edm::Event& iEvent, edm::EventSetup const& es) {
0084   auto hmsp = std::make_unique<uint32_t[]>(nMaxModules_ + 1);
0085 
0086   if (nHits_ > 0)
0087     std::copy(hitsModuleStart_.get(), hitsModuleStart_.get() + nMaxModules_ + 1, hmsp.get());
0088 
0089   iEvent.emplace(hostPutToken_, std::move(hmsp));
0090   iEvent.emplace(hitsPutTokenCPU_, store32_.get(), store16_.get(), hitsModuleStart_.get(), nHits_);
0091 }
0092 
0093 DEFINE_FWK_MODULE(SiPixelRecHitSoAFromCUDA);