From b13b7010b9fb31a742ae0f52197284c2783063ef Mon Sep 17 00:00:00 2001 From: Soumith Chintala Date: Fri, 31 Mar 2017 12:19:59 -0400 Subject: [PATCH] check for nvidia driver's sufficiency before checking for number of CUDA devices (#1156) --- torch/csrc/autograd/engine.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/torch/csrc/autograd/engine.cpp b/torch/csrc/autograd/engine.cpp index 4c025631f2fbc..3f7c6f897b977 100644 --- a/torch/csrc/autograd/engine.cpp +++ b/torch/csrc/autograd/engine.cpp @@ -350,7 +350,14 @@ auto Engine::ready_queue(int device) -> ReadyQueue& { auto Engine::start_threads() -> void { int num_devices = 0; #ifdef WITH_CUDA - THCudaCheck(cudaGetDeviceCount(&num_devices)); + cudaError_t err = cudaGetDeviceCount(&num_devices); + + // check for case of compiled with CUDA but no NVIDIA driver available + if (err == cudaErrorInsufficientDriver) { + num_devices = 0; + } else { + THCudaCheck(err); + } #endif ready_queues = std::vector>(num_devices + 1); for (auto& queue : ready_queues) {