Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:10

0001 #include "CondFormats/EcalObjects/interface/EcalLaserAPDPNRatiosGPU.h"
0002 
0003 #include "FWCore/Utilities/interface/typelookup.h"
0004 #include "HeterogeneousCore/CUDAUtilities/interface/copyAsync.h"
0005 
0006 EcalLaserAPDPNRatiosGPU::EcalLaserAPDPNRatiosGPU(EcalLaserAPDPNRatios const& values)
0007     : p1_(values.getLaserMap().size()),
0008       p2_(values.getLaserMap().size()),
0009       p3_(values.getLaserMap().size()),
0010       t1_(values.getTimeMap().size()),
0011       t2_(values.getTimeMap().size()),
0012       t3_(values.getTimeMap().size()) {
0013   // fill in eb
0014   //     auto const& barrelValues = values.barrelItems();
0015   for (unsigned int i = 0; i < values.getLaserMap().barrelItems().size(); i++) {
0016     p1_[i] = values.getLaserMap().barrelItems()[i].p1;
0017     p2_[i] = values.getLaserMap().barrelItems()[i].p2;
0018     p3_[i] = values.getLaserMap().barrelItems()[i].p3;
0019   }
0020 
0021   // fill in ee
0022   //     auto const& endcapValues = values.endcapItems();
0023   auto const offset_laser = values.getLaserMap().barrelItems().size();
0024   for (unsigned int i = 0; i < values.getLaserMap().endcapItems().size(); i++) {
0025     p1_[offset_laser + i] = values.getLaserMap().endcapItems()[i].p1;
0026     p2_[offset_laser + i] = values.getLaserMap().endcapItems()[i].p2;
0027     p3_[offset_laser + i] = values.getLaserMap().endcapItems()[i].p3;
0028   }
0029 
0030   //   Time is a simple std::vector
0031   //       typedef std::vector<EcalLaserTimeStamp> EcalLaserTimeStampMap;
0032   for (unsigned int i = 0; i < values.getTimeMap().size(); i++) {
0033     t1_[i] = values.getTimeMap()[i].t1.value();
0034     t2_[i] = values.getTimeMap()[i].t2.value();
0035     t3_[i] = values.getTimeMap()[i].t3.value();
0036   }
0037 }
0038 
0039 EcalLaserAPDPNRatiosGPU::Product const& EcalLaserAPDPNRatiosGPU::getProduct(cudaStream_t cudaStream) const {
0040   auto const& product = product_.dataForCurrentDeviceAsync(
0041       cudaStream, [this](EcalLaserAPDPNRatiosGPU::Product& product, cudaStream_t cudaStream) {
0042         // allocate
0043         product.p1 = cms::cuda::make_device_unique<float[]>(p1_.size(), cudaStream);
0044         product.p2 = cms::cuda::make_device_unique<float[]>(p2_.size(), cudaStream);
0045         product.p3 = cms::cuda::make_device_unique<float[]>(p3_.size(), cudaStream);
0046         product.t1 = cms::cuda::make_device_unique<edm::TimeValue_t[]>(t1_.size(), cudaStream);
0047         product.t2 = cms::cuda::make_device_unique<edm::TimeValue_t[]>(t2_.size(), cudaStream);
0048         product.t3 = cms::cuda::make_device_unique<edm::TimeValue_t[]>(t3_.size(), cudaStream);
0049         // transfer
0050         cms::cuda::copyAsync(product.p1, p1_, cudaStream);
0051         cms::cuda::copyAsync(product.p2, p2_, cudaStream);
0052         cms::cuda::copyAsync(product.p3, p3_, cudaStream);
0053         cms::cuda::copyAsync(product.t1, t1_, cudaStream);
0054         cms::cuda::copyAsync(product.t2, t2_, cudaStream);
0055         cms::cuda::copyAsync(product.t3, t3_, cudaStream);
0056       });
0057 
0058   return product;
0059 }
0060 
0061 TYPELOOKUP_DATA_REG(EcalLaserAPDPNRatiosGPU);