cuda9.1.sh-20180505-yuan
#!/bin/bash
# add variables
i1=0
if [ "$1" ]; then
i1=$1
fi
# add functions
function prompt()
{
read -p "$1 [YES/NO]: " input
}
# script name
function myecho0script()
{
echo
echo '==========================================================='
echo "$1"
echo '==========================================================='
echo
}
# task title
function myecho1task()
{
echo
if [ "$1" ]; then
# 蓝底白字
echo -e "\033[44;37m --> $i1. $1\033[0m"
fi
i1=$[$i1+1]
}
# things title
function myecho2thing()
{
echo
# 红色字
#echo -e "\033[31m - $1 \033[0m"
# 绿色字
echo -e "\033[32m - $1 \033[0m"
# 红底白字
#echo -e "\033[41;37m- $1\033[0m"
}
# steps title
function myecho3step()
{
echo
echo -e " * $1"
}
# reference title
function myecho4ref()
{
#echo
echo -e "\t$1"
}
# highlight title
function myechoy()
{
echo
# 黄底黑字
echo -e "\033[43;30m$1\033[0m"
#echo -e "\t\t$1"
}
# call outside script
function mysource()
{
(source $1 $i1)
i1=$[$i1+1]
}
# new chapter
myecho1task 'CUDA'
#-----------------------------------------------------------------
myecho2thing 'install Nvidia driver'
myecho3step 'remove old Nvidia driver'
#sudo apt-get purge nvidia*
myecho3step 'blacklist nouveau'
#cd /etc/modprobe.d/
#sudo sh -c "echo 'blacklist nouveau' >> blacklist-nouveau.conf"
#sudo sh -c "echo 'options nouveau modset=0' >> blacklist-nouveau.conf"
#cd -
#sudo update-initramfs -u
#lsmod | grep nouveau
myecho3step 'init 3 and installation'
#read -p 'Please enter console with ctrl+alt+F1, and then run this script again [YES/NO] '
#sudo service lightdm stop
# sudo init 3
#cd /home/xy2/tools/GPU/
#sudo ./NVIDIA-Linux-x86_64-390.48.run -no-x-check -no-nouveau-check -no-opengl-files
#cd -
#sudo service lightdm start
# lspci | grep -i nvidia
# sudo dpkg --list | grep nvidia-*
nvidia-smi
myecho2thing 'install CUDA'
myecho3step 'CUDA and patches'
# CUDA 8.0
#prompt '[Download...] https://developer.nvidia.com/cuda-80-ga2-download-archive'
# CUDA 9.1
#prompt '[Download...] https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1604&target_type=deblocal'
cd tools/
# CUDA base
#sudo dpkg -i cuda-repo-ubuntu1604-9-1-local_9.1.85-1_amd64.deb
#sudo apt-key add /var/cuda-repo-9-1-local/7fa2af80.pub
#sudo apt-get update
#sudo apt-get install cuda
# CUDA patch 1
#sudo dpkg -i cuda-repo-ubuntu1604-9-1-local-cublas-performance-update-1_1.0-1_amd64.deb
# CUDA patch 2
#sudo dpkg -i cuda-repo-ubuntu1604-9-1-local-compiler-update-1_1.0-1_amd64.deb
# CUDA patch 3
#sudo dpkg -i cuda-repo-ubuntu1604-9-1-local-cublas-performance-update-3_1.0-1_amd64.deb
# CUDA env setup
cd -
myecho2thing 'configurate CUDA'
myecho4ref 'https://developer.download.nvidia.com/compute/cuda/9.1/Prod/docs/sidebar/CUDA_Installation_Guide_Linux.pdf'
# ~/.bashrc
# way 1.
#echo 'export CUDA_HOME=/usr/local/cuda' | tee -a ~/.bashrc
#echo 'export PATH=$PATH:$CUDA_HOME/bin' | tee -a ~/.bashrc
#echo 'export LD_LIBRARY_PATH=$CUDA_HOME/lib64' | tee -a ~/.bashrc
# way 2.
envfile=~/.bashrc
#echo 'export PATH=/usr/local/cuda-9.1/bin${PATH:+:${PATH}}' | tee -a $envfile
#echo 'export LD_LIBRARY_PATH=/usr/local/cuda-9.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}' | tee -a $envfile
#source ~/.bashrc
# /etc/profile
#echo 'export PATH=/usr/local/cuda/bin:$PATH' | sudo tee -a /etc/profile
#echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64' | sudo tee -a /etc/profile
myecho4ref 'https://www.2cto.com/kf/201612/578337.html'
echo 'CUDA driver version'
cat /proc/driver/nvidia/version
echo
echo 'nvcc'
nvcc -V
echo
myecho4ref 'verify CUDA installation'
cd /usr/local/cuda/samples/1_Utilities/deviceQuery #由自己电脑目录决定
sudo make clean
sudo make
sudo ./deviceQuery
cd -
myecho2thing 'CUDA cuDNN (nvcc)'
myecho4ref 'https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html'
cd tools/
# way 1
#cp cudnn-9.1-linux-x64-v7.1.solitairetheme8 cudnn-9.1-linux-x64-v7.1.tgz
#tar -xvf cudnn-9.1-linux-x64-v7.1.tgz
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
echo 'libcudnn'
echo '/usr/local/cuda/lib64/libcudnn'
#/usr/local/cuda/lib64/libcudnn*
# way 2
# sudo dpkg -i libcudnn7_7.1.3.16-1+cuda9.1_amd64.deb
# sudo dpkg -i libcudnn7-dev_7.1.3.16-1+cuda9.1_amd64.deb
# sudo dpkg -i libcudnn7-doc_7.1.3.16-1+cuda9.1_amd64.deb
cd -
sudo ln -s /usr/local/cuda/lib64/libcudart.so.9.1.85 /usr/local/cuda/lib64/libcudart.so.7.5
echo
#echo '==========================================================='
echo 'End'