Ubuntu之cuda安装及历史版本安装

一、cuda简介

  NVIDIA CUDA工具包提供了开发环境,可供创建经 GPU 加速的高性能应用。借助 CUDA 工具包,您可以在经 GPU 加速的嵌入式系统、台式工作站、企业数据中心、基于云的平台和 HPC 超级计算机中开发、优化和部署应用。此工具包中包含多个 GPU 加速库、多种调试和优化工具、一个 C/C++ 编译器以及一个用于在主要架构(包括 x86、Arm 和 POWER)上构建和部署应用的运行时库。借助多 GPU 配置中用于分布式计算的多项内置功能,科学家和研究人员能够开发出可从单个 GPU 工作站扩展到配置数千个 GPU 的云端设施的应用。本博文示例安装在Ubuntu18.04系统下安装cuda11.4,官网查看安装要求如下:
在这里插入图片描述

二、安装步骤

0、检查是否安装显卡驱动

root@testuat:/opt# cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module 470.57.02 Tue Jul 13 16:14:05 UTC 2021
GCC version: gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)

1、验证系统是否具有支持CUDA的GPU在这里插入图片描述

2、验证系统是否运行受支持的Linux版本

root@testuat:/opt# uname -m && cat /etc/*release
x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION=“Ubuntu 18.04.5 LTS”
NAME=“Ubuntu”
VERSION=“18.04.5 LTS (Bionic Beaver)”
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME=“Ubuntu 18.04.5 LTS”
VERSION_ID=“18.04”
HOME_URL=“https://www.ubuntu.com/”
SUPPORT_URL=“https://help.ubuntu.com/”
BUG_REPORT_URL=“https://bugs.launchpad.net/ubuntu/”
PRIVACY_POLICY_URL=“https://www.ubuntu.com/legal/terms-and-policies/privacy-policy”
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

3、验证系统是否已安装gcc

root@testuat:/opt# gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright © 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

4、验证系统是否安装了正确的内核头和开发包

root@testuat:/opt# sudo apt-get install linux-headers-$(uname -r)
正在读取软件包列表… 完成
正在分析软件包的依赖关系树
正在读取状态信息… 完成
linux-headers-5.4.0-81-generic 已经是最新版 (5.4.0-81.91~18.04.1)。

5、选择英伟达cuda工具包版本

根据系统环境官网选择英伟达cuda工具包
在这里插入图片描述

6、下载cuda pin文件

root@testuat:/opt# wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin

7、cuda pin文件移到apt配置目录下

root@testuat:/opt# mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600

8、下载cuda-repo deb软件包

root@testuat:/opt# wget https://developer.download.nvidia.com/compute/cuda/11.4.1/local_installers/cuda-repo-ubuntu1804-11-4-local_11.4.1-470.57.02-1_amd64.deb

9、安装cuda-repo软件包

root@testuat:/opt# sudo dpkg -i cuda-repo-ubuntu1804-11-4-local_11.4.1-470.57.02-1_amd64.deb
正在选中未选择的软件包 cuda-repo-ubuntu1804-11-4-local。
(正在读取数据库 … 系统当前共安装有 214569 个文件和目录。)
正准备解包 cuda-repo-ubuntu1804-11-4-local_11.4.1-470.57.02-1_amd64.deb …
正在解包 cuda-repo-ubuntu1804-11-4-local (11.4.1-470.57.02-1) …
正在设置 cuda-repo-ubuntu1804-11-4-local (11.4.1-470.57.02-1) …

10、添加cuda-repo密钥

root@testuat:/opt# sudo apt-key add /var/cuda-repo-ubuntu1804-11-4-local/7fa2af80.pub
OK

11、更新软件列表

root@testuat:/opt# sudo apt-get update

12、安装cuda最新版本

当前最新版本为11.4.1
root@testuat:/opt# sudo apt-get -y install cuda

