Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:18

0001 #ifndef RecoLocalTracker_SiPixelClusterizer_SiPixelRawToClusterKernel_h
0002 #define RecoLocalTracker_SiPixelClusterizer_SiPixelRawToClusterKernel_h
0003 
0004 #include <algorithm>
0005 #include <optional>
0006 #include <utility>
0007 
0008 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0009 #include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
0010 
0011 #include "DataFormats/SiPixelClusterSoA/interface/alpaka/SiPixelClustersSoACollection.h"
0012 #include "DataFormats/SiPixelClusterSoA/interface/SiPixelClustersDevice.h"
0013 #include "DataFormats/SiPixelDigiSoA/interface/SiPixelDigisDevice.h"
0014 #include "DataFormats/SiPixelDigiSoA/interface/alpaka/SiPixelDigisSoACollection.h"
0015 #include "DataFormats/SiPixelDigiSoA/interface/alpaka/SiPixelDigiErrorsSoACollection.h"
0016 #include "DataFormats/SiPixelDigiSoA/interface/SiPixelDigiErrorsDevice.h"
0017 #include "DataFormats/SiPixelClusterSoA/interface/ClusteringConstants.h"
0018 
0019 #include "CondFormats/SiPixelObjects/interface/SiPixelGainCalibrationForHLTLayout.h"
0020 #include "CondFormats/SiPixelObjects/interface/alpaka/SiPixelGainCalibrationForHLTDevice.h"
0021 #include "CondFormats/SiPixelObjects/interface/alpaka/SiPixelMappingDevice.h"
0022 
0023 #include "DataFormats/SiPixelRawData/interface/SiPixelErrorCompact.h"
0024 #include "DataFormats/SiPixelRawData/interface/SiPixelFormatterErrors.h"
0025 #include "DataFormats/SiPixelDetId/interface/PixelChannelIdentifier.h"
0026 
0027 namespace pixelDetails {
0028 
0029   constexpr auto MAX_LINK = pixelgpudetails::MAX_LINK;
0030   constexpr auto MAX_SIZE = pixelgpudetails::MAX_SIZE;
0031   constexpr auto MAX_ROC = pixelgpudetails::MAX_ROC;
0032 
0033   // Phase 1 geometry constants
0034   constexpr uint32_t layerStartBit = 20;
0035   constexpr uint32_t ladderStartBit = 12;
0036   constexpr uint32_t moduleStartBit = 2;
0037 
0038   constexpr uint32_t panelStartBit = 10;
0039   constexpr uint32_t diskStartBit = 18;
0040   constexpr uint32_t bladeStartBit = 12;
0041 
0042   constexpr uint32_t layerMask = 0xF;
0043   constexpr uint32_t ladderMask = 0xFF;
0044   constexpr uint32_t moduleMask = 0x3FF;
0045   constexpr uint32_t panelMask = 0x3;
0046   constexpr uint32_t diskMask = 0xF;
0047   constexpr uint32_t bladeMask = 0x3F;
0048 
0049   constexpr uint32_t LINK_bits = 6;
0050   constexpr uint32_t ROC_bits = 5;
0051   constexpr uint32_t DCOL_bits = 5;
0052   constexpr uint32_t PXID_bits = 8;
0053   constexpr uint32_t ADC_bits = 8;
0054 
0055   // special for layer 1
0056   constexpr uint32_t LINK_bits_l1 = 6;
0057   constexpr uint32_t ROC_bits_l1 = 5;
0058   constexpr uint32_t COL_bits_l1 = 6;
0059   constexpr uint32_t ROW_bits_l1 = 7;
0060   constexpr uint32_t OMIT_ERR_bits = 1;
0061 
0062   constexpr uint32_t maxROCIndex = 8;
0063   constexpr uint32_t numRowsInRoc = 80;
0064   constexpr uint32_t numColsInRoc = 52;
0065 
0066   constexpr uint32_t MAX_WORD = 2000;
0067 
0068   constexpr uint32_t ADC_shift = 0;
0069   constexpr uint32_t PXID_shift = ADC_shift + ADC_bits;
0070   constexpr uint32_t DCOL_shift = PXID_shift + PXID_bits;
0071   constexpr uint32_t ROC_shift = DCOL_shift + DCOL_bits;
0072   constexpr uint32_t LINK_shift = ROC_shift + ROC_bits_l1;
0073   // special for layer 1 ROC
0074   constexpr uint32_t ROW_shift = ADC_shift + ADC_bits;
0075   constexpr uint32_t COL_shift = ROW_shift + ROW_bits_l1;
0076   constexpr uint32_t OMIT_ERR_shift = 20;
0077 
0078   constexpr uint32_t LINK_mask = ~(~uint32_t(0) << LINK_bits_l1);
0079   constexpr uint32_t ROC_mask = ~(~uint32_t(0) << ROC_bits_l1);
0080   constexpr uint32_t COL_mask = ~(~uint32_t(0) << COL_bits_l1);
0081   constexpr uint32_t ROW_mask = ~(~uint32_t(0) << ROW_bits_l1);
0082   constexpr uint32_t DCOL_mask = ~(~uint32_t(0) << DCOL_bits);
0083   constexpr uint32_t PXID_mask = ~(~uint32_t(0) << PXID_bits);
0084   constexpr uint32_t ADC_mask = ~(~uint32_t(0) << ADC_bits);
0085   constexpr uint32_t ERROR_mask = ~(~uint32_t(0) << ROC_bits_l1);
0086   constexpr uint32_t OMIT_ERR_mask = ~(~uint32_t(0) << OMIT_ERR_bits);
0087 
0088   struct DetIdGPU {
0089     uint32_t rawId;
0090     uint32_t rocInDet;
0091     uint32_t moduleId;
0092   };
0093 
0094   struct Pixel {
0095     uint32_t row;
0096     uint32_t col;
0097   };
0098 
0099   ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr pixelchannelidentifierimpl::Packing packing() {
0100     return PixelChannelIdentifier::thePacking;
0101   }
0102 
0103   ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr uint32_t pack(uint32_t row,
0104                                                               uint32_t col,
0105                                                               uint32_t adc,
0106                                                               uint32_t flag = 0) {
0107     constexpr pixelchannelidentifierimpl::Packing thePacking = packing();
0108     adc = std::min(adc, uint32_t(thePacking.max_adc));
0109 
0110     return (row << thePacking.row_shift) | (col << thePacking.column_shift) | (adc << thePacking.adc_shift);
0111   }
0112 
0113   constexpr uint32_t pixelToChannel(int row, int col) {
0114     constexpr pixelchannelidentifierimpl::Packing thePacking = packing();
0115     return (row << thePacking.column_width) | col;
0116   }
0117 
0118 }  // namespace pixelDetails
0119 
0120 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0121   namespace pixelDetails {
0122 
0123     class WordFedAppender {
0124     public:
0125       WordFedAppender(Queue& queue, uint32_t words)
0126           : word_{cms::alpakatools::make_host_buffer<unsigned int[]>(queue, words)},
0127             fedId_{cms::alpakatools::make_host_buffer<unsigned char[]>(queue, words)} {};
0128 
0129       void initializeWordFed(int fedId, unsigned int wordCounterGPU, const uint32_t* src, unsigned int length) {
0130         std::memcpy(word_.data() + wordCounterGPU, src, sizeof(uint32_t) * length);
0131         std::memset(fedId_.data() + wordCounterGPU / 2, fedId - 1200, length / 2);
0132       }
0133       auto word() const { return word_; }
0134       auto fedId() const { return fedId_; }
0135 
0136     private:
0137       cms::alpakatools::host_buffer<unsigned int[]> word_;
0138       cms::alpakatools::host_buffer<unsigned char[]> fedId_;
0139     };
0140 
0141     template <typename TrackerTraits>
0142     class SiPixelRawToClusterKernel {
0143     public:
0144       SiPixelRawToClusterKernel() : nModules_Clusters_h{cms::alpakatools::make_host_buffer<uint32_t[], Platform>(3u)} {}
0145 
0146       ~SiPixelRawToClusterKernel() = default;
0147 
0148       SiPixelRawToClusterKernel(const SiPixelRawToClusterKernel&) = delete;
0149       SiPixelRawToClusterKernel(SiPixelRawToClusterKernel&&) = delete;
0150       SiPixelRawToClusterKernel& operator=(const SiPixelRawToClusterKernel&) = delete;
0151       SiPixelRawToClusterKernel& operator=(SiPixelRawToClusterKernel&&) = delete;
0152 
0153       void makePhase1ClustersAsync(Queue& queue,
0154                                    const SiPixelClusterThresholds clusterThresholds,
0155                                    const SiPixelMappingSoAConstView& cablingMap,
0156                                    const unsigned char* modToUnp,
0157                                    const SiPixelGainCalibrationForHLTSoAConstView& gains,
0158                                    const WordFedAppender& wordFed,
0159                                    const uint32_t wordCounter,
0160                                    const uint32_t fedCounter,
0161                                    bool useQualityInfo,
0162                                    bool includeErrors,
0163                                    bool debug);
0164 
0165       void makePhase2ClustersAsync(Queue& queue,
0166                                    const SiPixelClusterThresholds clusterThresholds,
0167                                    SiPixelDigisSoAView& digis_view,
0168                                    const uint32_t numDigis);
0169 
0170       SiPixelDigisSoACollection getDigis() {
0171         digis_d->setNModulesDigis(nModules_Clusters_h[0], nDigis);
0172         return std::move(*digis_d);
0173       }
0174 
0175       SiPixelClustersSoACollection getClusters() {
0176         clusters_d->setNClusters(nModules_Clusters_h[1], nModules_Clusters_h[2]);
0177         return std::move(*clusters_d);
0178       }
0179 
0180       SiPixelDigiErrorsSoACollection getErrors() { return std::move(*digiErrors_d); }
0181 
0182       auto nModules() { return nModules_Clusters_h[0]; }
0183 
0184     private:
0185       uint32_t nDigis = 0;
0186 
0187       // Data to be put in the event
0188       cms::alpakatools::host_buffer<uint32_t[]> nModules_Clusters_h;
0189       std::optional<SiPixelDigisSoACollection> digis_d;
0190       std::optional<SiPixelClustersSoACollection> clusters_d;
0191       std::optional<SiPixelDigiErrorsSoACollection> digiErrors_d;
0192     };
0193 
0194   }  // namespace pixelDetails
0195 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0196 
0197 #endif  // plugin_SiPixelClusterizer_alpaka_SiPixelRawToClusterKernel_h