0


【Ubuntu 20.04LTS系统】安装CUDA11.8、cuDNN,可进行CUDA版本切换

Ubuntu 20.04LTS系统安装CUDA11.8、cuDNN,可进行CUDA版本切换

1. 更改为清华源并更新软件列表和依赖项

https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse

更新软件列表和必要的依赖项

sudoapt-get update        # 更新软件列表sudoapt-getinstall g++        # 下载g++编译器sudoapt-getinstall gcc        # 下载gcc编译器sudoapt-getinstallmake# 下载GNU Make编译器sudoapt-getinstall initramfs-tools   # 下载安装initramfs-tools

2. 安装CUDA

步骤一: 下载CUDA安装包

wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
sudo sh cuda_11.8.0_520.61.05_linux.run

步骤二: 安装CUDA安装包过程中的选择

  • Do you accept the above EULA? (accept / decline / quit): 是否接受最终用户许可协议,输入accept在这里插入图片描述
  • 回车键进行勾选,X就是选中,没有X就是没有选中,把安装驱动进行取消。之后向下键,回车确认在这里插入图片描述
  • 最后点击 install
  • 出现了警告信息,对安装无影响在这里插入图片描述

截图日志:

wit622@622:~/cuda$ sudosh cuda_11.8.0_520.61.05_linux.run
[sudo] wit622 的密码: 
============ Summary ============

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-11.8/

Please make sure that
 -   PATH includes /usr/local/cuda-11.8/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-11.8/lib64, or, add /usr/local/cuda-11.8/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.8/bin
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 520.00 is required for CUDA 11.8 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
    sudo<CudaInstaller>.run --silent--driver

Logfile is /var/log/cuda-installer.log

也可以进入日志进行查看(位置如下):

 /var/log/cuda-installer.log

步骤三: 配置CUDA环境

sudo  vim ~/.bashrc
  • 在bashrc文件最下方,添加下入代码
  • (ps:这边需要注意cuda的版本,版本不同,路径的命名需修改)
export PATH=$PATH:/usr/local/cuda-11.8/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.8/lib64
  • 更新环境
source ~/.bashrc
  • 测试CUDA是否安装成功
nvcc -V

输出下述结果,表示安装成功:

wit622@622:~/cuda$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c)2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0

3. 安装cuDNN

步骤一:下载cuDNN包

https://developer.nvidia.com/rdp/cudnn-archive

  • 例如这边选择了Download cuDNN v8.8.1 (March 8th, 2023), for CUDA 11.x
  • 点击Local Installer for Linux x86_64 (Tar)即可下载压缩包在这里插入图片描述
  • 将压缩包,放入自定义路径后,输入命令进行解压
tar-xvf cudnn-linux-x86_64-8.8.1.3_cuda11-archive.tar.xz 
  • 解压后,输入命令,讲cuDNN对应文件拷贝至CUDA指定路径。
wit622@622:~/下载$ cd cudnn-linux-x86_64-8.8.1.3_cuda11-archive/
wit622@622:~/下载/cudnn-linux-x86_64-8.8.1.3_cuda11-archive$ ls
include  lib  LICENSE
sudocp include/cudnn*.h /usr/local/cuda-11.8/include
sudocp lib/libcudnn* /usr/local/cuda-11.8/lib64
sudochmod a+r /usr/local/cuda-11.8/include/cudnn*.h /usr/local/cuda-11.8/lib64/libcudnn*

4. CUDA版本切换

因为后续部分项目,用的库对应的CUDA不同,无需进行修改,修改环境CUDA路径即可。例如需要11.1的CUDA,可通过修改bashrc进行修改

sudovim ~/.bashrc

将原先的cuda-11.8注释掉,添加cuda-11.1新的环境设置,即可

# cuda-11.8# export PATH=$PATH:/usr/local/cuda-11.8/bin# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.8/lib64# cuda-11.1exportPATH=$PATH:/usr/local/cuda-11.1/bin
exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.1/lib64
标签: ubuntu linux

本文转载自: https://blog.csdn.net/w946612410/article/details/131786512
版权归原作者 aglo 所有, 如有侵权,请联系我们删除。

“【Ubuntu 20.04LTS系统】安装CUDA11.8、cuDNN,可进行CUDA版本切换”的评论:

还没有评论