diff --git a/PhysicsTools/TensorFlow/src/TensorFlow.cc b/PhysicsTools/TensorFlow/src/TensorFlow.cc index fcb09e2e9c449..786166ef407a9 100644 --- a/PhysicsTools/TensorFlow/src/TensorFlow.cc +++ b/PhysicsTools/TensorFlow/src/TensorFlow.cc @@ -42,6 +42,15 @@ namespace tensorflow { // NVidia GPU else if (backend == Backend::cuda) { if (not ri->nvidiaDriverVersion().empty()) { + // Check if one GPU device is visible to TF + // If not, an exception is raised --> this can happen in case of driver version mismatch + // or missing CUDA support in TF compilation + if ((*_options.config.mutable_device_count())["GPU"] == 0) { + edm::Exception ex(edm::errors::UnavailableAccelerator); + ex << "Cuda backend requested, NVIDIA GPU visible to cmssw, but not visible to TensorFlow in the job"; + ex.addContext("Calling tensorflow::setBackend()"); + throw ex; + } // Take only the first GPU in the CUDA_VISIBLE_DEVICE list (*_options.config.mutable_device_count())["GPU"] = 1; _options.config.mutable_gpu_options()->set_visible_device_list("0");