Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:11

0001 #include "CondFormats/HcalObjects/interface/HcalGainWidths.h"
0002 #include "CondFormats/HcalObjects/interface/HcalGainWidthsGPU.h"
0003 #include "FWCore/Utilities/interface/typelookup.h"
0004 #include "HeterogeneousCore/CUDAUtilities/interface/copyAsync.h"
0005 
0006 // FIXME: add proper getters to conditions
0007 HcalGainWidthsGPU::HcalGainWidthsGPU(HcalGainWidths const& gains)
0008     : totalChannels_{gains.getAllContainers()[0].second.size() + gains.getAllContainers()[1].second.size()},
0009       value0_(totalChannels_),
0010       value1_(totalChannels_),
0011       value2_(totalChannels_),
0012       value3_(totalChannels_) {
0013   auto const gainContainers = gains.getAllContainers();
0014 
0015   // fill in eb
0016   auto const& barrelValues = gainContainers[0].second;
0017   for (uint64_t i = 0; i < barrelValues.size(); ++i) {
0018     value0_[i] = barrelValues[i].getValue(0);
0019     value1_[i] = barrelValues[i].getValue(1);
0020     value2_[i] = barrelValues[i].getValue(2);
0021     value3_[i] = barrelValues[i].getValue(3);
0022   }
0023 
0024   // fill in ee
0025   auto const& endcapValues = gainContainers[1].second;
0026   auto const offset = barrelValues.size();
0027   for (uint64_t i = 0; i < endcapValues.size(); ++i) {
0028     value0_[i + offset] = endcapValues[i].getValue(0);
0029     value1_[i + offset] = endcapValues[i].getValue(1);
0030     value2_[i + offset] = endcapValues[i].getValue(2);
0031     value3_[i + offset] = endcapValues[i].getValue(3);
0032   }
0033 }
0034 
0035 HcalGainWidthsGPU::Product const& HcalGainWidthsGPU::getProduct(cudaStream_t stream) const {
0036   auto const& product =
0037       product_.dataForCurrentDeviceAsync(stream, [this](HcalGainWidthsGPU::Product& product, cudaStream_t stream) {
0038         // allocate
0039         product.value0 = cms::cuda::make_device_unique<float[]>(value0_.size(), stream);
0040         product.value1 = cms::cuda::make_device_unique<float[]>(value1_.size(), stream);
0041         product.value2 = cms::cuda::make_device_unique<float[]>(value2_.size(), stream);
0042         product.value3 = cms::cuda::make_device_unique<float[]>(value3_.size(), stream);
0043 
0044         // transfer
0045         cms::cuda::copyAsync(product.value0, value0_, stream);
0046         cms::cuda::copyAsync(product.value1, value1_, stream);
0047         cms::cuda::copyAsync(product.value2, value2_, stream);
0048         cms::cuda::copyAsync(product.value3, value3_, stream);
0049       });
0050 
0051   return product;
0052 }
0053 
0054 TYPELOOKUP_DATA_REG(HcalGainWidthsGPU);