Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use TensorFlow GPU?

How do I 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 do I switch to GPU version?

like image 463
Guruku Avatar asked Jul 12 '18 13:07

Guruku


People also ask

Does TensorFlow automatically use GPU?

If a TensorFlow operation has both CPU and GPU implementations, TensorFlow will automatically place the operation to run on a GPU device first. If you have more than one GPU, the GPU with the lowest ID will be selected by default. However, TensorFlow does not place operations into multiple GPUs automatically.


2 Answers

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()) 
like image 78
Ashwel Avatar answered Oct 14 '22 14:10

Ashwel


The 'new' way to install tensorflow GPU if you have Nvidia, is with Anaconda. Works on Windows too. With 1 line.

conda create --name tf_gpu tensorflow-gpu  

This is a shortcut for 3 commands, which you can execute separately if you want or if you already have a conda environment and do not need to create one.

  1. Create an anaconda environment conda create --name tf_gpu

  2. Activate the environment conda activate tf_gpu

  3. Install tensorflow-GPU conda install tensorflow-gpu

You can use the conda environment.

like image 37
kkica Avatar answered Oct 14 '22 16:10

kkica