File indexing completed on 2024-04-06 12:02:16
0001 #include "CondFormats/HcalObjects/interface/HcalQIECodersGPU.h"
0002 #include "FWCore/Utilities/interface/typelookup.h"
0003 #include "HeterogeneousCore/CUDAUtilities/interface/copyAsync.h"
0004
0005 HcalQIECodersGPU::HcalQIECodersGPU(HcalQIEData const& qiedata)
0006 : totalChannels_{qiedata.getAllContainers()[0].second.size() + qiedata.getAllContainers()[1].second.size()},
0007 offsets_(totalChannels_ * numValuesPerChannel),
0008 slopes_(totalChannels_ * numValuesPerChannel) {
0009 auto const containers = qiedata.getAllContainers();
0010
0011
0012 auto const& barrelValues = containers[0].second;
0013 for (uint64_t i = 0; i < barrelValues.size(); ++i) {
0014 for (uint32_t k = 0; k < 4; k++)
0015 for (uint32_t l = 0; l < 4; l++) {
0016 auto const linear = k * 4 + l;
0017 offsets_[i * numValuesPerChannel + linear] = barrelValues[i].offset(k, l);
0018 slopes_[i * numValuesPerChannel + linear] = barrelValues[i].slope(k, l);
0019 }
0020 }
0021
0022
0023 auto const& endcapValues = containers[1].second;
0024 auto const offset = barrelValues.size();
0025 for (uint64_t i = 0; i < endcapValues.size(); ++i) {
0026 auto const off = (i + offset) * numValuesPerChannel;
0027 for (uint32_t k = 0; k < 4; k++)
0028 for (uint32_t l = 0; l < 4; l++) {
0029 auto const linear = k * 4u + l;
0030 offsets_[off + linear] = endcapValues[i].offset(k, l);
0031 slopes_[off + linear] = endcapValues[i].slope(k, l);
0032 }
0033 }
0034 }
0035
0036 HcalQIECodersGPU::Product const& HcalQIECodersGPU::getProduct(cudaStream_t stream) const {
0037 auto const& product =
0038 product_.dataForCurrentDeviceAsync(stream, [this](HcalQIECodersGPU::Product& product, cudaStream_t stream) {
0039
0040 product.offsets = cms::cuda::make_device_unique<float[]>(offsets_.size(), stream);
0041 product.slopes = cms::cuda::make_device_unique<float[]>(slopes_.size(), stream);
0042
0043
0044 cms::cuda::copyAsync(product.offsets, offsets_, stream);
0045 cms::cuda::copyAsync(product.slopes, slopes_, stream);
0046 });
0047
0048 return product;
0049 }
0050
0051 TYPELOOKUP_DATA_REG(HcalQIECodersGPU);