CMS 3D CMS Logo

SiPixelRawToClusterCUDA.cc
Go to the documentation of this file.
1 // C++ includes
2 #include <memory>
3 #include <string>
4 #include <vector>
5 
6 // CMSSW includes
38 
39 // local includes
42 
43 class SiPixelRawToClusterCUDA : public edm::stream::EDProducer<edm::ExternalWork> {
44 public:
45  explicit SiPixelRawToClusterCUDA(const edm::ParameterSet& iConfig);
46  ~SiPixelRawToClusterCUDA() override = default;
47 
48  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
49 
50 private:
51  void acquire(const edm::Event& iEvent,
52  const edm::EventSetup& iSetup,
53  edm::WaitingTaskWithArenaHolder waitingTaskHolder) override;
54  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
55 
57 
61 
63 
68 
69  std::unique_ptr<SiPixelFedCablingTree> cabling_;
70  std::vector<unsigned int> fedIds_;
72  std::unique_ptr<PixelUnpackingRegions> regions_;
73 
75  std::unique_ptr<pixelgpudetails::SiPixelRawToClusterGPUKernel::WordFedAppender> wordFedAppender_;
77 
78  const bool isRun2_;
79  const bool includeErrors_;
80  const bool useQuality_;
82 };
83 
85  : rawGetToken_(consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("InputLabel"))),
86  digiPutToken_(produces<cms::cuda::Product<SiPixelDigisCUDA>>()),
87  clusterPutToken_(produces<cms::cuda::Product<SiPixelClustersCUDA>>()),
91  edm::ESInputTag("", iConfig.getParameter<std::string>("CablingMapLabel")))),
92  isRun2_(iConfig.getParameter<bool>("isRun2")),
93  includeErrors_(iConfig.getParameter<bool>("IncludeErrors")),
94  useQuality_(iConfig.getParameter<bool>("UseQualityInfo")),
95  clusterThresholds_{iConfig.getParameter<int32_t>("clusterThreshold_layer1"),
96  iConfig.getParameter<int32_t>("clusterThreshold_otherLayers")} {
97  if (includeErrors_) {
98  digiErrorPutToken_ = produces<cms::cuda::Product<SiPixelDigiErrorsCUDA>>();
99  }
100 
101  // regions
102  if (!iConfig.getParameter<edm::ParameterSet>("Regions").getParameterNames().empty()) {
103  regions_ = std::make_unique<PixelUnpackingRegions>(iConfig, consumesCollector());
104  }
105 
107  if (cs->enabled()) {
108  wordFedAppender_ = std::make_unique<pixelgpudetails::SiPixelRawToClusterGPUKernel::WordFedAppender>();
109  }
110 }
111 
114  desc.add<bool>("isRun2", true);
115  desc.add<bool>("IncludeErrors", true);
116  desc.add<bool>("UseQualityInfo", false);
117  desc.add<int32_t>("clusterThreshold_layer1", kSiPixelClusterThresholdsDefaultPhase1.layer1);
118  desc.add<int32_t>("clusterThreshold_otherLayers", kSiPixelClusterThresholdsDefaultPhase1.otherLayers);
119  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
120  {
122  psd0.addOptional<std::vector<edm::InputTag>>("inputs");
123  psd0.addOptional<std::vector<double>>("deltaPhi");
124  psd0.addOptional<std::vector<double>>("maxZ");
125  psd0.addOptional<edm::InputTag>("beamSpot");
126  desc.add<edm::ParameterSetDescription>("Regions", psd0)
127  ->setComment("## Empty Regions PSet means complete unpacking");
128  }
129  desc.add<std::string>("CablingMapLabel", "")->setComment("CablingMap label"); //Tav
130  descriptions.addWithDefaultLabel(desc);
131 }
132 
134  const edm::EventSetup& iSetup,
135  edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
136  cms::cuda::ScopedContextAcquire ctx{iEvent.streamID(), std::move(waitingTaskHolder), ctxState_};
137 
138  auto hgpuMap = iSetup.getHandle(gpuMapToken_);
139  if (hgpuMap->hasQuality() != useQuality_) {
140  throw cms::Exception("LogicError")
141  << "UseQuality of the module (" << useQuality_
142  << ") differs the one from SiPixelROCsStatusAndMappingWrapper. Please fix your configuration.";
143  }
144  // get the GPU product already here so that the async transfer can begin
145  const auto* gpuMap = hgpuMap->getGPUProductAsync(ctx.stream());
146 
147  auto hgains = iSetup.getHandle(gainsToken_);
148  // get the GPU product already here so that the async transfer can begin
149  const auto* gpuGains = hgains->getGPUProductAsync(ctx.stream());
150 
151  cms::cuda::device::unique_ptr<unsigned char[]> modulesToUnpackRegional;
152  const unsigned char* gpuModulesToUnpack;
153 
154  if (regions_) {
155  regions_->run(iEvent, iSetup);
156  LogDebug("SiPixelRawToCluster") << "region2unpack #feds: " << regions_->nFEDs();
157  LogDebug("SiPixelRawToCluster") << "region2unpack #modules (BPIX,EPIX,total): " << regions_->nBarrelModules() << " "
158  << regions_->nForwardModules() << " " << regions_->nModules();
159  modulesToUnpackRegional = hgpuMap->getModToUnpRegionalAsync(*(regions_->modulesToUnpack()), ctx.stream());
160  gpuModulesToUnpack = modulesToUnpackRegional.get();
161  } else {
162  gpuModulesToUnpack = hgpuMap->getModToUnpAllAsync(ctx.stream());
163  }
164 
165  // initialize cabling map or update if necessary
166  if (recordWatcher_.check(iSetup)) {
167  // cabling map, which maps online address (fed->link->ROC->local pixel) to offline (DetId->global pixel)
168  auto cablingMap = iSetup.getTransientHandle(cablingMapToken_);
169  cablingMap_ = cablingMap.product();
170  fedIds_ = cablingMap->fedIds();
171  cabling_ = cablingMap->cablingTree();
172  LogDebug("map version:") << cabling_->version();
173  }
174 
175  const auto& buffers = iEvent.get(rawGetToken_);
176 
177  errors_.clear();
178 
179  // GPU specific: Data extraction for RawToDigi GPU
180  unsigned int wordCounterGPU = 0;
181  unsigned int fedCounter = 0;
182  bool errorsInEvent = false;
183 
184  // In CPU algorithm this loop is part of PixelDataFormatter::interpretRawData()
185  ErrorChecker errorcheck;
186  for (int fedId : fedIds_) {
187  if (regions_ && !regions_->mayUnpackFED(fedId))
188  continue;
189 
190  // for GPU
191  // first 150 index stores the fedId and next 150 will store the
192  // start index of word in that fed
194  fedCounter++;
195 
196  // get event data for this fed
197  const FEDRawData& rawData = buffers.FEDData(fedId);
198 
199  // GPU specific
200  int nWords = rawData.size() / sizeof(cms_uint64_t);
201  if (nWords == 0) {
202  continue;
203  }
204 
205  // check CRC bit
206  const cms_uint64_t* trailer = reinterpret_cast<const cms_uint64_t*>(rawData.data()) + (nWords - 1);
207  if (not errorcheck.checkCRC(errorsInEvent, fedId, trailer, errors_)) {
208  continue;
209  }
210 
211  // check headers
212  const cms_uint64_t* header = reinterpret_cast<const cms_uint64_t*>(rawData.data());
213  header--;
214  bool moreHeaders = true;
215  while (moreHeaders) {
216  header++;
217  bool headerStatus = errorcheck.checkHeader(errorsInEvent, fedId, header, errors_);
218  moreHeaders = headerStatus;
219  }
220 
221  // check trailers
222  bool moreTrailers = true;
223  trailer++;
224  while (moreTrailers) {
225  trailer--;
226  bool trailerStatus = errorcheck.checkTrailer(errorsInEvent, fedId, nWords, trailer, errors_);
227  moreTrailers = trailerStatus;
228  }
229 
230  const cms_uint32_t* bw = (const cms_uint32_t*)(header + 1);
231  const cms_uint32_t* ew = (const cms_uint32_t*)(trailer);
232 
233  assert(0 == (ew - bw) % 2);
234  wordFedAppender_->initializeWordFed(fedId, wordCounterGPU, bw, (ew - bw));
235  wordCounterGPU += (ew - bw);
236 
237  } // end of for loop
238 
241  gpuMap,
242  gpuModulesToUnpack,
243  gpuGains,
246  wordCounterGPU,
247  fedCounter,
248  useQuality_,
250  edm::MessageDrop::instance()->debugEnabled,
251  ctx.stream());
252 }
253 
256 
257  auto tmp = gpuAlgo_.getResults();
258  ctx.emplace(iEvent, digiPutToken_, std::move(tmp.first));
259  ctx.emplace(iEvent, clusterPutToken_, std::move(tmp.second));
260  if (includeErrors_) {
261  ctx.emplace(iEvent, digiErrorPutToken_, gpuAlgo_.getErrors());
262  }
263 }
264 
265 // define as framework plugin
ConfigurationDescriptions.h
SiPixelRawToClusterCUDA::cabling_
std::unique_ptr< SiPixelFedCablingTree > cabling_
Definition: SiPixelRawToClusterCUDA.cc:69
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
FEDNumbering.h
cms_uint32_t
unsigned int cms_uint32_t
Definition: typedefs.h:15
electrons_cff.bool
bool
Definition: electrons_cff.py:366
SiPixelRawToClusterCUDA::cablingMapToken_
edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > cablingMapToken_
Definition: SiPixelRawToClusterCUDA.cc:67
pixelgpudetails::SiPixelRawToClusterGPUKernel
Definition: SiPixelRawToClusterGPUKernel.h:118
ESTransientHandle.h
MessageLogger.h
SiPixelGainCalibrationForHLTGPURcd
Definition: SiPixelGainCalibrationForHLTGPURcd.h:9
SiPixelRawToClusterCUDA::digiErrorPutToken_
edm::EDPutTokenT< cms::cuda::Product< SiPixelDigiErrorsCUDA > > digiErrorPutToken_
Definition: SiPixelRawToClusterCUDA.cc:59
edm::ESWatcher< SiPixelFedCablingMapRcd >
ESHandle.h
ESInputTag
cms::cuda::ScopedContextProduce
Definition: ScopedContext.h:149
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:47
SiPixelRawToClusterCUDA
Definition: SiPixelRawToClusterCUDA.cc:43
SiPixelRawToClusterCUDA::recordWatcher_
edm::ESWatcher< SiPixelFedCablingMapRcd > recordWatcher_
Definition: SiPixelRawToClusterCUDA.cc:64
SiPixelClustersCUDA
Definition: SiPixelClustersCUDA.h:10
PixelDataFormatter::Errors
std::map< cms_uint32_t, DetErrors > Errors
Definition: PixelDataFormatter.h:64
edm::EDGetTokenT< FEDRawDataCollection >
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
SiPixelRawToClusterCUDA::gainsToken_
edm::ESGetToken< SiPixelGainCalibrationForHLTGPU, SiPixelGainCalibrationForHLTGPURcd > gainsToken_
Definition: SiPixelRawToClusterCUDA.cc:66
FEDNumbering::MINSiPixeluTCAFEDID
Definition: FEDNumbering.h:105
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::EDPutTokenT
Definition: EDPutToken.h:33
SiPixelRawToClusterCUDA::ctxState_
cms::cuda::ContextState ctxState_
Definition: SiPixelRawToClusterCUDA.cc:62
SiPixelRawToClusterCUDA::clusterPutToken_
edm::EDPutTokenT< cms::cuda::Product< SiPixelClustersCUDA > > clusterPutToken_
Definition: SiPixelRawToClusterCUDA.cc:60
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
SiPixelROCsStatusAndMappingWrapper
Definition: SiPixelROCsStatusAndMappingWrapper.h:17
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
l1tstage2_dqm_sourceclient-live_cfg.rawData
rawData
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:163
SiPixelClusterThresholds
Definition: SiPixelClusterThresholds.h:4
cms::cuda::assert
assert(be >=bs)
EDProducer.h
SiPixelFedCablingMap.h
SiPixelRawToClusterCUDA::wordFedAppender_
std::unique_ptr< pixelgpudetails::SiPixelRawToClusterGPUKernel::WordFedAppender > wordFedAppender_
Definition: SiPixelRawToClusterCUDA.cc:75
SiPixelFedCablingTree.h
CkfComponentsRecord.h
pixelgpudetails::SiPixelRawToClusterGPUKernel::getResults
std::pair< SiPixelDigisCUDA, SiPixelClustersCUDA > getResults()
Definition: SiPixelRawToClusterGPUKernel.h:157
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
SiPixelClustersCUDA.h
FEDRawData.h
edm::ParameterSetDescription::addOptional
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:105
FEDRawData
Definition: FEDRawData.h:19
SiPixelRawToClusterCUDA::cablingMap_
const SiPixelFedCablingMap * cablingMap_
Definition: SiPixelRawToClusterCUDA.cc:71
ErrorCheckerBase::checkTrailer
bool checkTrailer(bool &errorsInEvent, int fedId, unsigned int nWords, const Word64 *trailer, SiPixelFormatterErrors &errors) const
Definition: ErrorCheckerBase.cc:64
edm::WaitingTaskWithArenaHolder
Definition: WaitingTaskWithArenaHolder.h:34
MakerMacros.h
kSiPixelClusterThresholdsDefaultPhase1
constexpr SiPixelClusterThresholds kSiPixelClusterThresholdsDefaultPhase1
Definition: SiPixelClusterThresholds.h:12
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
CkfComponentsRecord
Definition: CkfComponentsRecord.h:22
Service.h
SiPixelRawToClusterCUDA::digiPutToken_
edm::EDPutTokenT< cms::cuda::Product< SiPixelDigisCUDA > > digiPutToken_
Definition: SiPixelRawToClusterCUDA.cc:58
SiPixelClusterThresholds.h
SiPixelRawToClusterCUDA::includeErrors_
const bool includeErrors_
Definition: SiPixelRawToClusterCUDA.cc:79
SiPixelROCsStatusAndMappingWrapper.h
ParameterSetDescription.h
PixelUnpackingRegions.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
SiPixelDigisCUDA
Definition: SiPixelDigisCUDA.h:10
ErrorCheckerBase::checkHeader
bool checkHeader(bool &errorsInEvent, int fedId, const Word64 *header, SiPixelFormatterErrors &errors) const
Definition: ErrorCheckerBase.cc:47
SiPixelRawToClusterCUDA::isRun2_
const bool isRun2_
Definition: SiPixelRawToClusterCUDA.cc:78
SiPixelRawToClusterCUDA::useQuality_
const bool useQuality_
Definition: SiPixelRawToClusterCUDA.cc:80
SiPixelGainCalibrationForHLTGPURcd.h
cms::cuda::ContextState
Definition: ContextState.h:15
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
SiPixelFedCablingMapRcd.h
SiPixelGainCalibrationForHLTGPU
Definition: SiPixelGainCalibrationForHLTGPU.h:12
edm::ParameterSet::getParameterNames
std::vector< std::string > getParameterNames() const
Definition: ParameterSet.cc:663
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
FEDRawDataCollection.h
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
edm::stream::EDProducer
Definition: EDProducer.h:36
SiPixelDigiErrorsCUDA.h
cms_uint64_t
unsigned long long cms_uint64_t
Definition: typedefs.h:17
edm::EventSetup
Definition: EventSetup.h:58
l1tstage2_dqm_sourceclient-live_cfg.fedId
fedId
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:89
edm::EventSetup::getTransientHandle
ESTransientHandle< T > getTransientHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:166
SiPixelDigisCUDA.h
SiPixelClusterThresholds::otherLayers
const int32_t otherLayers
Definition: SiPixelClusterThresholds.h:9
ErrorChecker
Definition: ErrorChecker.h:12
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ESGetToken< SiPixelROCsStatusAndMappingWrapper, CkfComponentsRecord >
SiPixelRawToClusterCUDA::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: SiPixelRawToClusterCUDA.cc:254
SiPixelFedCablingMap
Definition: SiPixelFedCablingMap.h:19
SiPixelRawToClusterCUDA::fedIds_
std::vector< unsigned int > fedIds_
Definition: SiPixelRawToClusterCUDA.cc:70
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
CUDAService.h
cms::cuda::ScopedContextAcquire
Definition: ScopedContext.h:101
Product.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
PixelDataFormatter.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
ESWatcher.h
SiPixelClusterThresholds::layer1
const int32_t layer1
Definition: SiPixelClusterThresholds.h:8
Exception
Definition: hltDiff.cc:245
SiPixelRawToClusterCUDA::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: SiPixelRawToClusterCUDA.cc:112
ScopedContext.h
edm::MessageDrop::instance
static MessageDrop * instance()
Definition: MessageDrop.cc:33
pixelgpudetails::SiPixelRawToClusterGPUKernel::makeClustersAsync
void makeClustersAsync(bool isRun2, const SiPixelClusterThresholds clusterThresholds, const SiPixelROCsStatusAndMapping *cablingMap, const unsigned char *modToUnp, const SiPixelGainForHLTonGPU *gains, const WordFedAppender &wordFed, SiPixelFormatterErrors &&errors, const uint32_t wordCounter, const uint32_t fedCounter, bool useQualityInfo, bool includeErrors, bool debug, cudaStream_t stream)
ecalDigis_cff.cuda
cuda
Definition: ecalDigis_cff.py:35
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
SiPixelRawToClusterCUDA::acquire
void acquire(const edm::Event &iEvent, const edm::EventSetup &iSetup, edm::WaitingTaskWithArenaHolder waitingTaskHolder) override
Definition: SiPixelRawToClusterCUDA.cc:133
SiPixelRawToClusterCUDA::clusterThresholds_
const SiPixelClusterThresholds clusterThresholds_
Definition: SiPixelRawToClusterCUDA.cc:81
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:291
SiPixelRawToClusterCUDA::gpuMapToken_
edm::ESGetToken< SiPixelROCsStatusAndMappingWrapper, CkfComponentsRecord > gpuMapToken_
Definition: SiPixelRawToClusterCUDA.cc:65
ConsumesCollector.h
SiPixelRawToClusterGPUKernel.h
ParameterSet.h
SiPixelFedCablingMapRcd
Definition: SiPixelFedCablingMapRcd.h:5
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
pixelgpudetails::SiPixelRawToClusterGPUKernel::getErrors
SiPixelDigiErrorsCUDA && getErrors()
Definition: SiPixelRawToClusterGPUKernel.h:170
edm::Event
Definition: Event.h:73
SiPixelRawToClusterCUDA::SiPixelRawToClusterCUDA
SiPixelRawToClusterCUDA(const edm::ParameterSet &iConfig)
Definition: SiPixelRawToClusterCUDA.cc:84
SiPixelRawToClusterCUDA::gpuAlgo_
pixelgpudetails::SiPixelRawToClusterGPUKernel gpuAlgo_
Definition: SiPixelRawToClusterCUDA.cc:74
edm::InputTag
Definition: InputTag.h:15
SiPixelRawToClusterCUDA::regions_
std::unique_ptr< PixelUnpackingRegions > regions_
Definition: SiPixelRawToClusterCUDA.cc:72
SiPixelRawToClusterCUDA::~SiPixelRawToClusterCUDA
~SiPixelRawToClusterCUDA() override=default
SiPixelGainCalibrationForHLTGPU.h
ErrorCheckerBase::checkCRC
bool checkCRC(bool &errorsInEvent, int fedId, const Word64 *trailer, SiPixelFormatterErrors &errors) const
Definition: ErrorCheckerBase.cc:35
SiPixelRawToClusterCUDA::rawGetToken_
edm::EDGetTokenT< FEDRawDataCollection > rawGetToken_
Definition: SiPixelRawToClusterCUDA.cc:56
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87
SiPixelRawToClusterCUDA::errors_
PixelDataFormatter::Errors errors_
Definition: SiPixelRawToClusterCUDA.cc:76
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21