GPU is not used for calculations even though tensor-stream-gpu is installed
The following software is installed on my computer: Anaconda (3), TensorFlow (GPU) and Keras. There are two Anaconda virtual environments, one with TensorFlow for Python 2.7 and one for 3.5, the GPU version installed according to TF instructions . (I had the TensorFlow processor version installed earlier in a separate environment, but I uninstalled it.)
When I run the following:
source activate tensorflow-gpu-3.5
python code.py
and check nvidia-smi
it only shows 3MiB memory usage in Python, so it looks like the GPU is not being used for calculations. ( code.py
- simple deep Q-learning algorithm implemented with Keras)
Any ideas what could possibly go wrong?
source to share
The reason my GPU was not working was because of a broken CuDNN installation, or rather the libraries and source are from different versions of CuDNN.
This has been corrected with the following tip.
source to share
A good way to debug these problems is to check which operations have been distributed to which devices.
You can check this by passing a config parameter to the session:
session = tf.Session(config=tf.ConfigProto(log_device_placement=True))
When you start the application, you will see some kind of output indicating which devices are in use.
You can find more information here: https://www.tensorflow.org/tutorials/using_gpu
source to share
TensorFlow on Windows
It took me a few hours to fix problems with installing TensorFlow on windows, so here's a summary:
Check if TensorFlow-gpu is working or not (use this code):
with tf.device('/gpu:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
with tf.Session() as sess:
print(sess.run(c))
To check the list of available CPUs or GPUs (use this code):
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
if tf.test.gpu_device_name():
print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
else:
print("Please install GPU version of TF")
Install Tensorflow GPU on Windows using CUDA and cuDNN
Guide overview
- Install the Nvidia card on your computer along with the drivers.
- Downloading and installing CUDA
- Download and install "cuDNN"
- Uninstalling Tensorflow, Installing Tensorflow GPU
- Update% PATH% on the system
- Check installation
Manual Full Details
Specify
- You removed tensorflow and in order to get things done, you just installed tensorflow-gpu for it.
- Remove tensorflow from pip and conda context depending on your project settings and only install tensorflow-gpu
- After setting the PATH variable, be sure to log out or reboot the system.
Hope this is helpful :))
source to share