Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:59:58

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