How to use TensorFlow GPU?

Go To StackoverFlow.com

9

How to use TensorFlow GPU version instead of CPU version in Python 3.6 x64?

import tensorflow as tf

Python is using my CPU for calculations.
I can notice it because I have an error:

Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

I have installed tensorflow and tensorflow-gpu.

How to switch to GPU version?

2018-07-12 13:23
by Guruku
Have you tried uninstalling tensorflow and just keep the tensorflow-gpu installed - Jorge Leitão 2018-07-12 13:27
Try downloading CUDA and installing the GPU version - Warp Drive Enterprises 2018-07-12 13:28
That's just a warning, if you have an NVIDIA GPU, Tensorflow-gpu will automatically use that. To know more and how to disable the warning: https://stackoverflow.com/a/47227886/4892874 To check that you're using the GPU: sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))iacolippo 2018-07-12 13:29
Are you using Anaconda ? if you are you have to switch the interpreter of the particular environment in PyCharm - Mohan Radhakrishnan 2018-07-12 13:30
Device mapping: no known devices. I do not use Anacond - Guruku 2018-07-12 13:31
What is your GPU - Mathieu 2018-07-12 13:33
NVIDIA 940mx, it is relative new Nvidia card. @JorgeLeitão yes, then I have no TensorFlo - Guruku 2018-07-12 13:36


4

Follow this tutorial Tensorflow GPU I did it and it works perfect.

Attention! - install version 9.0! newer version is not supported by Tensorflow-gpu

Steps:

  1. Uninstall your old tensorflow
  2. Install tensorflow-gpu pip install tensorflow-gpu
  3. Install Nvidia Graphics Card & Drivers (you probably already have)
  4. Download & Install CUDA
  5. Download & Install cuDNN
  6. Verify by simple program

from tensorflow.python.client import device_lib print(device_lib.list_local_devices())

2018-07-12 13:48
by Ashwel
So, CUDA 9.2 can be the problem? Should I install 9.0 then? Yesterday I had an error after installing CUDA 9.2. It said that I need DLL from CUDA 9.0 and I knew it was using GPU version, today all the time I see the error about CPU, so it is using CPU. I will try it step by step, thanks - Guruku 2018-07-12 13:52
Yea, i had same problem about 2 month ago. I tried CUDA 9.1 and Tensorflow doesn't support it..Then i uninstall everything and repeat all steps with CUDA 9.0 and now it works without problems - Ashwel 2018-07-12 14:06
Maybe I should ask in another question, but is tensorflow on GPU is faster than CPU at your PC? I tried with linear regression model and for 10000 epos and step 0.01 my CPU can calculate it in 13 second and when I use GPU it takes 39 second - Guruku 2018-07-12 17:13
Ofc i have CPU i7 8700k and GPU nVidia GTX 1060 STRING 6GB and on GPU is faster 20 times aproximate - Ashwel 2018-07-13 06:25


1

I tried following the above tutorial. Thing is tensorflow changes a lot and so do the NVIDIA versions needed for running on a GPU. The next issue is that your driver version determines your toolkit version etc. As of today this information about the software requirements should shed some light on how they interplay:

NVIDIA® GPU drivers —CUDA 9.0 requires 384.x or higher.
CUDA® Toolkit —TensorFlow supports CUDA 9.0.
CUPTI ships with the CUDA Toolkit.
cuDNN SDK (>= 7.2) Note: Make sure your GPU has compute compatibility >3.0
(Optional) NCCL 2.2 for multiple GPU support.
(Optional) TensorRT 4.0 to improve latency and throughput for inference on some models.

And here you'll find the up-to-date requirements stated by tensorflow (which will hopefully be updated by them on a regular basis).

2019-01-06 20:53
by mrk
Ads