Linux搭建深度学习环境
一、独显
二、下载显卡驱动
https://www.nvidia.cn/Download/index.aspx?lang=cn
三、安装显卡驱动
1、卸载原有的驱动
sudo apt-get remove --purge nvidia*
2、禁用nouveau
sudo gedit /etc/modprobe.d/blacklist.conf
在文本最后添加以下内容
blacklist nouveau
options nouveau modeset=0
3、保存退出,执行命令使其生效
sudo update-initramfs -u
4、重启电脑
5、执行命令没有任何输出则说明禁用成功
lsmod | grep nouveau
6、将安装包放到Home里面
7、停掉linux图形界面的服务
sudo service lightdm stop
8、按ctrl+alt+f1切换到纯控制台界面
9、进入Home
cd ~
10、给驱动赋可执行权限
sudo chmod a+x NVIDIA-Linux-xxx.run
11、安装
sudo ./NVIDIA-Linux-xxx.run -no-opengl-files
(提示安装基本上都是accept, yes, 当提示你nvidia-xconfig时,如果有双显卡就选择不安装,如果单显卡就选择安装)
12、检验是否安装成功
nvidia-smi
13、启用图形界面
sudo service lightdm start
14、按ctrl+alt+f7切换回图形界面
三、安装cuda
1、下载cuda
https://developer.nvidia.com/cuda-downloads
2、查看nouveau是否禁用成功
lsmod | grep nouveau
3、给文件赋予可执行权限
sudo chmod a+x cuda_xxxx.run
4、安装cuda
sudo ./cuda_xxx.run --no-opengl-libs
安装步骤
Do you accept the previously read EULA?
accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 361.62?
(y)es/(n)o/(q)uit: n
Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: y
Enter Toolkit Location
[ default is /usr/local/cuda-8.0 ]:(直接回车)
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y
Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y
Enter CUDA Samples Location
[ default is /home/tang]:(直接回车)
5、配置环境变量
export PATH=
$PATH:
/usr/local/cuda_xxx/bin
export LD_LIBRARY_PATH=
$LD_LIBRARY_PATH
:/usr/local/cuda_xxx/lib64
6、使配置生效
source ~/.bashrc
7、验证CUDA Toolkit
nvcc -V
四、配置cudnn
1、下载cudnn
https://developer.nvidia.com/rdp/form/cudnn-download-survey
2、解压cudnn
cp cudnn_xxx-linux-x64.solitairetheme8 cudnn_xxx-linux-x64.tgz
tar -xvf cudnn_xxx-linux-x64.tgz
3、将cudnn复制到对应的文件夹内
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*
五、卸载显卡驱动
sudo apt-get remove --purge nvidia*
六、卸载cuda
1、执行卸载脚本
sudo /usr/local/cuda_xxx/bin/uninstall_cuda_xxx.pl
2、删除残留的文件夹
sudo rm -rf /usr/local/cuda_xxx/
参考文献:
https://github.com/karentwan/document/blob/master/deep%20learning%20install.md