Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:42

0001 #ifndef RecoLocalCalo_EcalRecProducers_plugins_DeclsForKernels_h
0002 #define RecoLocalCalo_EcalRecProducers_plugins_DeclsForKernels_h
0003 
0004 #include <vector>
0005 
0006 #include <cuda.h>
0007 #include <cuda_runtime.h>
0008 
0009 #include "CUDADataFormats/EcalDigi/interface/DigisCollection.h"
0010 #include "CUDADataFormats/EcalRecHitSoA/interface/EcalRecHit.h"
0011 #include "CUDADataFormats/EcalRecHitSoA/interface/EcalUncalibratedRecHit.h"
0012 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
0013 #include "CondFormats/EcalObjects/interface/EcalChannelStatusCode.h"
0014 #include "CondFormats/EcalObjects/interface/EcalGainRatios.h"
0015 #include "CondFormats/EcalObjects/interface/EcalGainRatiosGPU.h"
0016 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstantsGPU.h"
0017 #include "CondFormats/EcalObjects/interface/EcalLaserAPDPNRatiosGPU.h"
0018 #include "CondFormats/EcalObjects/interface/EcalLaserAPDPNRatiosRefGPU.h"
0019 #include "CondFormats/EcalObjects/interface/EcalLaserAlphasGPU.h"
0020 #include "CondFormats/EcalObjects/interface/EcalLinearCorrectionsGPU.h"
0021 #include "CondFormats/EcalObjects/interface/EcalMultifitParametersGPU.h"
0022 #include "CondFormats/EcalObjects/interface/EcalPedestals.h"
0023 #include "CondFormats/EcalObjects/interface/EcalPedestalsGPU.h"
0024 #include "CondFormats/EcalObjects/interface/EcalPulseCovariancesGPU.h"
0025 #include "CondFormats/EcalObjects/interface/EcalPulseShapesGPU.h"
0026 #include "CondFormats/EcalObjects/interface/EcalRechitADCToGeVConstantGPU.h"
0027 #include "CondFormats/EcalObjects/interface/EcalRechitChannelStatusGPU.h"
0028 #include "CondFormats/EcalObjects/interface/EcalSamplesCorrelationGPU.h"
0029 #include "CondFormats/EcalObjects/interface/EcalTimeBiasCorrections.h"
0030 #include "CondFormats/EcalObjects/interface/EcalTimeBiasCorrectionsGPU.h"
0031 #include "CondFormats/EcalObjects/interface/EcalTimeCalibConstantsGPU.h"
0032 #include "CondFormats/EcalObjects/interface/EcalTimeOffsetConstant.h"
0033 #include "CondFormats/EcalObjects/interface/EcalWeightSet.h"
0034 #include "DataFormats/EcalRecHit/interface/RecoTypes.h"
0035 #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
0036 #include "RecoLocalCalo/EcalRecProducers/interface/EigenMatrixTypes_gpu.h"
0037 
0038 struct EcalPulseShape;
0039 class EcalSampleMask;
0040 class EcalTimeBiasCorrections;
0041 struct EcalPulseCovariance;
0042 class EcalDigiCollection;
0043 class EcalXtalGroupId;
0044 class EcalSamplesCorrelation;
0045 class EBDigiCollection;
0046 class EEDigiCollection;
0047 
0048 namespace ecal {
0049   namespace multifit {
0050 
0051     enum class TimeComputationState : char { NotFinished = 0, Finished = 1 };
0052     enum class MinimizationState : char {
0053       NotFinished = 0,
0054       Finished = 1,
0055       Precomputed = 2,
0056     };
0057 
0058     //
0059     struct EventInputDataGPU {
0060       ecal::DigisCollection<calo::common::DevStoragePolicy> const& ebDigis;
0061       ecal::DigisCollection<calo::common::DevStoragePolicy> const& eeDigis;
0062     };
0063 
0064     // parameters have a fixed type
0065     // Can we go by with single precision
0066     struct ConfigurationParameters {
0067       using type = double;
0068       // device ptrs
0069       const type *amplitudeFitParametersEB = nullptr, *amplitudeFitParametersEE = nullptr;
0070 
0071       uint32_t timeFitParametersSizeEB, timeFitParametersSizeEE;
0072       // device ptrs
0073       const type *timeFitParametersEB = nullptr, *timeFitParametersEE = nullptr;
0074 
0075       type timeFitLimitsFirstEB, timeFitLimitsFirstEE;
0076       type timeFitLimitsSecondEB, timeFitLimitsSecondEE;
0077 
0078       type timeConstantTermEB, timeConstantTermEE;
0079 
0080       type timeNconstEB, timeNconstEE;
0081 
0082       type amplitudeThreshEE, amplitudeThreshEB;
0083 
0084       type outOfTimeThreshG12pEB, outOfTimeThreshG12mEB;
0085       type outOfTimeThreshG12pEE, outOfTimeThreshG12mEE;
0086       type outOfTimeThreshG61pEE, outOfTimeThreshG61mEE;
0087       type outOfTimeThreshG61pEB, outOfTimeThreshG61mEB;
0088 
0089       std::array<uint32_t, 3> kernelMinimizeThreads;
0090 
0091       bool shouldRunTimingComputation;
0092     };
0093 
0094     struct EventOutputDataGPU {
0095       UncalibratedRecHit<::calo::common::DevStoragePolicy> recHitsEB, recHitsEE;
0096 
0097       void allocate(ConfigurationParameters const& configParameters,
0098                     uint32_t sizeEB,
0099                     uint32_t sizeEE,
0100                     cudaStream_t cudaStream) {
0101         recHitsEB.amplitudesAll = cms::cuda::make_device_unique<reco::ComputationScalarType[]>(
0102             sizeEB * EcalDataFrame::MAXSAMPLES, cudaStream);
0103         recHitsEB.amplitude = cms::cuda::make_device_unique<reco::StorageScalarType[]>(sizeEB, cudaStream);
0104         recHitsEB.chi2 = cms::cuda::make_device_unique<reco::StorageScalarType[]>(sizeEB, cudaStream);
0105         recHitsEB.pedestal = cms::cuda::make_device_unique<reco::StorageScalarType[]>(sizeEB, cudaStream);
0106 
0107         if (configParameters.shouldRunTimingComputation) {
0108           recHitsEB.jitter = cms::cuda::make_device_unique<reco::StorageScalarType[]>(sizeEB, cudaStream);
0109           recHitsEB.jitterError = cms::cuda::make_device_unique<reco::StorageScalarType[]>(sizeEB, cudaStream);
0110         }
0111 
0112         recHitsEB.did = cms::cuda::make_device_unique<uint32_t[]>(sizeEB, cudaStream);
0113         recHitsEB.flags = cms::cuda::make_device_unique<uint32_t[]>(sizeEB, cudaStream);
0114 
0115         recHitsEE.amplitudesAll = cms::cuda::make_device_unique<reco::ComputationScalarType[]>(
0116             sizeEE * EcalDataFrame::MAXSAMPLES, cudaStream);
0117         recHitsEE.amplitude = cms::cuda::make_device_unique<reco::StorageScalarType[]>(sizeEE, cudaStream);
0118         recHitsEE.chi2 = cms::cuda::make_device_unique<reco::StorageScalarType[]>(sizeEE, cudaStream);
0119         recHitsEE.pedestal = cms::cuda::make_device_unique<reco::StorageScalarType[]>(sizeEE, cudaStream);
0120 
0121         if (configParameters.shouldRunTimingComputation) {
0122           recHitsEE.jitter = cms::cuda::make_device_unique<reco::StorageScalarType[]>(sizeEE, cudaStream);
0123           recHitsEE.jitterError = cms::cuda::make_device_unique<reco::StorageScalarType[]>(sizeEE, cudaStream);
0124         }
0125 
0126         recHitsEE.did = cms::cuda::make_device_unique<uint32_t[]>(sizeEE, cudaStream);
0127         recHitsEE.flags = cms::cuda::make_device_unique<uint32_t[]>(sizeEE, cudaStream);
0128       }
0129     };
0130 
0131     template <typename EigenM>
0132     constexpr auto getLength() -> uint32_t {
0133       return EigenM::RowsAtCompileTime * EigenM::ColsAtCompileTime;
0134     }
0135 
0136     struct EventDataForScratchGPU {
0137       using SVT = SampleVector::Scalar;
0138       using SGVT = SampleGainVector::Scalar;
0139       using SMT = SampleMatrix::Scalar;
0140       using PMT = PulseMatrixType::Scalar;
0141       using BXVT = BXVectorType::Scalar;
0142 
0143       cms::cuda::device::unique_ptr<SVT[]> samples;
0144       cms::cuda::device::unique_ptr<SGVT[]> gainsNoise;
0145 
0146       cms::cuda::device::unique_ptr<SMT[]> noisecov;
0147       cms::cuda::device::unique_ptr<PMT[]> pulse_matrix;
0148       cms::cuda::device::unique_ptr<BXVT[]> activeBXs;
0149       cms::cuda::device::unique_ptr<char[]> acState;
0150 
0151       cms::cuda::device::unique_ptr<bool[]> hasSwitchToGain6, hasSwitchToGain1, isSaturated;
0152 
0153       cms::cuda::device::unique_ptr<SVT[]> sample_values, sample_value_errors;
0154       cms::cuda::device::unique_ptr<bool[]> useless_sample_values;
0155       cms::cuda::device::unique_ptr<SVT[]> chi2sNullHypot;
0156       cms::cuda::device::unique_ptr<SVT[]> sum0sNullHypot;
0157       cms::cuda::device::unique_ptr<SVT[]> sumAAsNullHypot;
0158       cms::cuda::device::unique_ptr<char[]> pedestal_nums;
0159       cms::cuda::device::unique_ptr<SVT[]> tMaxAlphaBetas, tMaxErrorAlphaBetas;
0160       cms::cuda::device::unique_ptr<SVT[]> accTimeMax, accTimeWgt;
0161       cms::cuda::device::unique_ptr<SVT[]> ampMaxAlphaBeta, ampMaxError;
0162       cms::cuda::device::unique_ptr<SVT[]> timeMax, timeError;
0163       cms::cuda::device::unique_ptr<TimeComputationState[]> tcState;
0164 
0165       void allocate(ConfigurationParameters const& configParameters,
0166                     uint32_t sizeEB,
0167                     uint32_t sizeEE,
0168                     cudaStream_t cudaStream) {
0169         constexpr auto svlength = getLength<SampleVector>();
0170         constexpr auto sgvlength = getLength<SampleGainVector>();
0171         constexpr auto smlength = getLength<SampleMatrix>();
0172         constexpr auto pmlength = getLength<PulseMatrixType>();
0173         constexpr auto bxvlength = getLength<BXVectorType>();
0174         auto const size = sizeEB + sizeEE;
0175 
0176         auto alloc = [cudaStream](auto& var, uint32_t size) {
0177           using element_type = typename std::remove_reference_t<decltype(var)>::element_type;
0178           var = cms::cuda::make_device_unique<element_type[]>(size, cudaStream);
0179         };
0180 
0181         alloc(samples, size * svlength);
0182         alloc(gainsNoise, size * sgvlength);
0183 
0184         alloc(noisecov, size * smlength);
0185         alloc(pulse_matrix, size * pmlength);
0186         alloc(activeBXs, size * bxvlength);
0187         alloc(acState, size);
0188 
0189         alloc(hasSwitchToGain6, size);
0190         alloc(hasSwitchToGain1, size);
0191         alloc(isSaturated, size);
0192 
0193         if (configParameters.shouldRunTimingComputation) {
0194           alloc(sample_values, size * svlength);
0195           alloc(sample_value_errors, size * svlength);
0196           alloc(useless_sample_values, size * EcalDataFrame::MAXSAMPLES);
0197           alloc(chi2sNullHypot, size);
0198           alloc(sum0sNullHypot, size);
0199           alloc(sumAAsNullHypot, size);
0200           alloc(pedestal_nums, size);
0201 
0202           alloc(tMaxAlphaBetas, size);
0203           alloc(tMaxErrorAlphaBetas, size);
0204           alloc(accTimeMax, size);
0205           alloc(accTimeWgt, size);
0206           alloc(ampMaxAlphaBeta, size);
0207           alloc(ampMaxError, size);
0208           alloc(timeMax, size);
0209           alloc(timeError, size);
0210           alloc(tcState, size);
0211         }
0212       }
0213     };
0214 
0215     // const refs products to conditions
0216     struct ConditionsProducts {
0217       EcalPedestalsGPU::Product const& pedestals;
0218       EcalGainRatiosGPU::Product const& gainRatios;
0219       EcalPulseShapesGPU::Product const& pulseShapes;
0220       EcalPulseCovariancesGPU::Product const& pulseCovariances;
0221       EcalSamplesCorrelationGPU::Product const& samplesCorrelation;
0222       EcalTimeBiasCorrectionsGPU::Product const& timeBiasCorrections;
0223       EcalTimeCalibConstantsGPU::Product const& timeCalibConstants;
0224       EcalSampleMask const& sampleMask;
0225       EcalTimeOffsetConstant const& timeOffsetConstant;
0226       uint32_t offsetForHashes;
0227       EcalMultifitParametersGPU::Product const& multifitParameters;
0228     };
0229 
0230     struct xyz {
0231       int x, y, z;
0232     };
0233 
0234     struct conf_data {
0235       xyz threads;
0236       bool runV1;
0237       cudaStream_t cuStream;
0238     };
0239 
0240   }  // namespace multifit
0241 }  // namespace ecal
0242 
0243 //
0244 // ECAL Rechit producer
0245 //
0246 
0247 namespace ecal {
0248   namespace rechit {
0249 
0250     // parameters that are read in the configuration file for rechit producer
0251     struct ConfigurationParameters {
0252       // device ptrs
0253       const int* ChannelStatusToBeExcluded = nullptr;
0254       uint32_t ChannelStatusToBeExcludedSize;
0255 
0256       bool killDeadChannels;
0257 
0258       bool recoverEBIsolatedChannels;
0259       bool recoverEEIsolatedChannels;
0260       bool recoverEBVFE;
0261       bool recoverEEVFE;
0262       bool recoverEBFE;
0263       bool recoverEEFE;
0264 
0265       float EBLaserMIN;
0266       float EELaserMIN;
0267       float EBLaserMAX;
0268       float EELaserMAX;
0269 
0270       const int* expanded_v_DB_reco_flags;
0271       const uint32_t* expanded_Sizes_v_DB_reco_flags;
0272       const uint32_t* expanded_flagbit_v_DB_reco_flags;
0273       uint32_t expanded_v_DB_reco_flagsSize;
0274 
0275       uint32_t flagmask;
0276     };
0277 
0278     struct EventOutputDataGPU {
0279       RecHit<::calo::common::DevStoragePolicy> recHitsEB, recHitsEE;
0280 
0281       void allocate(ConfigurationParameters const& configParameters,
0282                     uint32_t sizeEB,
0283                     uint32_t sizeEE,
0284                     cudaStream_t cudaStream) {
0285         //---- configParameters -> needed only to decide if to save the timing information or not
0286         recHitsEB.energy = cms::cuda::make_device_unique<::ecal::reco::StorageScalarType[]>(sizeEB, cudaStream);
0287         recHitsEB.time = cms::cuda::make_device_unique<::ecal::reco::StorageScalarType[]>(sizeEB, cudaStream);
0288         recHitsEB.chi2 = cms::cuda::make_device_unique<::ecal::reco::StorageScalarType[]>(sizeEB, cudaStream);
0289         recHitsEB.flagBits = cms::cuda::make_device_unique<uint32_t[]>(sizeEB, cudaStream);
0290         recHitsEB.extra = cms::cuda::make_device_unique<uint32_t[]>(sizeEB, cudaStream);
0291         recHitsEB.did = cms::cuda::make_device_unique<uint32_t[]>(sizeEB, cudaStream);
0292 
0293         recHitsEE.energy = cms::cuda::make_device_unique<::ecal::reco::StorageScalarType[]>(sizeEE, cudaStream);
0294         recHitsEE.time = cms::cuda::make_device_unique<::ecal::reco::StorageScalarType[]>(sizeEE, cudaStream);
0295         recHitsEE.chi2 = cms::cuda::make_device_unique<::ecal::reco::StorageScalarType[]>(sizeEE, cudaStream);
0296         recHitsEE.flagBits = cms::cuda::make_device_unique<uint32_t[]>(sizeEE, cudaStream);
0297         recHitsEE.extra = cms::cuda::make_device_unique<uint32_t[]>(sizeEE, cudaStream);
0298         recHitsEE.did = cms::cuda::make_device_unique<uint32_t[]>(sizeEE, cudaStream);
0299       }
0300     };
0301 
0302     struct EventInputDataGPU {
0303       ecal::UncalibratedRecHit<calo::common::DevStoragePolicy> const& ebUncalibRecHits;
0304       ecal::UncalibratedRecHit<calo::common::DevStoragePolicy> const& eeUncalibRecHits;
0305     };
0306 
0307     // const refs products to conditions
0308     struct ConditionsProducts {
0309       EcalRechitADCToGeVConstantGPU::Product const& ADCToGeV;
0310       EcalIntercalibConstantsGPU::Product const& Intercalib;
0311       EcalRechitChannelStatusGPU::Product const& ChannelStatus;
0312 
0313       EcalLaserAPDPNRatiosGPU::Product const& LaserAPDPNRatios;
0314       EcalLaserAPDPNRatiosRefGPU::Product const& LaserAPDPNRatiosRef;
0315       EcalLaserAlphasGPU::Product const& LaserAlphas;
0316       EcalLinearCorrectionsGPU::Product const& LinearCorrections;
0317 
0318       uint32_t offsetForHashes;
0319     };
0320 
0321   }  // namespace rechit
0322 }  // namespace ecal
0323 
0324 #endif  // RecoLocalCalo_EcalRecProducers_plugins_DeclsForKernels_h