ubuntu系统下安装cuda与cudnn
一、安装依赖
1.更新
sudo apt update
sudo apt upgrade -y
2.基础工具
sudo apt install -y build-essential python
二、安装CUDA
1.文件下载
网址
https://developer.nvidia.com/cuda-toolkit-archive
依次点击
(1)"CUDA Toolkit 11.6.2"
(2)"Linux"
(3)"x86_64"
(4)"Ubuntu"
(5)"20.04"
(6)"runfile(local)"
在"Installation Instructions:"下方为下载安装指令
下载指令(文件需下载到英文路径),如:
cd /home/heqingchun/soft/nvidia
wget https://developer.download.nvidia.com/compute/cuda/11.6.2/local_installers/cuda_11.6.2_510.47.03_linux.run
在"/home/heqingchun/soft/nvidia"路径中下载得到"cuda_11.6.2_510.47.03_linux.run"文件
以下是安装时使用的指令
sudo sh cuda_11.6.2_510.47.03_linux.run
2.cuda安装
(1)赋予可执行权限
chmod 755 cuda_11.6.2_510.47.03_linux.run
(2)运行安装
sudo sh cuda_11.6.2_510.47.03_linux.run
期间会弹出对话框,需手动输入"accept"回车,在之后再弹出对话框中取消勾选"Driver"
CUDA Installer │
│ - [ ] Driver │
│ [ ] 510.47.03 │
│ + [X] CUDA Toolkit 11.6 │
│ [X] CUDA Samples 11.6 │
│ [X] CUDA Demo Suite 11.6 │
│ [X] CUDA Documentation 11.6 │
│ Options │
│ Install
向下选择"install"后等待安装完毕即可。
安装完毕信息:
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-11.6/
Please make sure that
- PATH includes /usr/local/cuda-11.6/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-11.6/lib64, or, add /usr/local/cuda-11.6/lib64 to /etc/ld.so.conf and run ldconfig as root
To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.6/bin
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 510.00 is required for CUDA 11.6 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
(3)配置环境变量
str='export PATH=/usr/local/cuda-11.6/bin:"$"PATH' && \
sudo sh -c "echo $str >> /etc/profile" && \
source /etc/profile && \
str='export LD_LIBRARY_PATH=/usr/local/cuda-11.6/lib64:"$"LD_LIBRARY_PATH' && \
sudo sh -c "echo $str >> /etc/profile" && \
source /etc/profile
(4)重启电脑
3.验证安装
(1)版本信息
nvcc -V
显示如下:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 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
(2)库信息
cat /usr/local/cuda/version.json
显示如下:
{
"cuda" : {
"name" : "CUDA SDK",
"version" : "11.6.20220318"
},
"cuda_cccl" : {
"name" : "CUDA C++ Core Compute Libraries",
"version" : "11.6.55"
},
"cuda_cudart" : {
"name" : "CUDA Runtime (cudart)",
"version" : "11.6.55"
},
"cuda_cuobjdump" : {
"name" : "cuobjdump",
"version" : "11.6.124"
},
"cuda_cupti" : {
"name" : "CUPTI",
"version" : "11.6.124"
},
"cuda_cuxxfilt" : {
"name" : "CUDA cu++ filt",
"version" : "11.6.124"
},
"cuda_demo_suite" : {
"name" : "CUDA Demo Suite",
"version" : "11.6.55"
},
"cuda_gdb" : {
"name" : "CUDA GDB",
"version" : "11.6.124"
},
"cuda_memcheck" : {
"name" : "CUDA Memcheck",
"version" : "11.6.124"
},
"cuda_nsight" : {
"name" : "Nsight Eclipse Plugins",
"version" : "11.6.124"
},
"cuda_nvcc" : {
"name" : "CUDA NVCC",
"version" : "11.6.124"
},
"cuda_nvdisasm" : {
"name" : "CUDA nvdisasm",
"version" : "11.6.124"
},
"cuda_nvml_dev" : {
"name" : "CUDA NVML Headers",
"version" : "11.6.55"
},
"cuda_nvprof" : {
"name" : "CUDA nvprof",
"version" : "11.6.124"
},
"cuda_nvprune" : {
"name" : "CUDA nvprune",
"version" : "11.6.124"
},
"cuda_nvrtc" : {
"name" : "CUDA NVRTC",
"version" : "11.6.124"
},
"cuda_nvtx" : {
"name" : "CUDA NVTX",
"version" : "11.6.124"
},
"cuda_nvvp" : {
"name" : "CUDA NVVP",
"version" : "11.6.124"
},
"cuda_samples" : {
"name" : "CUDA Samples",
"version" : "11.6.101"
},
"cuda_sanitizer_api" : {
"name" : "CUDA Compute Sanitizer API",
"version" : "11.6.124"
},
"libcublas" : {
"name" : "CUDA cuBLAS",
"version" : "11.9.2.110"
},
"libcufft" : {
"name" : "CUDA cuFFT",
"version" : "10.7.2.124"
},
"libcurand" : {
"name" : "CUDA cuRAND",
"version" : "10.2.9.124"
},
"libcusolver" : {
"name" : "CUDA cuSOLVER",
"version" : "11.3.4.124"
},
"libcusparse" : {
"name" : "CUDA cuSPARSE",
"version" : "11.7.2.124"
},
"libnpp" : {
"name" : "CUDA NPP",
"version" : "11.6.3.124"
},
"libnvjpeg" : {
"name" : "CUDA nvJPEG",
"version" : "11.6.2.124"
},
"nsight_compute" : {
"name" : "Nsight Compute",
"version" : "2022.1.1.2"
},
"nsight_systems" : {
"name" : "Nsight Systems",
"version" : "2021.5.2.53"
},
"nvidia_driver" : {
"name" : "NVIDIA Linux Driver",
"version" : "510.47.03"
}
}
(3)计算能力
cd /usr/local/cuda/extras/demo_suite
./deviceQuery
显示:
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.6, CUDA Runtime Version = 11.6, NumDevs = 1, Device0 = NVIDIA GeForce RTX 3050 Laptop GPU
Result = PASS
CUDA安装完毕
三、安装cuDNN
1.文件下载
网址
https://developer.nvidia.com/rdp/cudnn-archive
依次点击
(1)"Download cuDNN v8.4.0 (April 1st, 2022), for CUDA 11.x"
(2)"Local Installer for Linux x86_64 (Tar)"
注:需要登陆,登陆成功后即可下载
下载得到"cudnn-linux-x86_64-8.4.0.27_cuda11.6-archive.tar.xz"文件放入"/home/heqingchun/soft/nvidia"目录
2.cuDNN安装
进入文件所在目录、解压文件、解压后进入文件夹、拷贝文件
cd /home/heqingchun/soft/nvidia
tar -xvf cudnn-linux-x86_64-8.4.0.27_cuda11.6-archive.tar.xz && \
cd cudnn-linux-x86_64-8.4.0.27_cuda11.6-archive && \
sudo cp include/* /usr/local/cuda-11.6/include && \
sudo cp -P lib/* /usr/local/cuda-11.6/lib64 && \
sudo chmod a+r /usr/local/cuda-11.6/include/cudnn*.h /usr/local/cuda-11.6/lib64/libcudnn*
重启电脑
3.验证安装
cat /usr/local/cuda/include/cudnn_version.h
显示如下:
/**
* \file: The master cuDNN version file.
*/
#ifndef CUDNN_VERSION_H_
#define CUDNN_VERSION_H_
#define CUDNN_MAJOR 8
#define CUDNN_MINOR 4
#define CUDNN_PATCHLEVEL 0
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
#endif /* CUDNN_VERSION_H */
cuDNN安装完毕
ubuntu系统下安装cuda与cudnn-完毕