Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect CAHitNtupletCUDA ctor/dtor when CUDA is not available #544

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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