Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "CondFormats/HcalObjects/interface/HcalSiPMParameters.h"
0002 #include "CondFormats/HcalObjects/interface/HcalSiPMParametersGPU.h"
0003 #include "FWCore/Utilities/interface/typelookup.h"
0004 #include "HeterogeneousCore/CUDAUtilities/interface/copyAsync.h"
0005 
0006 HcalSiPMParametersGPU::HcalSiPMParametersGPU(HcalSiPMParameters const& parameters)
0007     : totalChannels_{parameters.getAllContainers()[0].second.size() + parameters.getAllContainers()[1].second.size()},
0008       type_(totalChannels_),
0009       auxi1_(totalChannels_),
0010       fcByPE_(totalChannels_),
0011       darkCurrent_(totalChannels_),
0012       auxi2_(totalChannels_) {
0013   auto const containers = parameters.getAllContainers();
0014 
0015   // fill in eb
0016   auto const& barrelValues = containers[0].second;
0017   for (uint64_t i = 0; i < barrelValues.size(); ++i) {
0018     auto const& item = barrelValues[i];
0019     type_[i] = item.getType();
0020     auxi1_[i] = item.getauxi1();
0021     fcByPE_[i] = item.getFCByPE();
0022     darkCurrent_[i] = item.getDarkCurrent();
0023     auxi2_[i] = item.getauxi2();
0024   }
0025 
0026   // fill in ee
0027   auto const& endcapValues = containers[1].second;
0028   auto const offset = barrelValues.size();
0029   for (uint64_t i = 0; i < endcapValues.size(); ++i) {
0030     auto const off = offset + i;
0031     auto const& item = endcapValues[i];
0032     type_[off] = item.getType();
0033     auxi1_[off] = item.getauxi1();
0034     fcByPE_[off] = item.getFCByPE();
0035     darkCurrent_[off] = item.getDarkCurrent();
0036     auxi2_[off] = item.getauxi2();
0037   }
0038 }
0039 
0040 HcalSiPMParametersGPU::Product const& HcalSiPMParametersGPU::getProduct(cudaStream_t stream) const {
0041   auto const& product =
0042       product_.dataForCurrentDeviceAsync(stream, [this](HcalSiPMParametersGPU::Product& product, cudaStream_t stream) {
0043         // allocate
0044         product.type = cms::cuda::make_device_unique<int[]>(type_.size(), stream);
0045         product.auxi1 = cms::cuda::make_device_unique<int[]>(auxi1_.size(), stream);
0046         product.fcByPE = cms::cuda::make_device_unique<float[]>(fcByPE_.size(), stream);
0047         product.darkCurrent = cms::cuda::make_device_unique<float[]>(darkCurrent_.size(), stream);
0048         product.auxi2 = cms::cuda::make_device_unique<float[]>(auxi2_.size(), stream);
0049 
0050         // transfer
0051         cms::cuda::copyAsync(product.type, type_, stream);
0052         cms::cuda::copyAsync(product.auxi1, auxi1_, stream);
0053         cms::cuda::copyAsync(product.fcByPE, fcByPE_, stream);
0054         cms::cuda::copyAsync(product.darkCurrent, darkCurrent_, stream);
0055         cms::cuda::copyAsync(product.auxi2, auxi2_, stream);
0056       });
0057 
0058   return product;
0059 }
0060 
0061 TYPELOOKUP_DATA_REG(HcalSiPMParametersGPU);