Skip to content

Commit

Permalink
Protect CAHitNtupletCUDA ctor/dtor when CUDA is not available (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
fwyzard committed Aug 27, 2020
1 parent a666934 commit 7f369c1
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "FWCore/Utilities/interface/isFinite.h"
#include "HeterogeneousCore/CUDAServices/interface/CUDAService.h"
#include "TrackingTools/DetLayers/interface/BarrelDetLayer.h"

#include "CAHitNtupletGeneratorOnGPU.h"
Expand Down Expand Up @@ -92,26 +94,33 @@ CAHitNtupletGeneratorOnGPU::CAHitNtupletGeneratorOnGPU(const edm::ParameterSet&
#endif

if (m_params.onGPU_) {
cudaCheck(cudaMalloc(&m_counters, sizeof(Counters)));
cudaCheck(cudaMemset(m_counters, 0, sizeof(Counters)));
// allocate pinned host memory only if CUDA is available
edm::Service<CUDAService> cs;
if (cs and cs->enabled()) {
cudaCheck(cudaMalloc(&m_counters, sizeof(Counters)));
cudaCheck(cudaMemset(m_counters, 0, sizeof(Counters)));
}
} else {
m_counters = new Counters();
memset(m_counters, 0, sizeof(Counters));
}
}

CAHitNtupletGeneratorOnGPU::~CAHitNtupletGeneratorOnGPU() {
if (m_params.doStats_) {
// crash on multi-gpu processes
if (m_params.onGPU_) {
CAHitNtupletGeneratorKernelsGPU::printCounters(m_counters);
} else {
CAHitNtupletGeneratorKernelsCPU::printCounters(m_counters);
}
}
if (m_params.onGPU_) {
cudaFree(m_counters);
// print the gpu statistics and free pinned host memory only if CUDA is available
edm::Service<CUDAService> cs;
if (cs and cs->enabled()) {
if (m_params.doStats_) {
// crash on multi-gpu processes
CAHitNtupletGeneratorKernelsGPU::printCounters(m_counters);
}
cudaFree(m_counters);
}
} else {
if (m_params.doStats_) {
CAHitNtupletGeneratorKernelsCPU::printCounters(m_counters);
}
delete m_counters;
}
}
Expand Down

0 comments on commit 7f369c1

Please sign in to comment.