diff --git a/HeterogeneousCore/CUDACore/interface/ESProduct.h b/HeterogeneousCore/CUDACore/interface/ESProduct.h index 8740095292380..fbe1825b0fa4d 100644 --- a/HeterogeneousCore/CUDACore/interface/ESProduct.h +++ b/HeterogeneousCore/CUDACore/interface/ESProduct.h @@ -20,10 +20,12 @@ namespace cms { class ESProduct { public: ESProduct() : gpuDataPerDevice_(numberOfDevices()) { - cms::cuda::ScopedSetDevice scopedDevice; - for (size_t i = 0; i < gpuDataPerDevice_.size(); ++i) { - scopedDevice.set(i); - gpuDataPerDevice_[i].m_event = getEventCache().get(); + if (not gpuDataPerDevice_.empty()) { + cms::cuda::ScopedSetDevice scopedDevice; + for (size_t i = 0; i < gpuDataPerDevice_.size(); ++i) { + scopedDevice.set(i); + gpuDataPerDevice_[i].m_event = getEventCache().get(); + } } }