From a66693417602bd70d2c06ed9e0b124eb6a49f76c Mon Sep 17 00:00:00 2001 From: Andrea Bocci Date: Wed, 26 Aug 2020 21:43:02 +0200 Subject: [PATCH] HcalDigisProducerGPU: preallocate pinned host memory only if CUDA is available (#543) --- .../plugins/HcalDigisProducerGPU.cc | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/EventFilter/HcalRawToDigi/plugins/HcalDigisProducerGPU.cc b/EventFilter/HcalRawToDigi/plugins/HcalDigisProducerGPU.cc index d5b6d42d0ed2c..4a69b7f425e73 100644 --- a/EventFilter/HcalRawToDigi/plugins/HcalDigisProducerGPU.cc +++ b/EventFilter/HcalRawToDigi/plugins/HcalDigisProducerGPU.cc @@ -92,12 +92,17 @@ HcalDigisProducerGPU::HcalDigisProducerGPU(const edm::ParameterSet& ps) // this is a preallocation for the max statically known number of time samples // actual stride/nsamples will be inferred from data - hf5_.stride = hcal::compute_stride(HBHEDataFrame::MAXSAMPLES); hf01_.stride = hcal::compute_stride(QIE11DigiCollection::MAXSAMPLES); + hf5_.stride = hcal::compute_stride(HBHEDataFrame::MAXSAMPLES); hf3_.stride = hcal::compute_stride(QIE11DigiCollection::MAXSAMPLES); - hf01_.reserve(config_.maxChannelsF01HE); - hf5_.reserve(config_.maxChannelsF5HB); - hf3_.reserve(config_.maxChannelsF3HB); + + // preallocate pinned host memory only if CUDA is available + edm::Service cs; + if (cs and cs->enabled()) { + hf01_.reserve(config_.maxChannelsF01HE); + hf5_.reserve(config_.maxChannelsF5HB); + hf3_.reserve(config_.maxChannelsF3HB); + } } void HcalDigisProducerGPU::acquire(edm::Event const& event, @@ -117,17 +122,15 @@ void HcalDigisProducerGPU::acquire(edm::Event const& event, event.getByToken(hbheDigiToken_, hbheDigis); event.getByToken(qie11DigiToken_, qie11Digis); - // init f5 collection if (hbheDigis->size() > 0) { auto const nsamples = (*hbheDigis)[0].size(); auto const stride = hcal::compute_stride(nsamples); hf5_.stride = stride; - + // flavor5 get device blobs df5_.stride = stride; - df5_.data = cms::cuda::make_device_unique( - config_.maxChannelsF5HB * stride, ctx.stream()); + df5_.data = cms::cuda::make_device_unique(config_.maxChannelsF5HB * stride, ctx.stream()); df5_.ids = cms::cuda::make_device_unique(config_.maxChannelsF5HB, ctx.stream()); df5_.npresamples = cms::cuda::make_device_unique(config_.maxChannelsF5HB, ctx.stream()); } @@ -139,17 +142,15 @@ void HcalDigisProducerGPU::acquire(edm::Event const& event, hf01_.stride = stride01; hf3_.stride = stride3; - + // flavor 0/1 get devie blobs df01_.stride = stride01; - df01_.data = cms::cuda::make_device_unique( - config_.maxChannelsF01HE * stride01, ctx.stream()); + df01_.data = cms::cuda::make_device_unique(config_.maxChannelsF01HE * stride01, ctx.stream()); df01_.ids = cms::cuda::make_device_unique(config_.maxChannelsF01HE, ctx.stream()); // flavor3 get device blobs df3_.stride = stride3; - df3_.data = cms::cuda::make_device_unique( - config_.maxChannelsF3HB * stride3, ctx.stream()); + df3_.data = cms::cuda::make_device_unique(config_.maxChannelsF3HB * stride3, ctx.stream()); df3_.ids = cms::cuda::make_device_unique(config_.maxChannelsF3HB, ctx.stream()); } @@ -199,7 +200,8 @@ void HcalDigisProducerGPU::acquire(edm::Event const& event, } auto lambdaToTransfer = [&ctx](auto* dest, auto const& src) { - if (src.size() == 0) return; + if (src.size() == 0) + return; using vector_type = typename std::remove_reference::type; using type = typename vector_type::value_type; using dest_data_type = typename std::remove_pointer::type;