Once upon a time
There was a operating system called Ubuntu 14.04, I tried installing tensorflow gpu on that. And I was stuck in login loop as Tom cruise was stuck in time loop in the movie “The Edge of tomorrow”. I couldn’t get out of login loop until I installed Ubuntu 16.04
Want to know how was my experience with ubuntu 16.04
In a very few[sarcastic laugh] steps I was able to install it.
- sudo apt-get –purge remove nvidia-*
- sudo apt-get autoremove
- sudo apt-get update
- sudo gedit /etc/modprobe.d/blacklist-nouveau.conf
pasteblacklist nouveau blacklist lbm-nouveau options nouveau modeset=0 alias nouveau off alias lbm-nouveau off
echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
- sudo update-initramfs -u
- sudo apt-get update
- sudo apt-get upgrade -y
- sudo apt-get dist-upgrade -y
- sudo apt-get install build-essential
- sudo apt-get install linux-image-extra-virtual
- sudo apt-get install linux-source
- sudo apt-get source linux-image-$(uname -r)
- sudo apt-get install linux-headers-$(uname -r)
- wget -O cuda_8_linux.run https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run
- sudo chmod +x cuda_8_linux.run
#in tty ctrl+alt+f1 or ctrl + alt +f6 sudo service lightdm stop #or if you are using gnome 3 then sudo service gdm3 stop sudo ./cuda_8_linux.run
- sudo service gdm3 stop
- sudo ./cuda_8_linux.run
#Do you accept the previously read EULA? #accept #Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48? #n (we installed drivers previously) #Install the CUDA 8.0 Toolkit? #y #Enter Toolkit Location: # /usr/local/cuda-8.0 (enter) # Do you wish to run the installation with ‚sudo’? # y # Do you want to install a symbolic link at /usr/local/cuda? # y # Install the CUDA 8.0 Samples? # y # Enter CUDA Samples Location: # enter # Install cuDNN # go to website and download cudnn-8.1 https://developer.nvidia.com/cudnn
-
tar -zxvf cudnn-8.1-linux-x64-v5.1.tgz
- copy libs to /usr/local/cuda folder
- sudo cp -P cuda/include/cudnn.h /usr/local/cuda/include
- sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64
- sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
- sudo add-apt-repository ppa:graphics-drivers/ppa
- sudo apt-get update
- sudo apt-get install nvidia-375
- sudo apt-get install libcupti-dev
Once nvidia driver is installed, restart the computer. You can verify the driver using the following command.
- cat /proc/driver/nvidia/version
- echo ‘export PATH=/usr/local/cuda/bin:$PATH’ » ~/.bashrc
- sudo apt-get install python-numpy python-dev python-pip python-wheel
Download Bazel
- chmod +x bazel-0.5.2-installer-linux-x86_64.sh
- ./bazel-0.5.2-installer-linux-x86_64.sh –user
paste in bashrc
- export PATH=”$PATH:$HOME/bin”
https://www.anaconda.com/download/ install anaconda
Add these two lines in gedit ~/.bashrc
- export LD_LIBRARY_PATH=”$LD_LIBRARY_PATH:/usr/local/cuda/lib64”
- export CUDA_HOME=/usr/local/cuda
- conda create -n tensorflow
- source activate tensorflow
- pip install –ignore-installed –upgrade \ https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.0-cp27-none-linux_x86_64.whl
But as time has passed by…………..
Things have changed a lot.Now on new ubuntu 18.04 you don’t need to do all this, Things have become relatively easy:
(Even though I installed conda packages first)
- sudo apt-get –purge remove nvidia-*
- sudo apt-get autoremove
- sudo add-apt-repository ppa:graphics-drivers/ppa
- sudo apt-get update
- sudo apt-get install nvidia-375
- sudo reboot
- wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
7.1. bash Anaconda3-5.2.0-Linux-x86_64.sh
While installation,when asked about adding path,say yes. - source ~/.bashrc
- conda update conda
- conda update anaconda
- conda update python
- conda update –all
- conda create –name tf-gpu
- source activate tf-gpu
- conda install tensorflow-gpu
I tried this and it worked. So now if you want to check if gpu device is recognized or not:
- python
16.1. import tensorflow as tfwith 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))
- That’s it you are done with installation.
- Reference