Skip to content

Instantly share code, notes, and snippets.

@lucduong
Created June 30, 2017 07:01
Show Gist options
  • Save lucduong/f635cbe43372b0ffbe14d5966f82e003 to your computer and use it in GitHub Desktop.
Save lucduong/f635cbe43372b0ffbe14d5966f82e003 to your computer and use it in GitHub Desktop.
Install TensorFlow CentOS

Verify You Have a CUDA-Capable GPU

To verify that your GPU is CUDA-capable, go to your distribution's equivalent of System Properties, or, from the command line, enter:

lspci | grep -i nvidia

If you do not see any settings, update the PCI hardware database that Linux maintains by entering update-pciids (generally found in /sbin) at the command line and rerun the previous lspci command.

If your graphics card is from NVIDIA and it is listed in CUDA-GPUS, your GPU is CUDA-capable.

The Release Notes for the CUDA Toolkit also contain a list of supported products.

Verify You Have a Supported Version of Linux

The CUDA Development Tools are only supported on some specific distributions of Linux. These are listed in the CUDA Toolkit release notes.

To determine which distribution and release number you're running, type the following at the command line:

uname -m && cat /etc/*release

You should see output similar to the following, modified for your particular system:

x86_64

Red Hat Enterprise Linux Workstation release 6.0 (Santiago) The x86_64 line indicates you are running on a 64-bit system. The remainder gives information about your distribution.

Verify the System Has gcc Installed

The gcc compiler is required for development using the CUDA Toolkit. It is not required for running CUDA applications. It is generally installed as part of the Linux installation, and in most cases the version of gcc installed with a supported version of Linux will work correctly.

To verify the version of gcc installed on your system, type the following on the command line:

gcc --version

If an error message displays, you need to install the development tools from your Linux distribution or obtain a version of gcc and its accompanying toolchain from the Web.

Verify the System has the Correct Kernel Headers and Development Packages Installed

The CUDA Driver requires that the kernel headers and development packages for the running version of the kernel be installed at the time of the driver installation, as well whenever the driver is rebuilt. For example, if your system is running kernel version 3.17.4-301, the 3.17.4-301 kernel headers and development packages must also be installed.

While the Runfile installation performs no package validation, the RPM and Deb installations of the driver will make an attempt to install the kernel header and development packages if no version of these packages is currently installed. However, it will install the latest version of these packages, which may or may not match the version of the kernel your system is using. Therefore, it is best to manually ensure the correct version of the kernel headers and development packages are installed prior to installing the CUDA Drivers, as well as whenever you change the kernel version.

The version of the kernel your system is running can be found by running the following command:

uname -r

This is the version of the kernel headers and development packages that must be installed prior to installing the CUDA Drivers. This command will be used multiple times below to specify the version of the packages to install. Note that below are the common-case scenarios for kernel usage. More advanced cases, such as custom kernel branches, should ensure that their kernel headers and sources match the kernel build they are running.

RHEL/CentOS

The kernel headers and development packages for the currently running kernel can be installed with:

sudo yum install kernel-devel-$(uname -r) kernel-headers-$(uname -r)

Fedora

The kernel headers and development packages for the currently running kernel can be installed with:

sudo dnf install kernel-devel-$(uname -r) kernel-headers-$(uname -r)

OpenSUSE/SLES

Use the output of the uname command to determine the running kernel's version and variant:

uname -r
3.16.6-2-default

In this example, the version is 3.16.6-2 and the variant is default. The kernel headers and development packages can then be installed with the following command, replacing and with the variant and version discovered from the previous uname command:

sudo zypper install kernel-<variant>-devel=<version>

Ubuntu

The kernel headers and development packages for the currently running kernel can be installed with:

sudo apt-get install linux-headers-$(uname -r)

Read more at: Cuda installation guide

Download from Official Site

https://developer.nvidia.com/cuda-downloads

Navigate to downloaded folder.

bash cuda_8.0.61_375.26_linux.run

Press ctrl+D to go next page and accept all the question.

vi ~/.bash_profile

export CUDA_HOME=/usr/local/cuda-8.0
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64:$LD_LIBRARY_PATH
export PATH=${CUDA_HOME}/bin:${PATH}

Source profile

source ~/.bash_profile

Download cuDNN v5.1

cuDNN

Sing In and select cuDNN v5.1

Navigate to downloaded cudnn folder.

tar zxvf cudnn-8.0-linux-x64-v5.1.tgz
cd cuda
sudo cp lib64/* /usr/local/cuda/lib64/
sudo cp include/* /usr/local/cuda/include/

Install libcupti-dev

The libcupti-dev library, which is the NVIDIA CUDA Profile Tools Interface. This library provides advanced profiling support. To install this library, issue the following command:


Prerequisites

First update your system. We do not wand to build NVidia modules on based on outdated Linux kernel. Do a full updated and reboot your system:

yum update
reboot

After a restart we make sure that we have kernel devel package installed matching our currently running kernel and that compiler is installed:

yum install kernel-devel-$(uname -r) gcc

Download latest driver

From here NVIDA Download

Or Directly from this link

wget http://us.download.nvidia.com/XFree86/Linux-x86_64/375.66/NVIDIA-Linux-x86_64-375.66.run

#Blacklist nouveau driver At this stage we need to ensure that a new propriatery NVidia driver does not get into a conflict with currently installed Nouveau driver thus we blacklist it:

echo 'blacklist nouveau' >> /etc/modprobe.d/blacklist.conf
dracut /boot/initramfs-$(uname -r).img $(uname -r) --force

We also temporarily disable desktop manager ( if you ar running kdm that updated the below command with kdm ):

systemctl disable gdm

Now reboot your system. Next time your system boots it will boot to terminal only with no GUI. As a result it is suggested to take some notes of the bellow commands as you will not be able to access this page with your GUI browser after you reboot:

reboot 

If you are running on centOS server, don't need to disable gdm and reboot.

NVIDIA GeForce Driver Installation

Now we have come to the actual NVidia driver installation. Locate your previously downloaded driver and execute ( your driver version may differ ):

bash NVIDIA-Linux-x86_64-352.30.run

Verifying archive integrity... OK Uncompressing NVIDIA Accelerated Graphics Driver for Linux-x86_64 352.30.................................................. NVidia driver is now installed. If you have not configured your X11 during the driver install you can do it now:

nvidia-xconfig 

WARNING: Unable to locate/open X configuration file.

New X configuration file written to '/etc/X11/xorg.conf' As a last step enable again your desktop manager and reboot to GUI with new NVidia driver:

systemctl enable gdm

ln -s '/usr/lib/systemd/system/gdm.service' '/etc/systemd/system/display-manager.service'

reboot

Verify installed driver

nvidia-smi

The output should be like below:

Fri Jun 30 11:39:03 2017
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 375.66                 Driver Version: 375.66                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 105...  Off  | 0000:01:00.0     Off |                  N/A |
|  0%   67C    P0    36W /  72W |      0MiB /  4038MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

Install python-devel

yum install python-devel

Install pip

curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"

python get-pip.py

Check the pip version

pip -V

The output should be like this:

pip 9.0.1 from /usr/lib/python2.7/site-packages (python 2.7)

Install TensorFlow

pip install tensorflow-gpu

For more detail, check Official Guide

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