Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef RecoLocalCalo_EcalRecProducers_plugins_alpaka_DeclsForKernels_h
0002 #define RecoLocalCalo_EcalRecProducers_plugins_alpaka_DeclsForKernels_h
0003 
0004 #include <vector>
0005 
0006 #include "CondFormats/EcalObjects/interface/EcalTimeOffsetConstant.h"
0007 #include "DataFormats/EcalDigi/interface/EcalDataFrame.h"
0008 #include "RecoLocalCalo/EcalRecProducers/interface/EigenMatrixTypes_gpu.h"
0009 
0010 class EcalSampleMask;
0011 
0012 namespace ALPAKA_ACCELERATOR_NAMESPACE::ecal::multifit {
0013 
0014   enum class TimeComputationState : char { NotFinished = 0, Finished = 1 };
0015   enum class MinimizationState : char {
0016     NotFinished = 0,
0017     Finished = 1,
0018     Precomputed = 2,
0019   };
0020 
0021   // parameters have a fixed type
0022   // Can we go by with single precision
0023   struct ConfigurationParameters {
0024     using type = double;
0025 
0026     type timeFitLimitsFirstEB, timeFitLimitsFirstEE;
0027     type timeFitLimitsSecondEB, timeFitLimitsSecondEE;
0028 
0029     type timeConstantTermEB, timeConstantTermEE;
0030 
0031     type timeNconstEB, timeNconstEE;
0032 
0033     type amplitudeThreshEE, amplitudeThreshEB;
0034 
0035     type outOfTimeThreshG12pEB, outOfTimeThreshG12mEB;
0036     type outOfTimeThreshG12pEE, outOfTimeThreshG12mEE;
0037     type outOfTimeThreshG61pEE, outOfTimeThreshG61mEE;
0038     type outOfTimeThreshG61pEB, outOfTimeThreshG61mEB;
0039 
0040     std::array<uint32_t, 3> kernelMinimizeThreads;
0041 
0042     bool shouldRunTimingComputation;
0043   };
0044 
0045   template <typename EigenM>
0046   constexpr uint32_t getLength() {
0047     return EigenM::RowsAtCompileTime * EigenM::ColsAtCompileTime;
0048   }
0049 
0050   struct EventDataForScratchDevice {
0051     using SVT = ::ecal::multifit::SampleVector::Scalar;
0052     using SGVT = ::ecal::multifit::SampleGainVector::Scalar;
0053     using SMT = ::ecal::multifit::SampleMatrix::Scalar;
0054     using PMT = ::ecal::multifit::PulseMatrixType::Scalar;
0055     using BXVT = ::ecal::multifit::BXVectorType::Scalar;
0056 
0057     static constexpr auto svlength = getLength<::ecal::multifit::SampleVector>();
0058     static constexpr auto sgvlength = getLength<::ecal::multifit::SampleGainVector>();
0059     static constexpr auto smlength = getLength<::ecal::multifit::SampleMatrix>();
0060     static constexpr auto pmlength = getLength<::ecal::multifit::PulseMatrixType>();
0061     static constexpr auto bxvlength = getLength<::ecal::multifit::BXVectorType>();
0062 
0063     // delete the default constructor because alpaka buffers do not have a default constructor
0064     EventDataForScratchDevice() = delete;
0065 
0066     explicit EventDataForScratchDevice(ConfigurationParameters const& configParameters, uint32_t size, Queue& queue)
0067         : samplesDevBuf{cms::alpakatools::make_device_buffer<SVT[]>(queue, size * svlength)},
0068           gainsNoiseDevBuf{cms::alpakatools::make_device_buffer<SGVT[]>(queue, size * sgvlength)},
0069           noisecovDevBuf{cms::alpakatools::make_device_buffer<SMT[]>(queue, size * smlength)},
0070           pulse_matrixDevBuf{cms::alpakatools::make_device_buffer<PMT[]>(queue, size * pmlength)},
0071           activeBXsDevBuf{cms::alpakatools::make_device_buffer<BXVT[]>(queue, size * bxvlength)},
0072           acStateDevBuf{cms::alpakatools::make_device_buffer<char[]>(queue, size)},
0073           hasSwitchToGain6DevBuf{cms::alpakatools::make_device_buffer<bool[]>(queue, size)},
0074           hasSwitchToGain1DevBuf{cms::alpakatools::make_device_buffer<bool[]>(queue, size)},
0075           isSaturatedDevBuf{cms::alpakatools::make_device_buffer<bool[]>(queue, size)} {
0076       if (configParameters.shouldRunTimingComputation) {
0077         sample_valuesDevBuf = cms::alpakatools::make_device_buffer<SVT[]>(queue, size * svlength);
0078         sample_value_errorsDevBuf = cms::alpakatools::make_device_buffer<SVT[]>(queue, size * svlength);
0079         useless_sample_valuesDevBuf =
0080             cms::alpakatools::make_device_buffer<bool[]>(queue, size * EcalDataFrame::MAXSAMPLES);
0081         chi2sNullHypotDevBuf = cms::alpakatools::make_device_buffer<SVT[]>(queue, size);
0082         sum0sNullHypotDevBuf = cms::alpakatools::make_device_buffer<SVT[]>(queue, size);
0083         sumAAsNullHypotDevBuf = cms::alpakatools::make_device_buffer<SVT[]>(queue, size);
0084         pedestal_numsDevBuf = cms::alpakatools::make_device_buffer<char[]>(queue, size);
0085 
0086         tMaxAlphaBetasDevBuf = cms::alpakatools::make_device_buffer<SVT[]>(queue, size);
0087         tMaxErrorAlphaBetasDevBuf = cms::alpakatools::make_device_buffer<SVT[]>(queue, size);
0088         accTimeMaxDevBuf = cms::alpakatools::make_device_buffer<SVT[]>(queue, size);
0089         accTimeWgtDevBuf = cms::alpakatools::make_device_buffer<SVT[]>(queue, size);
0090         ampMaxAlphaBetaDevBuf = cms::alpakatools::make_device_buffer<SVT[]>(queue, size);
0091         ampMaxErrorDevBuf = cms::alpakatools::make_device_buffer<SVT[]>(queue, size);
0092         timeMaxDevBuf = cms::alpakatools::make_device_buffer<SVT[]>(queue, size);
0093         timeErrorDevBuf = cms::alpakatools::make_device_buffer<SVT[]>(queue, size);
0094         tcStateDevBuf = cms::alpakatools::make_device_buffer<TimeComputationState[]>(queue, size);
0095       }
0096     };
0097 
0098     cms::alpakatools::device_buffer<Device, SVT[]> samplesDevBuf;
0099     cms::alpakatools::device_buffer<Device, SGVT[]> gainsNoiseDevBuf;
0100 
0101     cms::alpakatools::device_buffer<Device, SMT[]> noisecovDevBuf;
0102     cms::alpakatools::device_buffer<Device, PMT[]> pulse_matrixDevBuf;
0103     cms::alpakatools::device_buffer<Device, BXVT[]> activeBXsDevBuf;
0104     cms::alpakatools::device_buffer<Device, char[]> acStateDevBuf;
0105 
0106     cms::alpakatools::device_buffer<Device, bool[]> hasSwitchToGain6DevBuf;
0107     cms::alpakatools::device_buffer<Device, bool[]> hasSwitchToGain1DevBuf;
0108     cms::alpakatools::device_buffer<Device, bool[]> isSaturatedDevBuf;
0109 
0110     std::optional<cms::alpakatools::device_buffer<Device, SVT[]>> sample_valuesDevBuf;
0111     std::optional<cms::alpakatools::device_buffer<Device, SVT[]>> sample_value_errorsDevBuf;
0112     std::optional<cms::alpakatools::device_buffer<Device, bool[]>> useless_sample_valuesDevBuf;
0113     std::optional<cms::alpakatools::device_buffer<Device, SVT[]>> chi2sNullHypotDevBuf;
0114     std::optional<cms::alpakatools::device_buffer<Device, SVT[]>> sum0sNullHypotDevBuf;
0115     std::optional<cms::alpakatools::device_buffer<Device, SVT[]>> sumAAsNullHypotDevBuf;
0116     std::optional<cms::alpakatools::device_buffer<Device, char[]>> pedestal_numsDevBuf;
0117     std::optional<cms::alpakatools::device_buffer<Device, SVT[]>> tMaxAlphaBetasDevBuf;
0118     std::optional<cms::alpakatools::device_buffer<Device, SVT[]>> tMaxErrorAlphaBetasDevBuf;
0119     std::optional<cms::alpakatools::device_buffer<Device, SVT[]>> accTimeMaxDevBuf;
0120     std::optional<cms::alpakatools::device_buffer<Device, SVT[]>> accTimeWgtDevBuf;
0121     std::optional<cms::alpakatools::device_buffer<Device, SVT[]>> ampMaxAlphaBetaDevBuf;
0122     std::optional<cms::alpakatools::device_buffer<Device, SVT[]>> ampMaxErrorDevBuf;
0123     std::optional<cms::alpakatools::device_buffer<Device, SVT[]>> timeMaxDevBuf;
0124     std::optional<cms::alpakatools::device_buffer<Device, SVT[]>> timeErrorDevBuf;
0125     std::optional<cms::alpakatools::device_buffer<Device, TimeComputationState[]>> tcStateDevBuf;
0126   };
0127 
0128 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE::ecal::multifit
0129 
0130 #endif  // RecoLocalCalo_EcalRecProducers_plugins_alpaka_DeclsForKernels_h