Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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