Skip to content

Instantly share code, notes, and snippets.

@rava-dosa
Last active May 30, 2019 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rava-dosa/75a04514ad6864b1eb0eee6c9821143a to your computer and use it in GitHub Desktop.
Save rava-dosa/75a04514ad6864b1eb0eee6c9821143a to your computer and use it in GitHub Desktop.
sudo apt-get --purge remove nvidia-*
sudo apt-get autoremove
sudo apt-get update
sudo gedit /etc/modprobe.d/blacklist-nouveau.conf
paste
blacklist 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
#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
#links to follow
#https://www.tensorflow.org/install/install_linux
#https://kislayabhi.github.io/Installing_CUDA_with_Ubuntu/
#https://medium.com/@vivek.yadav/deep-learning-setup-for-ubuntu-16-04-tensorflow-1-2-keras-opencv3-python3-cuda8-and-cudnn5-1-324438dd46f0
#https://www.linkedin.com/pulse/installing-nvidia-cuda-80-ubuntu-1604-linux-gpu-new-victor
#http://www.allaboutlinux.eu/remove-nouveau-and-install-nvidia-driver-in-ubuntu-15-04/
#https://gist.github.com/ksopyla/813a62d6afc4307755e5832a3b62f432
#https://docs.bazel.build/versions/master/install-ubuntu.html#install-on-ubuntu
#Basic concepts while installation
#Don't install opengl and opencl
#Don't do anythin that meses up with Xorg
#That is don't do anything that installs a new package or gui manager
#https://www.youtube.com/watch?v=1Gd6e5BLkwo&feature=youtu.be
#
@rava-dosa
Copy link
Author

rava-dosa commented Aug 2, 2018

now on ubuntu 18.04 you don't need to do all this:

  1. sudo apt-get --purge remove nvidia-*
  2. sudo apt-get autoremove
  3. sudo add-apt-repository ppa:graphics-drivers/ppa
  4. sudo apt-get update
  5. sudo apt-get install nvidia-375
  6. sudo reboot
  7. 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
    // when asked about adding path do it.
  8. source ~/.bashrc
  9. conda update conda
  10. conda update anaconda
  11. conda update python
  12. conda update --all
  13. conda create --name tf-gpu
  14. source activate tf-gpu
  15. conda install tensorflow-gpu
    I tried this and it worked. So now if you want to check if it's working or not:
  16. python
    16.1. import tensorflow as tf
    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))
  1. If it's working then you are done with installation.
  2. Ref:
    18.1. https://gist.github.com/rava-dosa/75a04514ad6864b1eb0eee6c9821143a
    18.2. https://www.pugetsystems.com/labs/hpc/Install-TensorFlow-with-GPU-Support-the-Easy-Way-on-Ubuntu-18-04-without-installing-CUDA-1170/
    18.3 https://stackoverflow.com/questions/38009682/how-to-tell-if-tensorflow-is-using-gpu-acceleration-from-inside-python-shell

@pyradd
Copy link

pyradd commented Aug 26, 2018

I followed the procedure for ubuntu 18.04 but when I run python script it throws the following error:

2018-08-26 09:25:18.505743: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2
2018-08-26 09:25:18.507467: E tensorflow/stream_executor/cuda/cuda_driver.cc:397] failed call to cuInit: CUDA_ERROR_UNKNOWN
2018-08-26 09:25:18.507528: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:150] kernel driver does not appear to be running on this host (mohi-VirtualBox): /proc/driver/nvidia/version does not exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment