Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-11 03:36:06

0001 // C++ includes
0002 #include <memory>
0003 #include <string>
0004 #include <vector>
0005 
0006 // CMSSW includes
0007 #include "CUDADataFormats/Common/interface/Product.h"
0008 #include "CUDADataFormats/SiPixelCluster/interface/SiPixelClustersCUDA.h"
0009 #include "CUDADataFormats/SiPixelCluster/interface/gpuClusteringConstants.h"
0010 #include "CUDADataFormats/SiPixelDigi/interface/SiPixelDigiErrorsCUDA.h"
0011 #include "CUDADataFormats/SiPixelDigi/interface/SiPixelDigisCUDA.h"
0012 #include "CalibTracker/Records/interface/SiPixelGainCalibrationForHLTGPURcd.h"
0013 #include "CalibTracker/SiPixelESProducers/interface/SiPixelROCsStatusAndMappingWrapper.h"
0014 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationForHLTGPU.h"
0015 #include "CondFormats/DataRecord/interface/SiPixelFedCablingMapRcd.h"
0016 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h"
0017 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h"
0018 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0019 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0020 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0021 #include "EventFilter/SiPixelRawToDigi/interface/PixelDataFormatter.h"
0022 #include "EventFilter/SiPixelRawToDigi/interface/PixelUnpackingRegions.h"
0023 #include "FWCore/Framework/interface/ConsumesCollector.h"
0024 #include "FWCore/Framework/interface/ESHandle.h"
0025 #include "FWCore/Framework/interface/ESTransientHandle.h"
0026 #include "FWCore/Framework/interface/ESWatcher.h"
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/EventSetup.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 #include "FWCore/Framework/interface/stream/EDProducer.h"
0031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0032 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0034 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0035 #include "FWCore/ServiceRegistry/interface/Service.h"
0036 #include "HeterogeneousCore/CUDACore/interface/ScopedContext.h"
0037 #include "HeterogeneousCore/CUDAServices/interface/CUDAService.h"
0038 #include "RecoTracker/Record/interface/CkfComponentsRecord.h"
0039 
0040 // local includes
0041 #include "SiPixelClusterThresholds.h"
0042 #include "SiPixelRawToClusterGPUKernel.h"
0043 
0044 class SiPixelPhase2DigiToClusterCUDA : public edm::stream::EDProducer<edm::ExternalWork> {
0045 public:
0046   explicit SiPixelPhase2DigiToClusterCUDA(const edm::ParameterSet& iConfig);
0047   ~SiPixelPhase2DigiToClusterCUDA() override = default;
0048 
0049   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0050 
0051 private:
0052   void acquire(const edm::Event& iEvent,
0053                const edm::EventSetup& iSetup,
0054                edm::WaitingTaskWithArenaHolder waitingTaskHolder) override;
0055   void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0056 
0057   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
0058   const edm::EDGetTokenT<edm::DetSetVector<PixelDigi>> pixelDigiToken_;
0059 
0060   edm::EDPutTokenT<cms::cuda::Product<SiPixelDigisCUDA>> digiPutToken_;
0061   edm::EDPutTokenT<cms::cuda::Product<SiPixelDigiErrorsCUDA>> digiErrorPutToken_;
0062   edm::EDPutTokenT<cms::cuda::Product<SiPixelClustersCUDA>> clusterPutToken_;
0063 
0064   cms::cuda::ContextState ctxState_;
0065 
0066   pixelgpudetails::SiPixelRawToClusterGPUKernel gpuAlgo_;
0067   std::unique_ptr<pixelgpudetails::SiPixelRawToClusterGPUKernel::WordFedAppender> wordFedAppender_;
0068 
0069   const bool includeErrors_;
0070   const SiPixelClusterThresholds clusterThresholds_;
0071 };
0072 
0073 SiPixelPhase2DigiToClusterCUDA::SiPixelPhase2DigiToClusterCUDA(const edm::ParameterSet& iConfig)
0074     : geomToken_(esConsumes()),
0075       pixelDigiToken_(consumes<edm::DetSetVector<PixelDigi>>(iConfig.getParameter<edm::InputTag>("InputDigis"))),
0076       digiPutToken_(produces<cms::cuda::Product<SiPixelDigisCUDA>>()),
0077       clusterPutToken_(produces<cms::cuda::Product<SiPixelClustersCUDA>>()),
0078       includeErrors_(iConfig.getParameter<bool>("IncludeErrors")),
0079       clusterThresholds_{iConfig.getParameter<int32_t>("clusterThreshold_layer1"),
0080                          iConfig.getParameter<int32_t>("clusterThreshold_otherLayers")} {
0081   if (includeErrors_) {
0082     digiErrorPutToken_ = produces<cms::cuda::Product<SiPixelDigiErrorsCUDA>>();
0083   }
0084 }
0085 
0086 void SiPixelPhase2DigiToClusterCUDA::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0087   edm::ParameterSetDescription desc;
0088 
0089   desc.add<bool>("IncludeErrors", true);
0090   desc.add<int32_t>("clusterThreshold_layer1", kSiPixelClusterThresholdsDefaultPhase2.layer1);
0091   desc.add<int32_t>("clusterThreshold_otherLayers", kSiPixelClusterThresholdsDefaultPhase2.otherLayers);
0092   desc.add<edm::InputTag>("InputDigis", edm::InputTag("simSiPixelDigis:Pixel"));
0093   descriptions.addWithDefaultLabel(desc);
0094 }
0095 
0096 void SiPixelPhase2DigiToClusterCUDA::acquire(const edm::Event& iEvent,
0097                                              const edm::EventSetup& iSetup,
0098                                              edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
0099   cms::cuda::ScopedContextAcquire ctx{iEvent.streamID(), std::move(waitingTaskHolder), ctxState_};
0100 
0101   auto const& input = iEvent.get(pixelDigiToken_);
0102 
0103   const TrackerGeometry* geom_ = &iSetup.getData(geomToken_);
0104 
0105   uint32_t nDigis = 0;
0106 
0107   auto xDigis = cms::cuda::make_host_unique<uint16_t[]>(gpuClustering::maxNumDigis, ctx.stream());
0108   auto yDigis = cms::cuda::make_host_unique<uint16_t[]>(gpuClustering::maxNumDigis, ctx.stream());
0109   auto adcDigis = cms::cuda::make_host_unique<uint16_t[]>(gpuClustering::maxNumDigis, ctx.stream());
0110   auto moduleIds = cms::cuda::make_host_unique<uint16_t[]>(gpuClustering::maxNumDigis, ctx.stream());
0111   auto packedData = cms::cuda::make_host_unique<uint32_t[]>(gpuClustering::maxNumDigis, ctx.stream());
0112   auto rawIds = cms::cuda::make_host_unique<uint32_t[]>(gpuClustering::maxNumDigis, ctx.stream());
0113 
0114   for (auto DSViter = input.begin(); DSViter != input.end(); DSViter++) {
0115     unsigned int detid = DSViter->detId();
0116     DetId detIdObject(detid);
0117     const GeomDetUnit* genericDet = geom_->idToDetUnit(detIdObject);
0118     auto const gind = genericDet->index();
0119     for (auto const& px : *DSViter) {
0120       moduleIds[nDigis] = uint16_t(gind);
0121 
0122       xDigis[nDigis] = uint16_t(px.row());
0123       yDigis[nDigis] = uint16_t(px.column());
0124       adcDigis[nDigis] = uint16_t(px.adc());
0125 
0126       packedData[nDigis] = uint32_t(px.packedData());
0127 
0128       rawIds[nDigis] = uint32_t(detid);
0129 
0130       nDigis++;
0131     }
0132   }
0133 
0134   gpuAlgo_.makePhase2ClustersAsync(clusterThresholds_,
0135                                    moduleIds.get(),
0136                                    xDigis.get(),
0137                                    yDigis.get(),
0138                                    adcDigis.get(),
0139                                    packedData.get(),
0140                                    rawIds.get(),
0141                                    nDigis,
0142                                    ctx.stream());
0143 }
0144 
0145 void SiPixelPhase2DigiToClusterCUDA::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0146   cms::cuda::ScopedContextProduce ctx{ctxState_};
0147 
0148   auto tmp = gpuAlgo_.getResults();
0149   ctx.emplace(iEvent, digiPutToken_, std::move(tmp.first));
0150   ctx.emplace(iEvent, clusterPutToken_, std::move(tmp.second));
0151   if (includeErrors_) {
0152     ctx.emplace(iEvent, digiErrorPutToken_, gpuAlgo_.getErrors());
0153   }
0154 }
0155 
0156 // define as framework plugin
0157 DEFINE_FWK_MODULE(SiPixelPhase2DigiToClusterCUDA);