File indexing completed on 2024-04-06 12:10:59
0001 #include "CUDADataFormats/Common/interface/Product.h"
0002 #include "CUDADataFormats/SiPixelDigi/interface/SiPixelDigiErrorsCUDA.h"
0003 #include "DataFormats/SiPixelRawData/interface/SiPixelErrorsSoA.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/Framework/interface/stream/EDProducer.h"
0008 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "HeterogeneousCore/CUDACore/interface/ScopedContext.h"
0012 #include "HeterogeneousCore/CUDAUtilities/interface/host_unique_ptr.h"
0013
0014 class SiPixelDigiErrorsSoAFromCUDA : public edm::stream::EDProducer<edm::ExternalWork> {
0015 public:
0016 explicit SiPixelDigiErrorsSoAFromCUDA(const edm::ParameterSet& iConfig);
0017 ~SiPixelDigiErrorsSoAFromCUDA() override = default;
0018
0019 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0020
0021 private:
0022 void acquire(const edm::Event& iEvent,
0023 const edm::EventSetup& iSetup,
0024 edm::WaitingTaskWithArenaHolder waitingTaskHolder) override;
0025 void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0026
0027 edm::EDGetTokenT<cms::cuda::Product<SiPixelDigiErrorsCUDA>> digiErrorGetToken_;
0028 edm::EDPutTokenT<SiPixelErrorsSoA> digiErrorPutToken_;
0029
0030 cms::cuda::host::unique_ptr<SiPixelErrorCompact[]> data_;
0031 cms::cuda::SimpleVector<SiPixelErrorCompact> error_ = cms::cuda::make_SimpleVector<SiPixelErrorCompact>(0, nullptr);
0032 const SiPixelFormatterErrors* formatterErrors_ = nullptr;
0033 };
0034
0035 SiPixelDigiErrorsSoAFromCUDA::SiPixelDigiErrorsSoAFromCUDA(const edm::ParameterSet& iConfig)
0036 : digiErrorGetToken_(
0037 consumes<cms::cuda::Product<SiPixelDigiErrorsCUDA>>(iConfig.getParameter<edm::InputTag>("src"))),
0038 digiErrorPutToken_(produces<SiPixelErrorsSoA>()) {}
0039
0040 void SiPixelDigiErrorsSoAFromCUDA::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0041 edm::ParameterSetDescription desc;
0042 desc.add<edm::InputTag>("src", edm::InputTag("siPixelClustersCUDA"));
0043 descriptions.addWithDefaultLabel(desc);
0044 }
0045
0046 void SiPixelDigiErrorsSoAFromCUDA::acquire(const edm::Event& iEvent,
0047 const edm::EventSetup& iSetup,
0048 edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
0049
0050 cms::cuda::ScopedContextAcquire ctx{iEvent.streamID(), std::move(waitingTaskHolder)};
0051 const auto& gpuDigiErrors = ctx.get(iEvent, digiErrorGetToken_);
0052 formatterErrors_ = &(gpuDigiErrors.formatterErrors());
0053
0054 if (gpuDigiErrors.nErrorWords() == 0)
0055 return;
0056
0057 auto tmp = gpuDigiErrors.dataErrorToHostAsync(ctx.stream());
0058 error_ = tmp.first;
0059 data_ = std::move(tmp.second);
0060 }
0061
0062 void SiPixelDigiErrorsSoAFromCUDA::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 iEvent.emplace(digiErrorPutToken_, error_.size(), error_.data(), formatterErrors_);
0074 error_ = cms::cuda::make_SimpleVector<SiPixelErrorCompact>(0, nullptr);
0075 data_.reset();
0076 formatterErrors_ = nullptr;
0077 }
0078
0079
0080 DEFINE_FWK_MODULE(SiPixelDigiErrorsSoAFromCUDA);