Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "CondFormats/HcalObjects/interface/HcalSiPMCharacteristics.h"
0002 #include "CondFormats/HcalObjects/interface/HcalSiPMCharacteristicsGPU.h"
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 #include "FWCore/Utilities/interface/typelookup.h"
0005 #include "HeterogeneousCore/CUDAUtilities/interface/copyAsync.h"
0006 
0007 HcalSiPMCharacteristicsGPU::HcalSiPMCharacteristicsGPU(HcalSiPMCharacteristics const& parameters)
0008     : pixels_(parameters.getTypes()),
0009       auxi1_(parameters.getTypes()),
0010       parLin1_(parameters.getTypes()),
0011       parLin2_(parameters.getTypes()),
0012       parLin3_(parameters.getTypes()),
0013       crossTalk_(parameters.getTypes()),
0014       auxi2_(parameters.getTypes()) {
0015   for (uint32_t i = 0; i < parameters.getTypes(); i++) {
0016     auto const type = parameters.getType(i);
0017 #ifdef HCAL_MAHI_CPUDEBUG
0018     printf("index = %u type = %d\n", i, type);
0019 #endif
0020 
0021     // for now...
0022     if (static_cast<uint32_t>(type) != i + 1)
0023       throw cms::Exception("HcalSiPMCharacteristics")
0024           << "Wrong assumption for HcalSiPMcharacteristics type values, "
0025           << "should be type value <- type index + 1" << std::endl
0026           << "Observed type value = " << type << " and index = " << i << std::endl;
0027 
0028     pixels_[i] = parameters.getPixels(type);
0029     auxi1_[i] = parameters.getAuxi1(type);
0030     parLin1_[i] = parameters.getNonLinearities(type)[0];
0031     parLin2_[i] = parameters.getNonLinearities(type)[1];
0032     parLin3_[i] = parameters.getNonLinearities(type)[2];
0033     crossTalk_[i] = parameters.getCrossTalk(type);
0034     auxi2_[i] = parameters.getAuxi2(type);
0035   }
0036 }
0037 
0038 HcalSiPMCharacteristicsGPU::Product const& HcalSiPMCharacteristicsGPU::getProduct(cudaStream_t stream) const {
0039   auto const& product = product_.dataForCurrentDeviceAsync(
0040       stream, [this](HcalSiPMCharacteristicsGPU::Product& product, cudaStream_t stream) {
0041         // allocate
0042         product.pixels = cms::cuda::make_device_unique<int[]>(pixels_.size(), stream);
0043         product.auxi1 = cms::cuda::make_device_unique<int[]>(auxi1_.size(), stream);
0044         product.parLin1 = cms::cuda::make_device_unique<float[]>(parLin1_.size(), stream);
0045         product.parLin2 = cms::cuda::make_device_unique<float[]>(parLin2_.size(), stream);
0046         product.parLin3 = cms::cuda::make_device_unique<float[]>(parLin3_.size(), stream);
0047         product.crossTalk = cms::cuda::make_device_unique<float[]>(crossTalk_.size(), stream);
0048         product.auxi2 = cms::cuda::make_device_unique<float[]>(auxi2_.size(), stream);
0049 
0050         // transfer
0051         cms::cuda::copyAsync(product.pixels, pixels_, stream);
0052         cms::cuda::copyAsync(product.auxi1, auxi1_, stream);
0053         cms::cuda::copyAsync(product.parLin1, parLin1_, stream);
0054         cms::cuda::copyAsync(product.parLin2, parLin2_, stream);
0055         cms::cuda::copyAsync(product.parLin3, parLin3_, stream);
0056         cms::cuda::copyAsync(product.crossTalk, crossTalk_, stream);
0057         cms::cuda::copyAsync(product.auxi2, auxi2_, stream);
0058       });
0059 
0060   return product;
0061 }
0062 
0063 TYPELOOKUP_DATA_REG(HcalSiPMCharacteristicsGPU);