File indexing completed on 2023-03-17 10:46:53
0001 #include "CondFormats/EcalObjects/interface/EcalLinearCorrectionsGPU.h"
0002
0003 #include "FWCore/Utilities/interface/typelookup.h"
0004 #include "HeterogeneousCore/CUDAUtilities/interface/copyAsync.h"
0005
0006 EcalLinearCorrectionsGPU::EcalLinearCorrectionsGPU(EcalLinearCorrections const& values)
0007 : p1_(values.getValueMap().size()),
0008 p2_(values.getValueMap().size()),
0009 p3_(values.getValueMap().size()),
0010 t1_(values.getTimeMap().size()),
0011 t2_(values.getTimeMap().size()),
0012 t3_(values.getTimeMap().size()) {
0013
0014 for (unsigned int i = 0; i < values.getValueMap().barrelItems().size(); i++) {
0015 p1_[i] = values.getValueMap().barrelItems()[i].p1;
0016 p2_[i] = values.getValueMap().barrelItems()[i].p2;
0017 p3_[i] = values.getValueMap().barrelItems()[i].p3;
0018 }
0019
0020
0021 auto const offset_laser = values.getValueMap().barrelItems().size();
0022 for (unsigned int i = 0; i < values.getValueMap().endcapItems().size(); i++) {
0023 p1_[offset_laser + i] = values.getValueMap().endcapItems()[i].p1;
0024 p2_[offset_laser + i] = values.getValueMap().endcapItems()[i].p2;
0025 p3_[offset_laser + i] = values.getValueMap().endcapItems()[i].p3;
0026 }
0027
0028
0029
0030 for (unsigned int i = 0; i < values.getTimeMap().size(); i++) {
0031 t1_[i] = values.getTimeMap()[i].t1.value();
0032 t2_[i] = values.getTimeMap()[i].t2.value();
0033 t3_[i] = values.getTimeMap()[i].t3.value();
0034 }
0035 }
0036
0037 EcalLinearCorrectionsGPU::Product const& EcalLinearCorrectionsGPU::getProduct(cudaStream_t cudaStream) const {
0038 auto const& product = product_.dataForCurrentDeviceAsync(
0039 cudaStream, [this](EcalLinearCorrectionsGPU::Product& product, cudaStream_t cudaStream) {
0040
0041 product.p1 = cms::cuda::make_device_unique<float[]>(p1_.size(), cudaStream);
0042 product.p2 = cms::cuda::make_device_unique<float[]>(p2_.size(), cudaStream);
0043 product.p3 = cms::cuda::make_device_unique<float[]>(p3_.size(), cudaStream);
0044 product.t1 = cms::cuda::make_device_unique<edm::TimeValue_t[]>(t1_.size(), cudaStream);
0045 product.t2 = cms::cuda::make_device_unique<edm::TimeValue_t[]>(t2_.size(), cudaStream);
0046 product.t3 = cms::cuda::make_device_unique<edm::TimeValue_t[]>(t3_.size(), cudaStream);
0047
0048 cms::cuda::copyAsync(product.p1, p1_, cudaStream);
0049 cms::cuda::copyAsync(product.p2, p2_, cudaStream);
0050 cms::cuda::copyAsync(product.p3, p3_, cudaStream);
0051 cms::cuda::copyAsync(product.t1, t1_, cudaStream);
0052 cms::cuda::copyAsync(product.t2, t2_, cudaStream);
0053 cms::cuda::copyAsync(product.t3, t3_, cudaStream);
0054 });
0055
0056 return product;
0057 }
0058
0059 TYPELOOKUP_DATA_REG(EcalLinearCorrectionsGPU);