60 cablingMap.rawId()[
index], cablingMap.rocInDet()[
index], cablingMap.moduleId()[
index]};
69 int slopeRow = 0, slopeCol = 0;
70 int rowOffset = 0, colOffset = 0;
73 if (
side == -1 && layer != 1) {
74 if (rocIdInDetUnit < 8) {
86 if (rocIdInDetUnit < 8) {
101 if (rocIdInDetUnit < 8) {
113 if (rocIdInDetUnit < 8) {
128 uint32_t gRow = rowOffset + slopeRow *
local.row;
129 uint32_t gCol = colOffset + slopeCol *
local.col;
135 uint8_t errorType = 0;
140 printf(
"Error in Fed: %i, invalid channel Id (errorType = 35\n)",
fedId);
146 printf(
"Error in Fed: %i, invalid ROC Id (errorType = 36)\n",
fedId);
152 printf(
"Error in Fed: %i, invalid dcol/pixel value (errorType = 37)\n",
fedId);
158 printf(
"Error in Fed: %i, dcol/pixel read out of order (errorType = 38)\n",
fedId);
164 printf(
"Cabling check returned unexpected result, status = %i\n",
status);
178 ALPAKA_FN_ACC
bool dcolIsValid(uint32_t dcol, uint32_t pxid) {
return ((dcol < 26) & (2 <= pxid) & (pxid < 162)); }
184 bool debug =
false) {
188 bool errorFound =
false;
195 if (
index > 1 &&
index <= cablingMap.size()) {
196 if (!(link == cablingMap.link()[
index] && 1 == cablingMap.roc()[
index]))
199 if (
debug and errorFound)
200 printf(
"Invalid ROC = 25 found (errorType = 25)\n");
205 printf(
"Gap word found (errorType = 26)\n");
211 printf(
"Dummy word found (errorType = 27)\n");
217 printf(
"Error fifo nearly full (errorType = 28)\n");
223 printf(
"Timeout on a channel (errorType = 29)\n");
226 printf(
"...first errorType=29 error, this gets masked out\n");
233 printf(
"TBM error trailer (errorType = 30)\n");
234 int StateMatch_bits = 4;
235 int StateMatch_shift = 8;
236 uint32_t StateMatch_mask = ~(~uint32_t(0) << StateMatch_bits);
237 int StateMatch = (errorWord >> StateMatch_shift) & StateMatch_mask;
238 if (StateMatch != 1 && StateMatch != 8) {
240 printf(
"FED error 30 with unexpected State Bits (errorType = 30)\n");
249 printf(
"Event number error (errorType = 31)\n");
257 return errorFound ? errorType : 0;
264 bool debug =
false) {
265 uint32_t rID = 0xffffffff;
276 if (rID_temp != 9999)
282 const int DB0_shift = 0;
283 const int DB1_shift = DB0_shift + 1;
284 const int DB2_shift = DB1_shift + 1;
285 const int DB3_shift = DB2_shift + 1;
286 const int DB4_shift = DB3_shift + 1;
287 const uint32_t DataBit_mask = ~(~uint32_t(0) << 1);
289 int CH1 = (errWord >> DB0_shift) & DataBit_mask;
290 int CH2 = (errWord >> DB1_shift) & DataBit_mask;
291 int CH3 = (errWord >> DB2_shift) & DataBit_mask;
292 int CH4 = (errWord >> DB3_shift) & DataBit_mask;
293 int CH5 = (errWord >> DB4_shift) & DataBit_mask;
296 uint32_t BLOCK_mask = ~(~uint32_t(0) << BLOCK_bits);
297 int BLOCK = (errWord >> BLOCK_shift) & BLOCK_mask;
298 int localCH = 1 * CH1 + 2 * CH2 + 3 * CH3 + 4 * CH4 + 5 * CH5;
300 chanNmbr = (BLOCK / 2) * 9 + localCH;
302 chanNmbr = ((BLOCK - 1) / 2) * 9 + 4 + localCH;
303 if ((chanNmbr < 1) || (chanNmbr > 36))
307 uint32_t link = chanNmbr;
309 if (rID_temp != 9999)
318 if (rID_temp != 9999)
331 template <
typename TAcc>
334 const unsigned char *modToUnp,
335 const uint32_t wordCounter,
336 const uint32_t *
word,
345 auto dvgi = digisView[gIndex];
349 bool skipROC =
false;
352 err[gIndex].size() = 0;
364 uint32_t
ww =
word[gIndex];
384 uint32_t rocIdInDetUnit =
detId.rocInDet;
389 if (useQualityInfo) {
390 skipROC = cablingMap.badRocs()[
index];
394 skipROC = modToUnp[
index];
410 side = (panel == 1) ? -1 : 1;
427 printf(
"BPIX1 Error status: %i\n",
error);
436 uint32_t
col = dcol * 2 + pxid % 2;
444 printf(
"Error status: %i %d %d %d %d\n",
error, dcol, pxid,
fedId,
roc);
450 dvgi.xx() = globalPix.
row;
451 dvgi.yy() = globalPix.
col;
454 dvgi.moduleId() =
detId.moduleId;
455 dvgi.rawIdArr() =
rawId;
461 template <
typename TrackerTraits>
463 template <
typename TAcc>
471 [[maybe_unused]]
const uint32_t blockIdxLocal(alpaka::getIdx<alpaka::Grid, alpaka::Blocks>(acc)[0u]);
473 [[maybe_unused]]
const uint32_t
gridDimension(alpaka::getWorkDiv<alpaka::Grid, alpaka::Blocks>(acc)[0u]);
485 auto &&
ws = alpaka::declareSharedVar<uint32_t[32], __COUNTER__>(acc);
488 acc, clus_view.clusModuleStart() + 1, clus_view.clusModuleStart() + 1, 1024,
ws);
491 acc, clus_view.clusModuleStart() + 1024 + 1, clus_view.clusModuleStart() + 1024 + 1, leftModules,
ws);
495 acc, clus_view.clusModuleStart() + 2048 + 1, clus_view.clusModuleStart() + 2048 + 1, 1024,
ws);
497 clus_view.clusModuleStart() + 3072 + 1,
498 clus_view.clusModuleStart() + 3072 + 1,
505 clus_view[
i].clusModuleStart() += clus_view[1024].clusModuleStart();
507 alpaka::syncBlockThreads(acc);
511 clus_view[
i].clusModuleStart() += clus_view[2048].clusModuleStart();
513 alpaka::syncBlockThreads(acc);
516 clus_view[
i].clusModuleStart() += clus_view[3072].clusModuleStart();
518 alpaka::syncBlockThreads(acc);
534 if (
i == bpix2 ||
i == fpix1)
535 printf(
"moduleStart %d %d\n",
i, clus_view[
i].
moduleStart());
541 if (clus_view[
i].clusModuleStart() > MAX_HITS)
542 clus_view[
i].clusModuleStart() = MAX_HITS;
549 template <
typename TrackerTraits>
554 const unsigned char *modToUnp,
557 const uint32_t wordCounter,
558 const uint32_t fedCounter,
562 nDigis = wordCounter;
565 std::cout <<
"decoding " << wordCounter <<
" digis." << std::endl;
575 const int threadsPerBlockOrElementsPerThread =
576 cms::alpakatools::requires_single_thread_per_block_v<Acc1D> ? 32 : 512;
579 const auto workDiv = cms::alpakatools::make_workdiv<Acc1D>(
blocks, threadsPerBlockOrElementsPerThread);
580 assert(0 == wordCounter % 2);
582 auto word_d = cms::alpakatools::make_device_buffer<uint32_t[]>(
queue, wordCounter);
586 auto fedId_d = cms::alpakatools::make_device_buffer<uint8_t[]>(
queue, wordCounter / 2);
587 alpaka::memcpy(
queue, word_d, wordFed.
word(), wordCounter);
588 alpaka::memcpy(
queue, fedId_d, wordFed.
fedId(), wordCounter / 2);
590 alpaka::exec<Acc1D>(
queue,
599 digiErrors_d->view(),
606 std::cout <<
"RawToDigi_kernel was run smoothly!" << std::endl;
616 const int threadsPerBlockOrElementsPerThread = []() {
617 if constexpr (std::is_same_v<Device, alpaka_common::DevHost>) {
625 threadsPerBlockOrElementsPerThread);
626 const auto workDiv = cms::alpakatools::make_workdiv<Acc1D>(
blocks, threadsPerBlockOrElementsPerThread);
629 queue, workDiv,
CalibDigis{}, clusterThresholds, digis_d->view(), clusters_d->view(),
gains, wordCounter);
633 std::cout <<
"CountModules kernel launch with " <<
blocks <<
" blocks of " << threadsPerBlockOrElementsPerThread
634 <<
" threadsPerBlockOrElementsPerThread\n";
638 queue, workDiv, CountModules<TrackerTraits>{}, digis_d->view(), clusters_d->view(), wordCounter);
640 auto moduleStartFirstElement =
642 alpaka::memcpy(
queue, nModules_Clusters_h, moduleStartFirstElement);
648 constexpr auto threadsOrElementsFindClus = 256;
650 const auto workDivMaxNumModules =
651 cms::alpakatools::make_workdiv<Acc1D>(
numberOfModules, threadsOrElementsFindClus);
658 <<
" threadsPerBlockOrElementsPerThread\n";
662 queue, workDivMaxNumModules, FindClus<TrackerTraits>{}, digis_d->view(), clusters_d->view(), wordCounter);
668 constexpr auto threadsPerBlockChargeCut = 256;
669 const auto workDivChargeCut = cms::alpakatools::make_workdiv<Acc1D>(
numberOfModules, threadsPerBlockChargeCut);
671 alpaka::exec<Acc1D>(
queue,
684 const auto workDivOneBlock = cms::alpakatools::make_workdiv<Acc1D>(1u, 1024u);
694 alpaka::getDev(
queue), clusters_d->const_view().clusModuleStart() +
startBPIX2, 1u);
696 alpaka::memcpy(
queue, nModules_Clusters_h_1, clusModuleStartLastElement);
699 alpaka::memcpy(
queue, nModules_Clusters_h_2, bpix2ClusterStart);
703 std::cout <<
"SiPixelClusterizerAlpaka results:" << std::endl
704 <<
" > no. of digis: " << nDigis << std::endl
705 <<
" > no. of active modules: " << nModules_Clusters_h[0] << std::endl
706 <<
" > no. of clusters: " << nModules_Clusters_h[1] << std::endl
707 <<
" > bpix2 offset: " << nModules_Clusters_h[2] << std::endl;
713 template <
typename TrackerTraits>
718 const uint32_t numDigis) {
724 const auto threadsPerBlockOrElementsPerThread = 512;
727 const auto workDiv = cms::alpakatools::make_workdiv<Acc1D>(
blocks, threadsPerBlockOrElementsPerThread);
734 std::cout <<
"CountModules kernel launch with " <<
blocks <<
" blocks of " << threadsPerBlockOrElementsPerThread
735 <<
" threadsPerBlockOrElementsPerThread\n";
738 queue, workDiv, CountModules<pixelTopology::Phase2>{}, digis_view, clusters_d->view(), numDigis);
740 auto moduleStartFirstElement =
742 alpaka::memcpy(
queue, nModules_Clusters_h, moduleStartFirstElement);
746 const auto threadsPerBlockFindClus = 256;
747 const auto workDivMaxNumModules = cms::alpakatools::make_workdiv<Acc1D>(
numberOfModules, threadsPerBlockFindClus);
752 <<
" threadsPerBlockOrElementsPerThread\n";
755 queue, workDivMaxNumModules, FindClus<TrackerTraits>{}, digis_view, clusters_d->view(), numDigis);
761 alpaka::exec<Acc1D>(
queue,
762 workDivMaxNumModules,
775 const auto workDivOneBlock = cms::alpakatools::make_workdiv<Acc1D>(1u, 1024u);
784 alpaka::getDev(
queue), clusters_d->const_view().clusModuleStart() +
startBPIX2, 1u);
786 alpaka::memcpy(
queue, nModules_Clusters_h_1, clusModuleStartLastElement);
789 alpaka::memcpy(
queue, nModules_Clusters_h_2, bpix2ClusterStart);
793 std::cout <<
"SiPixelPhase2DigiToCluster: results \n" 794 <<
" > no. of digis: " << numDigis << std::endl
795 <<
" > no. of active modules: " << nModules_Clusters_h[0] << std::endl
796 <<
" > no. of clusters: " << nModules_Clusters_h[1] << std::endl
797 <<
" > bpix2 offset: " << nModules_Clusters_h[2] << std::endl;
const uint32_t gridDimension(alpaka::getWorkDiv< alpaka::Grid, alpaka::Blocks >(acc)[0u])
void makePhase1ClustersAsync(Queue &queue, const SiPixelClusterThresholds clusterThresholds, const SiPixelMappingSoAConstView &cablingMap, const unsigned char *modToUnp, const SiPixelGainCalibrationForHLTSoAConstView &gains, const WordFedAppender &wordFed, const uint32_t wordCounter, const uint32_t fedCounter, bool useQualityInfo, bool includeErrors, bool debug)
constexpr uint32_t moduleStartBit
constexpr int nMaxModules
ALPAKA_FN_ACC uint32_t getErrRawID(uint8_t fedId, uint32_t errWord, uint32_t errorType, const SiPixelMappingSoAConstView &cablingMap, bool debug=false)
constexpr uint32_t DCOL_shift
constexpr uint32_t DCOL_mask
constexpr uint32_t PXID_shift
constexpr uint32_t ERROR_mask
constexpr uint32_t COL_shift
constexpr uint32_t layerMask
constexpr uint32_t numRowsInRoc
ALPAKA_FN_ACC int side(int ieta, int iphi)
constexpr uint32_t ROC_shift
ALPAKA_FN_ACC void operator()(const TAcc &acc, const SiPixelMappingSoAConstView &cablingMap, const unsigned char *modToUnp, const uint32_t wordCounter, const uint32_t *word, const uint8_t *fedIds, SiPixelDigisSoAView digisView, SiPixelDigiErrorsSoAView err, bool useQualityInfo, bool includeErrors, bool debug) const
constexpr uint32_t ADC_shift
constexpr uint32_t ROW_shift
ALPAKA_ASSERT_OFFLOAD(offsets)
static constexpr uint16_t numberOfModules
void makePhase2ClustersAsync(Queue &queue, const SiPixelClusterThresholds clusterThresholds, SiPixelDigisSoAView &digis_view, const uint32_t numDigis)
constexpr uint16_t numberOfModules
constexpr uint32_t panelMask
constexpr uint32_t OMIT_ERR_shift
static constexpr uint32_t const * layerStart
ALPAKA_FN_ACC ::pixelDetails::Pixel frameConversion(bool bpix, int side, uint32_t layer, uint32_t rocIdInDetUnit, ::pixelDetails::Pixel local)
constexpr uint32_t OMIT_ERR_mask
ALPAKA_FN_ACC bool dcolIsValid(uint32_t dcol, uint32_t pxid)
ALPAKA_FN_ACC uint32_t getRoc(uint32_t ww)
T1 atomicInc(T1 *a, T2 b)
ALPAKA_FN_ACC uint32_t getADC(uint32_t ww)
std::conditional_t< std::is_same_v< Device, alpaka::DevCpu >, SiPixelDigisHost, SiPixelDigisDevice< Device > > SiPixelDigisSoACollection
constexpr unsigned int MAX_ROC
constexpr uint32_t ROC_mask
constexpr uint32_t moduleMask
constexpr uint32_t maxROCIndex
constexpr uint16_t invalidModuleId
ALPAKA_FN_ACC ::pixelDetails::DetIdGPU getRawId(const SiPixelMappingSoAConstView &cablingMap, uint8_t fed, uint32_t link, uint32_t roc)
constexpr float gains[NGAINS]
ALPAKA_FN_ACC uint32_t getLink(uint32_t ww)
constexpr uint32_t LINK_shift
constexpr uint32_t panelStartBit
ALPAKA_FN_ACC bool isBarrel(uint32_t rawId)
ALPAKA_FN_ACC bool rocRowColIsValid(uint32_t rocRow, uint32_t rocCol)
constexpr uint32_t LINK_mask
constexpr uint32_t layerStartBit
uint16_t *__restrict__ uint16_t const *__restrict__ uint32_t const *__restrict__ moduleStart
static constexpr uint32_t layerStart[numberOfLayers+1]
ALPAKA_FN_ACC uint8_t conversionError(uint8_t fedId, uint8_t status, bool debug=false)
constexpr uint32_t COL_mask
std::conditional_t< std::is_same_v< Device, alpaka::DevCpu >, SiPixelDigiErrorsHost, SiPixelDigiErrorsDevice< Device > > SiPixelDigiErrorsSoACollection
constexpr uint32_t numColsInRoc
constexpr uint32_t ADC_mask
constexpr uint32_t ROC_mask
ALPAKA_FN_ACC void operator()(const TAcc &acc, SiPixelClustersSoAView clus_view) const
constexpr uint32_t ROW_mask
constexpr uint32_t LINK_mask
ALPAKA_FN_ACC uint8_t checkROC(uint32_t errorWord, uint8_t fedId, uint32_t link, const SiPixelMappingSoAConstView &cablingMap, bool debug=false)
constexpr unsigned int MAX_LINK
constexpr uint32_t PXID_mask
std::conditional_t< std::is_same_v< Device, alpaka::DevCpu >, SiPixelClustersHost, SiPixelClustersDevice< Device > > SiPixelClustersSoACollection
constexpr uint32_t maxHitsInModule()