13
votes

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 ?

2
If you're using Tensorflow 1.1 from the prebuild binaries, you need CUDA 8 and cuDNN 5.1. Did you build this yourself?GPhilo
I have updated Tensorflow to v1.5. The error message disappeared but it is still using my CPU instead of my GPU. Do you what could be the reason?Vincent Roye
You installed via pip "tensorflow" instead of "tensorflow-gpu" perhaps?GPhilo
no, tensorflow-gpu is installed (only)Vincent Roye
Now I'm on : - Tensorflow-gpu 1.6 - CUDA 9.0 - Cudnn 7.0 Still : failed call to cuInit: CUDA_ERROR_NO_DEVICEVincent Roye

2 Answers

26
votes

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.

22
votes

The true answer is to add following line of code:

import os
os.environ['CUDA_VISIBLE_DEVICES'] = "0"