ubuntu18.04/20.04cv环境配置(上):cuda11.1+cudnn安装配置(代码片段)

TechblogofHaoWANG TechblogofHaoWANG     2023-03-19     112

关键词:

 

 

目录

1. 版本对应

查看CUDA版本与NVIDIA驱动的关系

2. 下载安装

2.1 下载CUDA文件

Download Installer for Linux Ubuntu 20.04 x86_64

2.2 下载cudnn文件

3. 配置测试

参考连接:


1. 版本对应

无论采用哪一种方式,首先都需要更新 Ubuntu 软件源和升级到最新版本的软件包。由于国内从 Ubuntu 官方软件源下载速度比较慢,所以,建议采用国内 Ubuntu 镜像源,比如阿里 Ubuntu 软件源清华大学 Ubuntu 软件源。具体的配置方式是修改配置文件 /etc/apt/sources.list,将其中的 archive.ubuntu.com 替换为 mirrors.alibaba.com 或 mirrors.tuna.tsinghua.edu.cn 。也可以在图形界面应用 "Software & Update" 中,修改 Ubuntu Software 标签页中的 Download from 后的软件源地址。

配置软件源后,采用如下命令进行软件源的更新和软件包的升级。

sudo apt update

查看CUDA版本与NVIDIA驱动的关系


也可以到官网查看,点击查看链接https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html

2. 下载安装

2.1 下载CUDA文件

CUDA Toolkit 11.1 Update 1 Downloads | NVIDIA Developerhttps://developer.nvidia.com/cuda-11.1.1-download-archive?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=runfilelocal

 

Download Installer for Linux Ubuntu 20.04 x86_64

The base installer is available for download below.

 Base Installer
Installation Instructions:
wget https://developer.download.nvidia.com/compute/cuda/11.1.1/local_installers/cuda_11.1.1_455.32.00_linux.run

sudo sh cuda_11.1.1_455.32.00_linux.run

The CUDA Toolkit contains Open-Source Software. The source code can be found here.

  • 打开主目录下的 .bashrc文件添加如下路径,.bashrc文件在/home下,如果没有找到,则按Ctrl+H键显示隐藏文件。将以下命令添加至文件末尾,保存退出。
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 驱动,安装记录如下:

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-11.0/
Samples:  Installed in /home/klchang/, but missing recommended libraries

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

To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.0/bin
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least .00 is required for CUDA 11.0 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

安装结束后,添加环境变量到 ~/.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

保存后退出。

在 Terminal 中,激活环境变量命令为 source ~/.bashrc 

注:上述命令中的cuda也可以改为cuda11.1,因为在系统目录中有cuda和cuda11.1两个文件夹,其中cuda文件夹是cuda11.1的链接,二者内容相同。

  • 检查:nvcc -V,查看cuda是否正确安装

 

2.2 下载cudnn文件