update-initramfs: Generating /boot/initrd.img-5.4.0-81-generic
正在处理用于 libc-bin (2.27-3ubuntu1.4) 的触发器 …
正在处理用于 man-db (2.8.3-2ubuntu0.1) 的触发器 …

13、查看GPU状态

nvidia-smi命令可以安装cuda之前执行,可以看到显卡驱动对应支持的cuda版本为11.4,如果安装其他版本nvidia-smi命令执行会报错mismatch。
root@vanfonuat:/opt# nvidia-smi
在这里插入图片描述

14、检验是否安装成功

root@testuat:/opt# cd /usr/local/cuda/samples/1_Utilities/deviceQuery
root@vanfonuat:/usr/local/cuda/samples/1_Utilities/deviceQuery# sudo make

e release (Use -Wno-deprecated-gpu-targets to suppress warning).
mkdir -p …/…/bin/x86_64/linux/release
cp deviceQuery …/…/bin/x86_64/linux/release

root@testuat:/usr/local/cuda/samples/1_Utilities/deviceQuery# ./deviceQuery
在这里插入图片描述

15、配置环境变量

(base) vanfon@testuat:~$ vim ~/.bashrc
添加如下两行到最下面
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
保存后退出

16、使环境变量生效

(base) vanfon@testuat:~$ source ~/.bashrc

17、检查cuda版本

(base) vanfon@testuat:~$ nvcc -V
nvcc: NVIDIA ® Cuda compiler driver
Copyright © 2005-2021 NVIDIA Corporation
Built on Wed_Jul_14_19:41:19_PDT_2021
Cuda compilation tools, release 11.4, V11.4.100
Build cuda_11.4.r11.4/compiler.30188945_0

18、配置 /etc/ld.so.conf.d/cuda.conf

root@testuat:/usr/local/cuda# cd /etc/ld.so.conf.d/
root@testuat:/etc/ld.so.conf.d# vim cuda.conf
#添加如下内容
/usr/local/cuda/lib64

19、使库生效

root@testuat:/etc/ld.so.conf.d# sudo ldconfig

20、cuda安装完成

三、安装指定版本

1、选择安装历史版本

  在步骤5的链接中下拉到最后,点击Archive of Previous CUDA Releases,进入历史版本列表。
在这里插入图片描述

2、选择版本

  访问链接https://developer.nvidia.com/cuda-toolkit-archive,进入历史版本选择,点击需要安装的历史版本。
在这里插入图片描述

3、获取版本及安装步骤

  剩余安装步骤跟上一章节是一样的,一步步选择系统架构、操作系统版本、安装方式可以获取到安装步骤。如下以x86架构、Ubuntu操作系统、runfile(local)安装方式为例,安装11.6.2版本。

wuhs@jqxxpc:~$ wget https://developer.download.nvidia.com/compute/cuda/11.6.2/local_installers/cuda_11.6.2_510.47.03_linux.run

bdsc@jqxxpc:~$ sudo sh cuda_11.6.2_510.47.03_linux.run

4、添加执行权限

wuhs@jqxxpc:~$ chmod u+x cuda_11.6.2_510.47.03_linux.run

5、执行安装脚本

wuhs@jqxxpc:~$ sudo sh cuda_11.6.2_510.47.03_linux.run

6、接受licence

在这里插入图片描述

7、选择Install开始安装

在这里插入图片描述

8、安装完成

在这里插入图片描述

9、添加环境变量

wuhs@jqxxpc:/usr/local$ vim ~/.bashrc
#添加cuda环境变量
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
(base) bdsc@jqxxpc:/usr/local$ source ~/.bashrc

10、验证版本

wuhs@jqxxpc:~$ nvcc -V
nvcc: NVIDIA ® Cuda compiler driver
Copyright © 2005-2022 NVIDIA Corporation
Built on Tue_Mar__8_18:18:20_PST_2022
Cuda compilation tools, release 11.6, V11.6.124
Build cuda_11.6.r11.6/compiler.31057947_0

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

恒悦sunsite

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值