Skip to content

Commit

Permalink
HcalDigisProducerGPU: preallocate pinned host memory only if CUDA is …
Browse files Browse the repository at this point in the history
…available (#543)
  • Loading branch information
fwyzard committed Aug 26, 2020
1 parent e4696ec commit a666934
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions EventFilter/HcalRawToDigi/plugins/HcalDigisProducerGPU.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<hcal::Flavor5>(HBHEDataFrame::MAXSAMPLES);
hf01_.stride = hcal::compute_stride<hcal::Flavor01>(QIE11DigiCollection::MAXSAMPLES);
hf5_.stride = hcal::compute_stride<hcal::Flavor5>(HBHEDataFrame::MAXSAMPLES);
hf3_.stride = hcal::compute_stride<hcal::Flavor3>(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<CUDAService> 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,
Expand All @@ -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<hcal::Flavor5>(nsamples);
hf5_.stride = stride;

// flavor5 get device blobs
df5_.stride = stride;
df5_.data = cms::cuda::make_device_unique<uint16_t[]>(
config_.maxChannelsF5HB * stride, ctx.stream());
df5_.data = cms::cuda::make_device_unique<uint16_t[]>(config_.maxChannelsF5HB * stride, ctx.stream());
df5_.ids = cms::cuda::make_device_unique<uint32_t[]>(config_.maxChannelsF5HB, ctx.stream());
df5_.npresamples = cms::cuda::make_device_unique<uint8_t[]>(config_.maxChannelsF5HB, ctx.stream());
}
Expand All @@ -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<uint16_t[]>(
config_.maxChannelsF01HE * stride01, ctx.stream());
df01_.data = cms::cuda::make_device_unique<uint16_t[]>(config_.maxChannelsF01HE * stride01, ctx.stream());
df01_.ids = cms::cuda::make_device_unique<uint32_t[]>(config_.maxChannelsF01HE, ctx.stream());

// flavor3 get device blobs
df3_.stride = stride3;
df3_.data = cms::cuda::make_device_unique<uint16_t[]>(
config_.maxChannelsF3HB * stride3, ctx.stream());
df3_.data = cms::cuda::make_device_unique<uint16_t[]>(config_.maxChannelsF3HB * stride3, ctx.stream());
df3_.ids = cms::cuda::make_device_unique<uint32_t[]>(config_.maxChannelsF3HB, ctx.stream());
}

Expand Down Expand Up @@ -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<decltype(src)>::type;
using type = typename vector_type::value_type;
using dest_data_type = typename std::remove_pointer<decltype(dest)>::type;
Expand Down

0 comments on commit a666934

Please sign in to comment.