sudo cp cudnn-11.1-linux-x64-v8.0.4.30.solitairetheme8 cudnn-11.1-linux-x64-v8.0.4.30.tgz
tar -xzvf cudnn-11.1-linux-x64-v8.0.4.30.tgz
sudo cp cuda/include/* /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*

注:此处必须使用sudo cp cuda/include/* /usr/local/cuda/include/,而不是sudo cp cuda/include/cudnn.h /usr/local/cuda/include/

3. 配置测试

测试 CUDA Toolkit 。 通过编译自带 Samples并执行, 以验证是否安装成功。具体命令如下所示:

cd /usr/local/cuda/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery

如果安装成功,则输出类似于如下信息:

3块 "NVIDIA A100 80GB PCIe"显卡,豪华套装

./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 3 CUDA Capable device(s)

Device 0: "NVIDIA A100 80GB PCIe"
  CUDA Driver Version / Runtime Version          11.6 / 11.1
  CUDA Capability Major/Minor version number:    8.0
  Total amount of global memory:                 81070 MBytes (85007794176 bytes)
  (108) Multiprocessors, ( 64) CUDA Cores/MP:     6912 CUDA Cores
  GPU Max Clock rate:                            1410 MHz (1.41 GHz)
  Memory Clock rate:                             1512 Mhz
  Memory Bus Width:                              5120-bit
  L2 Cache Size:                                 41943040 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 shared memory per multiprocessor:        167936 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 3 copy engine(s)
  Run time limit on kernels:                     No
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Enabled
  Device supports Unified Addressing (UVA):      Yes
  Device supports Managed Memory:                Yes
  Device supports Compute Preemption:            Yes
  Supports Cooperative Kernel Launch:            Yes
  Supports MultiDevice Co-op Kernel Launch:      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 33 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

Device 1: "NVIDIA A100 80GB PCIe"
  CUDA Driver Version / Runtime Version          11.6 / 11.1
  CUDA Capability Major/Minor version number:    8.0
  Total amount of global memory:                 81070 MBytes (85007794176 bytes)
  (108) Multiprocessors, ( 64) CUDA Cores/MP:     6912 CUDA Cores
  GPU Max Clock rate:                            1410 MHz (1.41 GHz)
  Memory Clock rate:                             1512 Mhz
  Memory Bus Width:                              5120-bit
  L2 Cache Size:                                 41943040 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 shared memory per multiprocessor:        167936 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 3 copy engine(s)
  Run time limit on kernels:                     No
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Enabled
  Device supports Unified Addressing (UVA):      Yes
  Device supports Managed Memory:                Yes
  Device supports Compute Preemption:            Yes
  Supports Cooperative Kernel Launch:            Yes
  Supports MultiDevice Co-op Kernel Launch:      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 129 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

Device 2: "NVIDIA A100 80GB PCIe"
  CUDA Driver Version / Runtime Version          11.6 / 11.1
  CUDA Capability Major/Minor version number:    8.0
  Total amount of global memory:                 81070 MBytes (85007794176 bytes)
  (108) Multiprocessors, ( 64) CUDA Cores/MP:     6912 CUDA Cores
  GPU Max Clock rate:                            1410 MHz (1.41 GHz)
  Memory Clock rate:                             1512 Mhz
  Memory Bus Width:                              5120-bit
  L2 Cache Size:                                 41943040 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 shared memory per multiprocessor:        167936 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 3 copy engine(s)
  Run time limit on kernels:                     No
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Enabled
  Device supports Unified Addressing (UVA):      Yes
  Device supports Managed Memory:                Yes
  Device supports Compute Preemption:            Yes
  Supports Cooperative Kernel Launch:            Yes
  Supports MultiDevice Co-op Kernel Launch:      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 226 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
> Peer access from NVIDIA A100 80GB PCIe (GPU0) -> NVIDIA A100 80GB PCIe (GPU1) : Yes
> Peer access from NVIDIA A100 80GB PCIe (GPU0) -> NVIDIA A100 80GB PCIe (GPU2) : Yes
> Peer access from NVIDIA A100 80GB PCIe (GPU1) -> NVIDIA A100 80GB PCIe (GPU0) : Yes
> Peer access from NVIDIA A100 80GB PCIe (GPU1) -> NVIDIA A100 80GB PCIe (GPU2) : Yes
> Peer access from NVIDIA A100 80GB PCIe (GPU2) -> NVIDIA A100 80GB PCIe (GPU0) : Yes
> Peer access from NVIDIA A100 80GB PCIe (GPU2) -> NVIDIA A100 80GB PCIe (GPU1) : Yes

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.6, CUDA Runtime Version = 11.1, NumDevs = 3
Result = PASS

 

参考连接:

Ubuntu 20.04 安装 CUDA Toolkit 的三种方式 - klchang - 博客园

Linux安装CUDA的正确姿势[通俗易懂] - 全栈程序员必看

cuda11.1 + cuDNN v8.0.4 for CUDA 11.1 配置流程 - 知乎

ubuntu18.04/20.04cv环境配置(中):tensorrt+pytorch安装配置(代码片段)

Ubuntu18.04/20.04CV环境配置(上):CUDA11.1+cudnn安装配置_TechblogofHaoWANG的博客-CSDN博客Ubuntu18.0420.04NVIDIACUDA环境配置与cudnnTensorrt等配置与使用https://blog.csdn.net/hhaowang/article/details/125803582?spm=1001.2014.3001.5501目录TensorRT的... 查看详情

ubuntu18.04/20.04cv环境配置(中):tensorrt+pytorch安装配置(代码片段)

Ubuntu18.04/20.04CV环境配置(上):CUDA11.1+cudnn安装配置_TechblogofHaoWANG的博客-CSDN博客Ubuntu18.0420.04NVIDIACUDA环境配置与cudnnTensorrt等配置与使用https://blog.csdn.net/hhaowang/article/details/125803582?spm=1001.2014.3001.5501目录TensorRT的... 查看详情

ubuntu18.04/20.04cv环境配置(下)--手势识别trtpose+kinectdk人体骨骼识别(代码片段)

https://github.com/Alex1114/TRT-Pose-ROShttps://github.com/Alex1114/TRT-Pose-ROSGitHub-NVIDIA-AI-IOT/trt_pose:Real-timeposeestimationacceleratedwithNVIDIATensorRTReal-timeposeestimationacceleratedwith 查看详情

ubuntu18.04/20.04cv环境配置(下)--手势识别trtpose+kinectdk人体骨骼识别(代码片段)

https://github.com/Alex1114/TRT-Pose-ROShttps://github.com/Alex1114/TRT-Pose-ROSGitHub-NVIDIA-AI-IOT/trt_pose:Real-timeposeestimationacceleratedwithNVIDIATensorRTReal-timeposeestimationacceleratedwith 查看详情

ubuntu18.04/20.04cv环境配置(上):cuda11.1+cudnn安装配置(代码片段)

...驱动的关系2.下载安装2.1 下载CUDA文件DownloadInstallerforLinuxUbuntu20.04x86_642.2下载cudnn文件3.配置测试参考连接:1.版本对应无论采用哪一种方式,首先都需要更新Ubuntu软件源和升级到最新版本的软件包。由于国内从Ubuntu官方软... 查看详情

ubuntu18.04/20.04cv环境配置(上):cuda11.1+cudnn安装配置(代码片段)

...驱动的关系2.下载安装2.1 下载CUDA文件DownloadInstallerforLinuxUbuntu20.04x86_642.2下载cudnn文件3.配置测试参考连接:1.版本对应无论采用哪一种方式,首先都需要更新Ubuntu软件源和升级到最新版本的软件包。由于国内从Ubuntu官方软... 查看详情

ubuntu18.04/20.04cv环境配置(下)--手势识别trtpose+kinectdk人体骨骼识别(代码片段)

https://github.com/Alex1114/TRT-Pose-ROShttps://github.com/Alex1114/TRT-Pose-ROSGitHub-NVIDIA-AI-IOT/trt_pose:Real-timeposeestimationacceleratedwithNVIDIATensorRTReal-timeposeestimationacceleratedwithNVIDIATensorRT-GitHub-NVIDIA-AI-IOT/trt_pose:Real-timeposeestimationacceleratedwithNVIDIATensorRThtt... 查看详情

ubuntu18.04/20.04cv环境配置(下)--手势识别trtpose+kinectdk人体骨骼识别(代码片段)

https://github.com/Alex1114/TRT-Pose-ROShttps://github.com/Alex1114/TRT-Pose-ROSGitHub-NVIDIA-AI-IOT/trt_pose:Real-timeposeestimationacceleratedwithNVIDIATensorRTReal-timeposeestimationacceleratedwithNVIDIATensorRT-GitHub-NVIDIA-AI-IOT/trt_pose:Real-timeposeestimationacceleratedwithNVIDIATensorRThtt... 查看详情

ubuntu18.04/20.04下安装搜狗输入法

https://pinyin.sogou.com/linux/guide 查看详情

ubuntu/linux系统知识虚拟机安装ubuntu18.04/20.04

文章目录1、下载Ubuntu镜像文件2、ubuntu虚拟机创建3、安装Ubuntu系统1、下载Ubuntu镜像文件打开网址:http://www.ubuntu.com,点击Download,如下图,即可下载。文件大小1.8G。镜像下载过程中,我们可以接着进行下一步。2、ubuntu虚拟机创... 查看详情

ubuntu/linux系统知识虚拟机安装ubuntu18.04/20.04

文章目录1、下载Ubuntu镜像文件2、ubuntu虚拟机创建3、安装Ubuntu系统1、下载Ubuntu镜像文件打开网址:http://www.ubuntu.com,点击Download,如下图,即可下载。文件大小1.8G。镜像下载过程中,我们可以接着进行下一步。2、ubuntu虚拟机创... 查看详情

ubuntu18.04/20.04/22.04安装显卡驱动与显卡信息查询(代码片段)

ubuntu18.04/20.04/22.04安装显卡驱动与显卡信息查询安装显卡驱动卸载已有的nvidia显卡驱动(如果已安装的话)不确定之前是否安装过nvidia显卡驱动,最好执行下。sudoaptremove--purgenvidia*添加ppa源sudoadd-apt-repositoryppa:graphics-dr... 查看详情

如何在 ubuntu(或其他 linux 环境)中将 realsense RGB 帧转换为 cv::Mat?

】如何在ubuntu(或其他linux环境)中将realsenseRGB帧转换为cv::Mat?【英文标题】:HowtoconvertrealsenseRGBframetocv::Matinubuntu(orotherlinuxenv)?【发布时间】:2016-05-1703:01:28【问题描述】:没有官方的SDK可以这样做,有人可以帮忙吗?如何在ub... 查看详情

ubuntu上查看硬件配置和软件环境

通过命令 inxi-FxzSystem:  Host:K29Kernel:4.10.0-37-genericx86_64(64bitgcc:5.4.0)      Desktop:Cinnamon3.4.3(Gtk3.18.9-1ubuntu3.3)      Distro:LinuxMint18.2SonyaMachine:  System:LENOVO(portable)product:201 查看详情

ubuntu上查看硬件配置和软件环境

通过命令 inxi-FxzSystem:  Host:K29Kernel:4.10.0-37-genericx86_64(64bitgcc:5.4.0)      Desktop:Cinnamon3.4.3(Gtk3.18.9-1ubuntu3.3)      Distro:LinuxMint18.2SonyaMachine:  System:LENOVO(portable)product:201 查看详情

[ubuntu][tenosrrt]ubuntu上tensorrt环境变量配置

vi~/.bashrcexportTR_PATH=yourpathexportPATH=$PATH:$TR_PATH/binexportCPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:$TR_PATH/includeexportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TR_PATH/libexportLD_L 查看详情

在 Ubuntu 上安装 OpenCV for Python,得到 ImportError: No module named cv2.cv

】在Ubuntu上安装OpenCVforPython,得到ImportError:Nomodulenamedcv2.cv【英文标题】:InstallingOpenCVforPythononUbuntu,gettingImportError:Nomodulenamedcv2.cv【发布时间】:2014-10-0214:50:28【问题描述】:我有一个Ubuntu14.04系统,我想在其上安装OpenCV并将其与... 查看详情

[环境配置][转载]ubuntu上源码编译ffmpeg(代码片段)

Ubuntu18.04系统ffmpeg安装下载ffmpeg代码gitclonehttps://git.ffmpeg.org/ffmpeg.gitffmpeg安装依赖库文件sudoaptinstallyasmlibsdl2-devlibx264-devlibx265-devlibfdk-aac-dev编译安装ffmpeg./configure--prefix=/usr/local/ffmpeg--enable-shared--enable-libx264--enable-libx265--enable-gpl--... 查看详情