File indexing completed on 2024-04-06 12:25:54
0001 #include <iostream>
0002 #include <memory>
0003 #include <chrono>
0004 #include <cuda_runtime.h>
0005
0006 #include "FWCore/Framework/interface/ESProducer.h"
0007 #include "FWCore/Framework/interface/stream/EDProducer.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
0011 #include "DataFormats/HGCRecHit/interface/HGCRecHit.h"
0012 #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0013 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0014 #include "FWCore/Utilities/interface/EDGetToken.h"
0015 #include "FWCore/Utilities/interface/EDPutToken.h"
0016 #include "FWCore/Utilities/interface/InputTag.h"
0017
0018 #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
0019 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0020 #include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
0021 #include "Geometry/HGCalCommonData/interface/HGCalWaferIndex.h"
0022
0023 #include "HeterogeneousCore/CUDACore/interface/ScopedContext.h"
0024 #include "HeterogeneousCore/CUDACore/interface/ContextState.h"
0025 #include "HeterogeneousCore/CUDAServices/interface/CUDAInterface.h"
0026 #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
0027
0028 #include "FWCore/ServiceRegistry/interface/Service.h"
0029 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0030 #include "RecoLocalCalo/HGCalRecProducers/plugins/KernelManagerHGCalRecHit.h"
0031
0032 #include "CUDADataFormats/HGCal/interface/HGCRecHitGPUProduct.h"
0033 #include "CUDADataFormats/HGCal/interface/HGCRecHitCPUProduct.h"
0034
0035 class HEFRecHitGPUtoSoA : public edm::stream::EDProducer<edm::ExternalWork> {
0036 public:
0037 explicit HEFRecHitGPUtoSoA(const edm::ParameterSet& ps);
0038 ~HEFRecHitGPUtoSoA() override;
0039
0040 void acquire(edm::Event const&, edm::EventSetup const&, edm::WaitingTaskWithArenaHolder) override;
0041 void produce(edm::Event&, const edm::EventSetup&) override;
0042
0043 private:
0044 cms::cuda::ContextState ctxState_;
0045 edm::EDGetTokenT<cms::cuda::Product<HGCRecHitGPUProduct>> recHitGPUToken_;
0046 edm::EDPutTokenT<HGCRecHitCPUProduct> recHitCPUSoAToken_;
0047
0048 std::unique_ptr<HGCRecHitCPUProduct> prodPtr_;
0049 };
0050
0051 HEFRecHitGPUtoSoA::HEFRecHitGPUtoSoA(const edm::ParameterSet& ps)
0052 : recHitGPUToken_{consumes<cms::cuda::Product<HGCRecHitGPUProduct>>(
0053 ps.getParameter<edm::InputTag>("HEFRecHitGPUTok"))},
0054 recHitCPUSoAToken_(produces<HGCRecHitCPUProduct>()) {}
0055
0056 HEFRecHitGPUtoSoA::~HEFRecHitGPUtoSoA() {}
0057
0058 void HEFRecHitGPUtoSoA::acquire(edm::Event const& event,
0059 edm::EventSetup const& setup,
0060 edm::WaitingTaskWithArenaHolder w) {
0061 cms::cuda::ScopedContextAcquire ctx{event.streamID(), std::move(w)};
0062 const auto& gpuRecHits = ctx.get(event, recHitGPUToken_);
0063
0064 prodPtr_ = std::make_unique<HGCRecHitCPUProduct>(gpuRecHits.nHits(), ctx.stream());
0065
0066 KernelManagerHGCalRecHit km((*prodPtr_).get(), gpuRecHits.get());
0067 km.transfer_soa_to_host(ctx.stream());
0068 }
0069
0070 void HEFRecHitGPUtoSoA::produce(edm::Event& event, const edm::EventSetup& setup) { event.put(std::move(prodPtr_)); }
0071
0072 #include "FWCore/Framework/interface/MakerMacros.h"
0073 DEFINE_FWK_MODULE(HEFRecHitGPUtoSoA);