Ubuntu18.04安装完应该做的一些事 显卡驱动安装和cuda8.0
程序员文章站
2024-01-22 16:38:10
博主装Ubuntu18.04主要是为了用于跑深度学习,所以我们先来搞搞gcc环境 第一步:安装多版本gcc、g++可切换 切换版本命令 根据自己想要的环境选择 第二步:准备安装显卡驱动和cuda8.0等相关文件 最新cuda8.0 及其补丁 cuda_8.0.61.2_linux.run cuda_ ......
博主装ubuntu18.04主要是为了用于跑深度学习,所以我们先来搞搞gcc环境
第一步:安装多版本gcc、g++可切换
sudo apt-get install gcc-4.8 gcc-4.8-multilib sudo apt-get install g++-4.8 g++-4.8-multilib sudo apt-get install gcc-5 gcc-5-multilib sudo apt-get install g++-5 g++-5-multilib sudo apt-get install gcc-6 gcc-6-multilib sudo apt-get install g++-6 g++-6-multilib sudo apt-get install gcc-7 gcc-7-multilib sudo apt-get install g++-7 g++-7-multilib sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 48 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 48 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 50 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 60 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 70
切换版本命令
sudo update-alternatives --config gcc sudo update-alternatives --config g++
根据自己想要的环境选择
第二步:准备安装显卡驱动和cuda8.0等相关文件
最新cuda8.0 及其补丁
cuda_8.0.61.2_linux.run
cuda_8.0.61_375.26_linux.run
最新支持cuda8.0的cudnn
libcudnn7_7.1.4.18-1+cuda8.0_amd64.deb
libcudnn7-dev_7.1.4.18-1+cuda8.0_amd64.deb
libcudnn7-doc_7.1.4.18-1+cuda8.0_amd64.deb
cuda8.0 安装包解压文件
/001/installutils.pm(从cuda_8.0.61.2_linux.run中解压出来的文件,后面会讲到)
第三步:安装显卡驱动
第三步:安装显卡驱动
-
1、开机 nomodeset 进入系统
-
开机进引导界面 第一项 按e 进入配置启动
-
在quiet splash - - -后加上 nomodeset
- 按f10 保存 进入系统
quiet splash - - - quiet splash nomodeset
- 2、禁用系统自带nvidia驱动
sudo vim /etc/modprobe.d/blacklist.conf # 在文件尾加入 blacklist nouveau options nouveau modeset=0 # 保存并退出 执行下面命令 更新引导 sudo update-initramfs –u
- 3、安装 nvidia 驱动
# 切换gcc 版本 到gcc-5 以上 (使用高版本感觉会好一点) # 查看支持的驱动版本 ubuntu-drivers devices # 安装驱动 sudo ubuntu-drivers autoinstall # 根据查询的版本安装比较保险 例如 sudo apt-get install nvidia-driver-390 # 装驱动 需要关闭 安全启动
- 5、重启系统
sudo reboot # 查看nvidia驱动 使用情况 nvidia-smi
- 6、安装cuda8.0
- 安装依赖
-
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
- 切换gcc版本到 4.8
-
sudo update-alternatives --config gcc
- 解压cuda8.0
-
sh cuda_8.0.61_375.26_linux.run --noexec --target 001 # 将runfile文件解压并且放到001文件夹中 # 将instalutil.pm 拷贝到 /etc/perl/ sudo cp instalutil.pm /etc/perl/
- 安装cuda8.0及补丁
-
# 可选 加运行权限 chmod u+x cuda_8.0.61_375.26_linux.run chmod u+x cuda_8.0.61.2_linux.run # 运行 sudo ./chmod u+x cuda_8.0.61_375.26_linux.run do you accept the previously read eula? accept/decline/quit: accept you are attempting to install on an unsupported configuration. do you wish to continue? (y)es/(n)o [ default is no ]: y install nvidia accelerated graphics driver for linux-x86_64 375.26? (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/deep ]: # 安装补丁 sudo ./cuda_8.0.61.2_linux.run
- 添加环境变量
-
cd vim .bashrc # 添加到文件尾部 export path=/usr/local/cuda-8.0/bin:$path export ld_library_path=/usr/local/cuda-8.0/lib64$ld_library_path # 保存 退出 sudo su source .bashrc
- 重启系统
-
sudo reboot
- 安装cudnn
-
sudo dpkg -i libcudnn7_7.1.4.18-1+cuda8.0_amd64.deb sudo dpkg -i libcudnn7-dev_7.1.4.18-1+cuda8.0_amd64.deb sudo dpkg -i libcudnn7-doc_7.1.4.18-1+cuda8.0_amd64.deb
- 查看cuda版本和cudnn版本
-
# cuda 版本 cat /usr/local/cuda/version.txt # cudnn 版本 cat /usr/include/x86_64-linux-gnu/cudnn_v7.h | grep cudnn_major -a 2
- 编译
-
# 不用编译全部 只编译devicequery cd /home/deep/nvidia_cuda-8.0_samples/1_utilities/devicequery make
- 测试
-
./devicequery # 出现显卡信息 ./devicequery starting... cuda device query (runtime api) version (cudart static linking) detected 1 cuda capable device(s) device 0: "geforce gtx 1080" cuda driver version / runtime version 9.1 / 8.0 cuda capability major/minor version number: 6.1 total amount of global memory: 8116 mbytes (8510701568 bytes) (20) multiprocessors, (128) cuda cores/mp: 2560 cuda cores gpu max clock rate: 1734 mhz (1.73 ghz) memory clock rate: 5005 mhz memory bus width: 256-bit l2 cache size: 2097152 bytes maximum texture dimension size (x,y,z) 1d=(131072), 2d=(131072, 65536), 3d=(16384, 16384, 16384) maximum layered 1d texture size, (num) layers 1d=(32768), 2048 layers maximum layered 2d texture size, (num) layers 2d=(32768, 32768), 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: 65536 warp size: 32 maximum number of threads per multiprocessor: 2048 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): (2147483647, 65535, 65535) maximum memory pitch: 2147483647 bytes texture alignment: 512 bytes concurrent copy and kernel execution: yes with 2 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 / 1 / 0 compute mode: < default (multiple host threads can use ::cudasetdevice() with device simultaneously) > devicequery, cuda driver = cudart, cuda driver version = 9.1, cuda runtime version = 8.0, numdevs = 1, device0 = geforce gtx 1080 result = pass
如果出现相应的显卡信息表示安装成功了。