Skip to content

Instantly share code, notes, and snippets.

@Quasimondo
Last active December 9, 2023 09:17
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Quasimondo/7e1068e488e20f194d37ba80696b55d8 to your computer and use it in GitHub Desktop.
Save Quasimondo/7e1068e488e20f194d37ba80696b55d8 to your computer and use it in GitHub Desktop.
A possible fix for "failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device"
This is a dreaded error that seems pop up its ugly head again and again, in particular after upgrading CUDA or Tensorflow.
Typcially it looks like this:
2020-12-30 17:31:40.829615: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2020-12-30 17:31:42.149768: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2020-12-30 17:31:42.150368: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcuda.so.1
2020-12-30 17:31:42.176643: E tensorflow/stream_executor/cuda/cuda_driver.cc:328] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected
Here is a solution that currently seems to work on my system,
with Cuda 11.0 and Tensorflow 2.4.0, you can try it if all the
other 500 proposed fixes did not work for you:
Add these two lines at the very top of your script BEFORE any call to "import tensorflow":
from tensorflow.python.client import device_lib
device_lib.list_local_devices()
That's all suddenly it works. I have no clue why.
If that did not help, here are a few other things you can try:
https://victorwyee.com/engineering/failed-call-to-cuinit-cuda-error-unknown/
@toomanycats
Copy link

This helped me, thanks.

@fabhari
Copy link

fabhari commented Feb 4, 2023

This fix seam to be silly, but still works perfectly. found this after a long struggle

@toomanycats
Copy link

I'm really guessing here but I have a thought on why it could work.
When I worked with serial devices in the past, sometimes the devices wouldn't talk unless I pinged them with a generic
query like, "what's your serial number?". Perhaps there's something similar happening with the GPU and the BUS that connects them.

@CH4LLENG3R
Copy link

LOL! It actually works. I didn't expect that at all. Thanks!

@tahakhalil
Copy link

worked to me, thinks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment