ubuntu20.04安装/重装 cuda11.4、cudnn
慎重安装最新版的cuda吧,看看当前版本的pytorch和tensorflow支不支持最新的cuda,最好选个两个都支持的cuda版本,安装流程是一样的
1.检查自己电脑支持的cuda
lhw@lhw-Dell-G15-5511:~$ nvidia-smi Wed Oct 20 00:00:21 2021 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 470.63.01 Driver Version: 470.63.01 CUDA Version: 11.4 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |===============================+======================+======================| | 0 NVIDIA GeForce ... Off | 00000000:01:00.0 On | N/A | | N/A 49C P8 16W / N/A | 633MiB / 5938MiB | 16% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | 0 N/A N/A 988 G /usr/lib/xorg/Xorg 35MiB | | 0 N/A N/A 1586 G /usr/lib/xorg/Xorg 345MiB | | 0 N/A N/A 1724 G /usr/bin/gnome-shell 57MiB | | 0 N/A N/A 164717 G ...AAAAAAAAA= --shared-files 144MiB | | 0 N/A N/A 164726 G ...AAAAAAAAA= --shared-files 38MiB | +-----------------------------------------------------------------------------+
显示支持的cuda版本为11.4
查看显卡算力地址
2.去nvidia官网下载最新的cuda11.4.2
wget https://developer.download.nvidia.com/compute/cuda/11.4.2/local_installers/cuda_11.4.2_470.57.02_linux.run sudo sh cuda_11.4.2_470.57.02_linux.run
出来提示后,依次操作(如果已经安装了NVIDIA驱动就把第一项的x驱动安装去掉)
1.是否接受EULA? 输入accept 2.cuda安装? 选择不安装驱动,其他默认安装install 直至安装完成
添加环境变量:
gedit ~/.bashrc # 文本最后添加以下内容: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64 export PATH=$PATH:/usr/local/cuda/bin export CUDA_HOME=$CUDA_HOME:/usr/local/cuda # 保存退出,打开新终端激活 source ~/.bashrc
测试CUda
cd /usr/local/cuda/samples/1_Utilities/deviceQuery sudo make -j4 ./deviceQuery
显示结果:
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.4, CUDA Runtime Version = 11.4, NumDevs = 1 Result = PASS
3.安装cuDNN
去官网注册账号登录下载cuDNN
cuDNN Library for Linux (x86_64)
下载后解压复制
tar zxvf cudnn-11.4-linux-x64-v8.2.4.15.tgz
sudo cp cuda/include/cudnn* /usr/local/cuda/include sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 sudo chmod a+r /usr/local/cuda/include/cudnn* /usr/local/cuda/lib64/libcudnn*
查询版本号
cat cuda/include/cudnn_version.h |grep ^# #ifndef CUDNN_VERSION_H_ #define CUDNN_VERSION_H_ #define CUDNN_MAJOR 8 #define CUDNN_MINOR 2 #define CUDNN_PATCHLEVEL 4 #define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL) #endif /* CUDNN_VERSION_H */
4. cuda 卸载
sudo apt autoremove cuda
cd /usr/local/cuda/bin/ sudo ./cuda-uninstaller # 选中所有cuda相关选项 sudo rm -rf /usr/local/cuda-11.0 sudo rm -rf /usr/local/cuda
5. cudnn卸载
sudo rm -rf /usr/local/cuda/include/cudnn.h sudo rm -rf /usr/local/cuda/lib64/libcudnn*