安装cuda
下载cuda
根据版本对应关系,选择cuda9.0 在官网下载对应版本cuda,如果像我一样版本太老,可以在这里找之前的版本
安装cuda
安装依赖库
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-devlibgl1-mesa-glx libglu1
【libxi-devlibgl1-mesa-glx无法安装】 如果出现无法定位软件包的问题,可以采取的措施: 打开sources.list
sudo vim /etc/apt/sources.list
按a进入编辑模式,开始添加。添加国内源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
在sources.list文末添加
deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse
按esc退出编辑模式,按:wq保存并退出 添加后更新
sudo apt-get update
sudo apt upgrade
安装执行文件
sudo sh cuda_9.0.176_384.81_linux.run
注意,讯问是否安装驱动时回答n
设置环境变量
sudo vim ~/.bashrc
在文末添加
export PATH=/usr/local/cuda-9.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH
export CUDA_HOME=/usr/local/cuda
保存并退出后执行
sudo source ~/.bashrc
sudo ldconfig
使用nvcc -V 检查是否装好
测试sample
cd /usr/local/cuda-9.0/samples
sudo make -j
warning不用管,编译完成后
cd ./bin/x86_64/linux/release
./deviceQuery
出现Result=PASS的就算成功
安装cudnn
下载cudnn
找到适合你的cudnn https://developer.nvidia.com/rdp/cudnn-archive#a-collapse7415-10 如果你后需要下载tensorflow,最好还要参照一下这张表
安装cudnn
下载好以后解压
tar -zxvf cudnn-9.0-linux-x64-v7.1.tgz
cd cuda
sudo cp /include/cudnn.h /usr/local/cuda/include/
sudo cp lib* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.7
sudo ln -s libcudnn.so.7.0.2 libcudnn.so.7
sudo ln -s libcudnn.so.7 libcudnn.so
sudo ldconfig -v
验证cudnn是否装好
https://developer.nvidia.com/rdp/cudnn-archive 找到对应版本的code samples 用下面的命令提取deb文件
ar -x libcudnn7-doc_7.1.4.18-1+cuda9.0_amd64.deb
xz -d data.tar.xz
tar xvf data.tar
到解压目录的mnistCUDNN,在终端打开
make
./mnistCUDNN
看到下图输出说明cudnn装好了
|