ubuntu +cuda+tensorflow

install NVIDIA driver

install driver by apt-get (ref),with a VPN to turn over the GFW

sudo apt-get purge nvidia*
sudo add-apt-repository ppa:graphics-drivers
sudo apt-get update 
sudo apt-cache search nvidia
sudo apt-get install nvidia-396 

test driver

reboot
lsmod | grep nvidia 
lsmod | grep nouveau # no output
install cuda9.0

2. Install CUDA 9.0 (ref)

The CUDA runfile installer can be downloaded from NVIDIA's websie, or using wget in case you can't find it easily on NVIDIA:

cd
wget https://developer.nvidia.com/cuda-90-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1604&target_type=runfilelocal
chmod a+x cuda_*
./cuda_9.0.176_384.81_linux-run 

Follow the command-line prompts
finally,install patch as above

Please make sure that

  • PATH includes /usr/local/cuda-9.0/bin
  • LD_LIBRARY_PATH includes /usr/local/cuda-9.0/lib64, or, add /usr/local/cuda-9.0/lib64 to /etc/ld.so.conf and run ldconfig as root

add the script to ~/.bashrc

export PATH=$PATH:/usr/local/cuda-9.0/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-9.0/lib64

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-9.0/bin

Install cuDNN 7.0

The recommended way for installing cuDNN is by Installing from a Tar File

  1. Download the "cuDNN v7.0.5 Library for Linux" tgz file (need to register for an Nvidia account).
  • your CUDA directory path is referred to as
    /usr/local/cuda/
  • your cuDNN download path is referred to as
  1. Navigate to your directory containing the cuDNN Tar file.
    4, Unzip the cuDNN package.
tar -xzvf cudnn-9.0-linux-x64-v7.tgz
  1. Copy the following files into the CUDA Toolkit directory.
sudo cp cuda/include/cudnn.h /usr/local/cuda/include  
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64  
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
install tensorflow
  1. install anaconda and create env
conda create -n tensorflow_gpu
source activate tensorflow_gpu
  1. use pip to get the latest version of tensorflow-gpu
pip install  tensorflow-gpu

3.verify

from tensorflow.python.client import device_lib
device_lib.list_local_devices()

你可能感兴趣的:(ubuntu +cuda+tensorflow)