Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "CondFormats/HcalObjects/interface/HcalPedestals.h"
0002 #include "CondFormats/HcalObjects/interface/HcalPedestalsGPU.h"
0003 #include "FWCore/Utilities/interface/typelookup.h"
0004 #include "HeterogeneousCore/CUDAUtilities/interface/copyAsync.h"
0005 
0006 // FIXME: add proper getters to conditions
0007 HcalPedestalsGPU::HcalPedestalsGPU(HcalPedestals const& pedestals)
0008     : unitIsADC_{pedestals.isADC()},
0009       totalChannels_{pedestals.getAllContainers()[0].second.size() + pedestals.getAllContainers()[1].second.size()},
0010       offsetForHashes_{static_cast<uint32_t>(pedestals.getAllContainers()[0].second.size())},
0011       values_(totalChannels_ * 4),
0012       widths_(totalChannels_ * 4) {
0013 #ifdef HCAL_MAHI_CPUDEBUG
0014   std::cout << "unitIsADC = " << unitIsADC_ << std::endl;
0015 #endif
0016 
0017   auto const containers = pedestals.getAllContainers();
0018 
0019   // fill in eb
0020   auto const& barrelValues = containers[0].second;
0021   for (uint64_t i = 0; i < barrelValues.size(); ++i) {
0022     values_[i * 4] = barrelValues[i].getValue(0);
0023     values_[i * 4 + 1] = barrelValues[i].getValue(1);
0024     values_[i * 4 + 2] = barrelValues[i].getValue(2);
0025     values_[i * 4 + 3] = barrelValues[i].getValue(3);
0026 
0027     widths_[i * 4] = barrelValues[i].getWidth(0);
0028     widths_[i * 4 + 1] = barrelValues[i].getWidth(1);
0029     widths_[i * 4 + 2] = barrelValues[i].getWidth(2);
0030     widths_[i * 4 + 3] = barrelValues[i].getWidth(3);
0031   }
0032 
0033   // fill in ee
0034   auto const& endcapValues = containers[1].second;
0035   auto const offset = barrelValues.size();
0036   for (uint64_t i = 0; i < endcapValues.size(); ++i) {
0037     auto const off = offset + i;
0038     values_[off * 4] = endcapValues[i].getValue(0);
0039     values_[off * 4 + 1] = endcapValues[i].getValue(1);
0040     values_[off * 4 + 2] = endcapValues[i].getValue(2);
0041     values_[off * 4 + 3] = endcapValues[i].getValue(3);
0042 
0043     widths_[off * 4] = endcapValues[i].getWidth(0);
0044     widths_[off * 4 + 1] = endcapValues[i].getWidth(1);
0045     widths_[off * 4 + 2] = endcapValues[i].getWidth(2);
0046     widths_[off * 4 + 3] = endcapValues[i].getWidth(3);
0047   }
0048 }
0049 
0050 HcalPedestalsGPU::Product const& HcalPedestalsGPU::getProduct(cudaStream_t stream) const {
0051   auto const& product =
0052       product_.dataForCurrentDeviceAsync(stream, [this](HcalPedestalsGPU::Product& product, cudaStream_t stream) {
0053         // allocate
0054         product.values = cms::cuda::make_device_unique<float[]>(values_.size(), stream);
0055         product.widths = cms::cuda::make_device_unique<float[]>(widths_.size(), stream);
0056 
0057         // transfer
0058         cms::cuda::copyAsync(product.values, values_, stream);
0059         cms::cuda::copyAsync(product.widths, widths_, stream);
0060       });
0061 
0062   return product;
0063 }
0064 
0065 TYPELOOKUP_DATA_REG(HcalPedestalsGPU);