Run command

lspci | grep -i nvidia

and check your gpu https://developer.nvidia.com/cuda-gpus#collapse4

Install build and require package

apt install build-essential libcupti-dev

Download CUDA installer

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda

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

Install cuDNN

https://developer.nvidia.com/cudnn

# Runtime
dpkg -i libcudnn7_7.0.1.13-1+cuda8.0_amd64.deb
# Dev tool
dpkg -i libcudnn7-dev_7.0.1.13-1+cuda8.0_amd64.deb
# Sample (require dev tool)
dpkg -i libcudnn7-doc_7.0.1.13-1+cuda8.0_amd64.deb

Set ENV

sudo vim /etc/profile.d/cuda.sh

and put environment variable for CUDA and cuDNN

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

then restart to see result

Test sample

Set sample script and make it

cuda-install-samples-8.0.sh ~/nvidiasample
cd ~/nvidiasample/NVIDIA_CUDA-8.0_Samples
make

This will build command in ./bin/x86_64/linux/release/. We can run to check

./bin/x86_64/linux/release/deviceQuery

And will get the result that have a result about you cuda gpu

./bin/x86_64/linux/release/deviceQuery Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "GeForce GTX 460"
  CUDA Driver Version / Runtime Version          8.0 / 8.0
  CUDA Capability Major/Minor version number:    2.1
  Total amount of global memory:                 961 MBytes (1007747072 bytes)
  ( 7) Multiprocessors, ( 48) CUDA Cores/MP:     336 CUDA Cores
  GPU Max Clock rate:                            1550 MHz (1.55 GHz)
  Memory Clock rate:                             2000 Mhz
  Memory Bus Width:                              256-bit
  L2 Cache Size:                                 524288 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65535), 3D=(2048, 2048, 2048)
  Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 32768
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  1536
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (65535, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 1 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 2 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 8.0, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = GeForce GTX 460
Result = PASS

If you also install cuDNN sample you can test it by

cp -r /usr/src/cudnn_samples_v7/ $HOME
cd $HOME/cudnn_samples_v7/mnistCUDNN
make clean && make
./mnistCUDNN

And the result

cudnnGetVersion() : 7001 , CUDNN_VERSION from cudnn.h : 7001 (7.0.1)
Host compiler version : GCC 5.4.0
There are 1 CUDA capable devices on your machine :
device 0 : sms  7  Capabilities 2.1, SmClock 1550.0 Mhz, MemSize (Mb) 961, MemClock 2000.0 Mhz, Ecc=0, boardGroupID=0
Using device 0
Testing single precision
CUDNN failure
Error: CUDNN_STATUS_ARCH_MISMATCH
mnistCUDNN.cpp:394
Aborting...

My test fail because cudnn does not support CUDA arch 2.1 cards. The minimum supported CUDA arch is 3.0. As you can see in the result from cuda that my card GTX 460 is arch 2.1 so it cannot use cudnn but I still write about the instruction for someone who may have newer card.

Setup python (2.7)

apt-get install python-pip python-dev python-virtualenv
pip install --upgrade pip
pip install --upgrade tensorflow
# or for gpu
# pip install --upgrade tensorflow-gpu