24

My test :

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()`

Error :

c:\l\work\tensorflow-1.1.0\tensorflow\stream_executor\cuda\cuda_driver.cc:405]

failed call to cuInit: CUDA_ERROR_NO_DEVICE

-> but "/cpu:0" works fine

Config :

nvidia-smi : enter image description here

  • CUDA Version 9.1
  • tensorflow-1.1.0
  • Windows 10
  • cudnn64_7.dll (installed in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\bin)
  • Only tensorflow-gpu is installed in my Conda environment

Why can't Tensorflow detect my GPU ?

talonmies
  • 70,661
  • 34
  • 192
  • 269
Vincent Roye
  • 2,751
  • 7
  • 33
  • 53

3 Answers3

36

The issue was solved on GitHub. This error message will be shown if you set an invalid value for the CUDA_VISIBLE_DEVICES environment variable, e.g. when you only have a single GPU (which has ID 0) and set CUDA_VISIBLE_DEVICES=1 or CUDA_VISIBLE_DEVICES=2.

mrry
  • 125,488
  • 26
  • 399
  • 400
35

The true answer is to add following line of code:

import os
os.environ['CUDA_VISIBLE_DEVICES'] = "0"
Muhammad Saqlain
  • 2,112
  • 4
  • 33
  • 48
fly
  • 383
  • 3
  • 2
  • 4
    Thank you. Funny enough this solution helped even when explicit "CUDA_VISIBLE_DEVICES=0 python ..." did not work. – Ivan Kovtun Feb 01 '20 at 01:09
  • 1
    So many places say to use "-1" to ignore GPU, but that just causes these error messages. Setting to zero makes sense, and it works (go figure) – DAG Dec 15 '21 at 17:38
0

If you're using Google Colab, it could be that your runtime is not GPU. Click the “Runtime” dropdown menu. Select “Change runtime type”. Now select GPU.

Claude COULOMBE
  • 3,434
  • 2
  • 36
  • 39