Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:42

0001 #include "DataFormats/HcalDetId/interface/HcalElectronicsId.h"
0002 #include "FWCore/Utilities/interface/typelookup.h"
0003 #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
0004 
0005 #include "ElectronicsMappingGPU.h"
0006 
0007 namespace hcal {
0008   namespace raw {
0009 
0010     // TODO: 0x3FFFFF * 4B ~= 16MB
0011     // tmp solution for linear mapping of eid -> did
0012     ElectronicsMappingGPU::ElectronicsMappingGPU(HcalElectronicsMap const& mapping)
0013         : eid2tid_(HcalElectronicsId::maxLinearIndex, 0u), eid2did_(HcalElectronicsId::maxLinearIndex, 0u) {
0014       auto const& eidsPrecision = mapping.allElectronicsIdPrecision();
0015       for (uint32_t i = 0; i < eidsPrecision.size(); ++i) {
0016         auto const& eid = eidsPrecision[i];
0017 
0018         // assign
0019         eid2did_[eid.linearIndex()] = eid.isTriggerChainId() ? 0u : mapping.lookup(eid).rawId();
0020       }
0021 
0022       auto const& eidsTrigger = mapping.allElectronicsIdTrigger();
0023       for (uint32_t i = 0; i < eidsTrigger.size(); i++) {
0024         auto const& eid = eidsTrigger[i];
0025 
0026         // assign
0027         eid2tid_[eid.linearIndex()] = eid.isTriggerChainId() ? mapping.lookupTrigger(eid).rawId() : 0u;
0028       }
0029     }
0030 
0031     ElectronicsMappingGPU::Product::~Product() {
0032       // deallocation
0033       cudaCheck(cudaFree(eid2did));
0034       cudaCheck(cudaFree(eid2tid));
0035     }
0036 
0037     ElectronicsMappingGPU::Product const& ElectronicsMappingGPU::getProduct(cudaStream_t cudaStream) const {
0038       auto const& product = product_.dataForCurrentDeviceAsync(
0039           cudaStream, [this](ElectronicsMappingGPU::Product& product, cudaStream_t cudaStream) {
0040             // malloc
0041             cudaCheck(cudaMalloc((void**)&product.eid2did, this->eid2did_.size() * sizeof(uint32_t)));
0042             cudaCheck(cudaMalloc((void**)&product.eid2tid, this->eid2tid_.size() * sizeof(uint32_t)));
0043 
0044             // transfer
0045             cudaCheck(cudaMemcpyAsync(product.eid2did,
0046                                       this->eid2did_.data(),
0047                                       this->eid2did_.size() * sizeof(uint32_t),
0048                                       cudaMemcpyHostToDevice,
0049                                       cudaStream));
0050             cudaCheck(cudaMemcpyAsync(product.eid2tid,
0051                                       this->eid2tid_.data(),
0052                                       this->eid2tid_.size() * sizeof(uint32_t),
0053                                       cudaMemcpyHostToDevice,
0054                                       cudaStream));
0055           });
0056 
0057       return product;
0058     }
0059 
0060   }  // namespace raw
0061 }  // namespace hcal
0062 
0063 TYPELOOKUP_DATA_REG(hcal::raw::ElectronicsMappingGPU);