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_;
83 };
84 
86  : rawGetToken_(consumes<FEDRawDataCollection>(iConfig.getParameter<edm::InputTag>("InputLabel"))),
87  digiPutToken_(produces<cms::cuda::Product<SiPixelDigisCUDA>>()),
88  clusterPutToken_(produces<cms::cuda::Product<SiPixelClustersCUDA>>()),
92  edm::ESInputTag("", iConfig.getParameter<std::string>("CablingMapLabel")))),
93  isRun2_(iConfig.getParameter<bool>("isRun2")),
94  includeErrors_(iConfig.getParameter<bool>("IncludeErrors")),
95  useQuality_(iConfig.getParameter<bool>("UseQualityInfo")),
96  maxFedWords_(iConfig.getParameter<uint32_t>("MaxFEDWords")),
97  clusterThresholds_{iConfig.getParameter<int32_t>("clusterThreshold_layer1"),
98  iConfig.getParameter<int32_t>("clusterThreshold_otherLayers")} {
99  if (includeErrors_) {
100  digiErrorPutToken_ = produces<cms::cuda::Product<SiPixelDigiErrorsCUDA>>();
101  }
102 
103  // regions
104  if (!iConfig.getParameter<edm::ParameterSet>("Regions").getParameterNames().empty()) {
105  regions_ = std::make_unique<PixelUnpackingRegions>(iConfig, consumesCollector());
106  }
107 
109  if (cs->enabled()) {
110  wordFedAppender_ = std::make_unique<pixelgpudetails::SiPixelRawToClusterGPUKernel::WordFedAppender>(maxFedWords_);
111  }
112 }
113 
116  desc.add<bool>("isRun2", true);
117  desc.add<bool>("IncludeErrors", true);
118  desc.add<bool>("UseQualityInfo", false);
119  desc.add<uint32_t>("MaxFEDWords", pixelgpudetails::MAX_FED * pixelgpudetails::MAX_WORD);
120  desc.add<int32_t>("clusterThreshold_layer1", kSiPixelClusterThresholdsDefaultPhase1.layer1);
121  desc.add<int32_t>("clusterThreshold_otherLayers", kSiPixelClusterThresholdsDefaultPhase1.otherLayers);
122  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
123  {
125  psd0.addOptional<std::vector<edm::InputTag>>("inputs");
126  psd0.addOptional<std::vector<double>>("deltaPhi");
127  psd0.addOptional<std::vector<double>>("maxZ");
128  psd0.addOptional<edm::InputTag>("beamSpot");
129  desc.add<edm::ParameterSetDescription>("Regions", psd0)
130  ->setComment("## Empty Regions PSet means complete unpacking");
131  }
132  desc.add<std::string>("CablingMapLabel", "")->setComment("CablingMap label"); //Tav
133  descriptions.addWithDefaultLabel(desc);
134 }
135 
137  const edm::EventSetup& iSetup,
138  edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
139  cms::cuda::ScopedContextAcquire ctx{iEvent.streamID(), std::move(waitingTaskHolder), ctxState_};
140 
141  auto hgpuMap = iSetup.getHandle(gpuMapToken_);
142  if (hgpuMap->hasQuality() != useQuality_) {
143  throw cms::Exception("LogicError")
144  << "UseQuality of the module (" << useQuality_
145  << ") differs the one from SiPixelROCsStatusAndMappingWrapper. Please fix your configuration.";
146  }
147  // get the GPU product already here so that the async transfer can begin
148  const auto* gpuMap = hgpuMap->getGPUProductAsync(ctx.stream());
149 
150  auto hgains = iSetup.getHandle(gainsToken_);
151  // get the GPU product already here so that the async transfer can begin
152  const auto* gpuGains = hgains->getGPUProductAsync(ctx.stream());
153 
154  cms::cuda::device::unique_ptr<unsigned char[]> modulesToUnpackRegional;
155  const unsigned char* gpuModulesToUnpack;
156 
157  if (regions_) {
158  regions_->run(iEvent, iSetup);
159  LogDebug("SiPixelRawToCluster") << "region2unpack #feds: " << regions_->nFEDs();
160  LogDebug("SiPixelRawToCluster") << "region2unpack #modules (BPIX,EPIX,total): " << regions_->nBarrelModules() << " "
161  << regions_->nForwardModules() << " " << regions_->nModules();
162  modulesToUnpackRegional = hgpuMap->getModToUnpRegionalAsync(*(regions_->modulesToUnpack()), ctx.stream());
163  gpuModulesToUnpack = modulesToUnpackRegional.get();
164  } else {
165  gpuModulesToUnpack = hgpuMap->getModToUnpAllAsync(ctx.stream());
166  }
167 
168  // initialize cabling map or update if necessary
169  if (recordWatcher_.check(iSetup)) {
170  // cabling map, which maps online address (fed->link->ROC->local pixel) to offline (DetId->global pixel)
171  auto cablingMap = iSetup.getTransientHandle(cablingMapToken_);
172  cablingMap_ = cablingMap.product();
173  fedIds_ = cablingMap->fedIds();
174  cabling_ = cablingMap->cablingTree();
175  LogDebug("map version:") << cabling_->version();
176  }
177 
178  const auto& buffers = iEvent.get(rawGetToken_);
179 
180  errors_.clear();
181 
182  // GPU specific: Data extraction for RawToDigi GPU
183  unsigned int wordCounterGPU = 0;
184  unsigned int fedCounter = 0;
185  bool errorsInEvent = false;
186 
187  // In CPU algorithm this loop is part of PixelDataFormatter::interpretRawData()
188  ErrorChecker errorcheck;
189  for (int fedId : fedIds_) {
190  if (regions_ && !regions_->mayUnpackFED(fedId))
191  continue;
192 
193  // for GPU
194  // first 150 index stores the fedId and next 150 will store the
195  // start index of word in that fed
197  fedCounter++;
198 
199  // get event data for this fed
200  const FEDRawData& rawData = buffers.FEDData(fedId);
201 
202  // GPU specific
203  int nWords = rawData.size() / sizeof(cms_uint64_t);
204  if (nWords == 0) {
205  continue;
206  }
207 
208  // check CRC bit
209  const cms_uint64_t* trailer = reinterpret_cast<const cms_uint64_t*>(rawData.data()) + (nWords - 1);
210  if (not errorcheck.checkCRC(errorsInEvent, fedId, trailer, errors_)) {
211  continue;
212  }
213 
214  // check headers
215  const cms_uint64_t* header = reinterpret_cast<const cms_uint64_t*>(rawData.data());
216  header--;
217  bool moreHeaders = true;
218  while (moreHeaders) {
219  header++;
220  bool headerStatus = errorcheck.checkHeader(errorsInEvent, fedId, header, errors_);
221  moreHeaders = headerStatus;
222  }
223 
224  // check trailers
225  bool moreTrailers = true;
226  trailer++;
227  while (moreTrailers) {
228  trailer--;
229  bool trailerStatus = errorcheck.checkTrailer(errorsInEvent, fedId, nWords, trailer, errors_);
230  moreTrailers = trailerStatus;
231  }
232 
233  const cms_uint32_t* bw = (const cms_uint32_t*)(header + 1);
234  const cms_uint32_t* ew = (const cms_uint32_t*)(trailer);
235 
236  assert(0 == (ew - bw) % 2);
237  wordFedAppender_->initializeWordFed(fedId, wordCounterGPU, bw, (ew - bw));
238  wordCounterGPU += (ew - bw);
239 
240  } // end of for loop
241 
244  gpuMap,
245  gpuModulesToUnpack,
246  gpuGains,
249  wordCounterGPU,
250  fedCounter,
251  maxFedWords_,
252  useQuality_,
254  edm::MessageDrop::instance()->debugEnabled,
255  ctx.stream());
256 }
257 
260 
261  auto tmp = gpuAlgo_.getResults();
262  ctx.emplace(iEvent, digiPutToken_, std::move(tmp.first));
263  ctx.emplace(iEvent, clusterPutToken_, std::move(tmp.second));
264  if (includeErrors_) {
265  ctx.emplace(iEvent, digiErrorPutToken_, gpuAlgo_.getErrors());
266  }
267 }
268 
269 // 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:168
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:157
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)