CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
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_;
81  const uint32_t maxFedWords_;
82  uint32_t nDigis_;
84 };
85 
87  : rawGetToken_(consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("InputLabel"))),
88  digiPutToken_(produces<cms::cuda::Product<SiPixelDigisCUDA>>()),
89  clusterPutToken_(produces<cms::cuda::Product<SiPixelClustersCUDA>>()),
93  edm::ESInputTag("", iConfig.getParameter<std::string>("CablingMapLabel")))),
94  isRun2_(iConfig.getParameter<bool>("isRun2")),
95  includeErrors_(iConfig.getParameter<bool>("IncludeErrors")),
96  useQuality_(iConfig.getParameter<bool>("UseQualityInfo")),
97  maxFedWords_(iConfig.getParameter<uint32_t>("MaxFEDWords")),
98  clusterThresholds_{iConfig.getParameter<int32_t>("clusterThreshold_layer1"),
99  iConfig.getParameter<int32_t>("clusterThreshold_otherLayers")} {
100  if (includeErrors_) {
101  digiErrorPutToken_ = produces<cms::cuda::Product<SiPixelDigiErrorsCUDA>>();
102  }
103 
104  // regions
105  if (!iConfig.getParameter<edm::ParameterSet>("Regions").getParameterNames().empty()) {
106  regions_ = std::make_unique<PixelUnpackingRegions>(iConfig, consumesCollector());
107  }
108 
110  if (cs->enabled()) {
111  wordFedAppender_ = std::make_unique<pixelgpudetails::SiPixelRawToClusterGPUKernel::WordFedAppender>(maxFedWords_);
112  }
113 }
114 
117  desc.add<bool>("isRun2", true);
118  desc.add<bool>("IncludeErrors", true);
119  desc.add<bool>("UseQualityInfo", false);
120  desc.add<uint32_t>("MaxFEDWords", pixelgpudetails::MAX_FED * pixelgpudetails::MAX_WORD);
121  desc.add<int32_t>("clusterThreshold_layer1", kSiPixelClusterThresholdsDefaultPhase1.layer1);
122  desc.add<int32_t>("clusterThreshold_otherLayers", kSiPixelClusterThresholdsDefaultPhase1.otherLayers);
123  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
124  {
126  psd0.addOptional<std::vector<edm::InputTag>>("inputs");
127  psd0.addOptional<std::vector<double>>("deltaPhi");
128  psd0.addOptional<std::vector<double>>("maxZ");
129  psd0.addOptional<edm::InputTag>("beamSpot");
130  desc.add<edm::ParameterSetDescription>("Regions", psd0)
131  ->setComment("## Empty Regions PSet means complete unpacking");
132  }
133  desc.add<std::string>("CablingMapLabel", "")->setComment("CablingMap label"); //Tav
134  descriptions.addWithDefaultLabel(desc);
135 }
136 
138  const edm::EventSetup& iSetup,
139  edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
140  cms::cuda::ScopedContextAcquire ctx{iEvent.streamID(), std::move(waitingTaskHolder), ctxState_};
141 
142  auto hgpuMap = iSetup.getHandle(gpuMapToken_);
143  if (hgpuMap->hasQuality() != useQuality_) {
144  throw cms::Exception("LogicError")
145  << "UseQuality of the module (" << useQuality_
146  << ") differs the one from SiPixelROCsStatusAndMappingWrapper. Please fix your configuration.";
147  }
148  // get the GPU product already here so that the async transfer can begin
149  const auto* gpuMap = hgpuMap->getGPUProductAsync(ctx.stream());
150 
151  auto hgains = iSetup.getHandle(gainsToken_);
152  // get the GPU product already here so that the async transfer can begin
153  const auto* gpuGains = hgains->getGPUProductAsync(ctx.stream());
154 
155  cms::cuda::device::unique_ptr<unsigned char[]> modulesToUnpackRegional;
156  const unsigned char* gpuModulesToUnpack;
157 
158  if (regions_) {
159  regions_->run(iEvent, iSetup);
160  LogDebug("SiPixelRawToCluster") << "region2unpack #feds: " << regions_->nFEDs();
161  LogDebug("SiPixelRawToCluster") << "region2unpack #modules (BPIX,EPIX,total): " << regions_->nBarrelModules() << " "
162  << regions_->nForwardModules() << " " << regions_->nModules();
163  modulesToUnpackRegional = hgpuMap->getModToUnpRegionalAsync(*(regions_->modulesToUnpack()), ctx.stream());
164  gpuModulesToUnpack = modulesToUnpackRegional.get();
165  } else {
166  gpuModulesToUnpack = hgpuMap->getModToUnpAllAsync(ctx.stream());
167  }
168 
169  // initialize cabling map or update if necessary
170  if (recordWatcher_.check(iSetup)) {
171  // cabling map, which maps online address (fed->link->ROC->local pixel) to offline (DetId->global pixel)
172  auto cablingMap = iSetup.getTransientHandle(cablingMapToken_);
173  cablingMap_ = cablingMap.product();
174  fedIds_ = cablingMap->fedIds();
175  cabling_ = cablingMap->cablingTree();
176  LogDebug("map version:") << cabling_->version();
177  }
178 
179  const auto& buffers = iEvent.get(rawGetToken_);
180 
181  errors_.clear();
182 
183  // GPU specific: Data extraction for RawToDigi GPU
184  unsigned int wordCounterGPU = 0;
185  unsigned int fedCounter = 0;
186  bool errorsInEvent = false;
187 
188  // In CPU algorithm this loop is part of PixelDataFormatter::interpretRawData()
189  ErrorChecker errorcheck;
190  for (int fedId : fedIds_) {
191  if (regions_ && !regions_->mayUnpackFED(fedId))
192  continue;
193 
194  // for GPU
195  // first 150 index stores the fedId and next 150 will store the
196  // start index of word in that fed
198  fedCounter++;
199 
200  // get event data for this fed
201  const FEDRawData& rawData = buffers.FEDData(fedId);
202 
203  // GPU specific
204  int nWords = rawData.size() / sizeof(cms_uint64_t);
205  if (nWords == 0) {
206  continue;
207  }
208 
209  // check CRC bit
210  const cms_uint64_t* trailer = reinterpret_cast<const cms_uint64_t*>(rawData.data()) + (nWords - 1);
211  if (not errorcheck.checkCRC(errorsInEvent, fedId, trailer, errors_)) {
212  continue;
213  }
214 
215  // check headers
216  const cms_uint64_t* header = reinterpret_cast<const cms_uint64_t*>(rawData.data());
217  header--;
218  bool moreHeaders = true;
219  while (moreHeaders) {
220  header++;
221  bool headerStatus = errorcheck.checkHeader(errorsInEvent, fedId, header, errors_);
222  moreHeaders = headerStatus;
223  }
224 
225  // check trailers
226  bool moreTrailers = true;
227  trailer++;
228  while (moreTrailers) {
229  trailer--;
230  bool trailerStatus = errorcheck.checkTrailer(errorsInEvent, fedId, nWords, trailer, errors_);
231  moreTrailers = trailerStatus;
232  }
233 
234  const cms_uint32_t* bw = (const cms_uint32_t*)(header + 1);
235  const cms_uint32_t* ew = (const cms_uint32_t*)(trailer);
236 
237  assert(0 == (ew - bw) % 2);
238  wordFedAppender_->initializeWordFed(fedId, wordCounterGPU, bw, (ew - bw));
239  wordCounterGPU += (ew - bw);
240 
241  } // end of for loop
242 
243  nDigis_ = wordCounterGPU;
244 
245  if (nDigis_ == 0)
246  return;
247 
250  gpuMap,
251  gpuModulesToUnpack,
252  gpuGains,
255  wordCounterGPU,
256  fedCounter,
257  maxFedWords_,
258  useQuality_,
260  edm::MessageDrop::instance()->debugEnabled,
261  ctx.stream());
262 }
263 
266 
267  if (nDigis_ == 0) {
268  // default construct collections and place them in event
269  auto tmp = std::make_pair(SiPixelDigisCUDA{}, SiPixelClustersCUDA{});
270  ctx.emplace(iEvent, digiPutToken_, std::move(tmp.first));
271  ctx.emplace(iEvent, clusterPutToken_, std::move(tmp.second));
272  if (includeErrors_) {
273  ctx.emplace(iEvent, digiErrorPutToken_, SiPixelDigiErrorsCUDA{});
274  }
275  return;
276  }
277 
278  auto tmp = gpuAlgo_.getResults();
279  ctx.emplace(iEvent, digiPutToken_, std::move(tmp.first));
280  ctx.emplace(iEvent, clusterPutToken_, std::move(tmp.second));
281  if (includeErrors_) {
282  ctx.emplace(iEvent, digiErrorPutToken_, gpuAlgo_.getErrors());
283  }
284 }
285 
286 // define as framework plugin
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
std::unique_ptr< SiPixelFedCablingTree > cabling_
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
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, const uint32_t maxFedWords, bool useQualityInfo, bool includeErrors, bool debug, cudaStream_t stream)
edm::ESWatcher< SiPixelFedCablingMapRcd > recordWatcher_
cms::cuda::ContextState ctxState_
edm::EDPutTokenT< cms::cuda::Product< SiPixelDigiErrorsCUDA > > digiErrorPutToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unique_ptr< ClusterSequence > cs
std::pair< SiPixelDigisCUDA, SiPixelClustersCUDA > getResults()
edm::ESGetToken< SiPixelGainCalibrationForHLTGPU, SiPixelGainCalibrationForHLTGPURcd > gainsToken_
static MessageDrop * instance()
Definition: MessageDrop.cc:33
edm::EDPutTokenT< cms::cuda::Product< SiPixelClustersCUDA > > clusterPutToken_
const SiPixelFedCablingMap * cablingMap_
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
assert(be >=bs)
std::unique_ptr< pixelgpudetails::SiPixelRawToClusterGPUKernel::WordFedAppender > wordFedAppender_
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
edm::EDPutTokenT< cms::cuda::Product< SiPixelDigisCUDA > > digiPutToken_
bool checkHeader(bool &errorsInEvent, int fedId, const Word64 *header, SiPixelFormatterErrors &errors) const
int iEvent
Definition: GenABIO.cc:224
bool enabled() const
Definition: CUDAService.h:22
def move
Definition: eostools.py:511
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
std::vector< std::string > getParameterNames() const
ParameterDescriptionBase * add(U const &iLabel, T const &value)
unsigned int cms_uint32_t
Definition: typedefs.h:15
std::vector< unsigned int > fedIds_
constexpr unsigned int MAX_FED
bool checkCRC(bool &errorsInEvent, int fedId, const Word64 *trailer, SiPixelFormatterErrors &errors) const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
constexpr SiPixelClusterThresholds kSiPixelClusterThresholdsDefaultPhase1
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
void acquire(const edm::Event &iEvent, const edm::EventSetup &iSetup, edm::WaitingTaskWithArenaHolder waitingTaskHolder) override
ESTransientHandle< T > getTransientHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:162
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
const SiPixelClusterThresholds clusterThresholds_
StreamID streamID() const
Definition: Event.h:98
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
pixelgpudetails::SiPixelRawToClusterGPUKernel gpuAlgo_
SiPixelRawToClusterCUDA(const edm::ParameterSet &iConfig)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
unsigned long long cms_uint64_t
Definition: typedefs.h:17
~SiPixelRawToClusterCUDA() override=default
tmp
align.sh
Definition: createJobs.py:716
std::unique_ptr< PixelUnpackingRegions > regions_
edm::ESGetToken< SiPixelROCsStatusAndMappingWrapper, CkfComponentsRecord > gpuMapToken_
PixelDataFormatter::Errors errors_
edm::EDGetTokenT< FEDRawDataCollection > rawGetToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
bool checkTrailer(bool &errorsInEvent, int fedId, unsigned int nWords, const Word64 *trailer, SiPixelFormatterErrors &errors) const
std::map< cms_uint32_t, DetErrors > Errors
edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > cablingMapToken_
#define LogDebug(id)