Linux/nvidia
来自康健生活
< Linux
引言
查看计算机的显卡。
[jian@kang /home/kangkk]$
lspci | grep -i vga
# or
lspci | egrep 'VGA|3D'
00:02.0 VGA compatible controller: Intel Corporation UHD Graphics (rev 05)
01:00.0 VGA compatible controller: NVIDIA Corporation TU106 [GeForce RTX 2060] (rev a1)
检查已经安装的 nvidia 驱动。
[jian@kang /home/kangkk]$
nvidia-detector
nvidia-driver-495
卸载
卸载所有已安装的 nvidia 驱动以及 cuda 相关文件。
/home/kangkk
sudo apt remove --purge nvidia*
sudo apt remove --purge cuda*
sudo rm -rf cuda*
安装
输入 ubuntu-drivers 命令进行查看 ubuntu 系统推荐的驱动。
[jian@kang /home/kangkk]$
ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00001F15sv00001043sd00001C6Fbc03sc00i00
vendor : NVIDIA Corporation
driver : nvidia-driver-455 - third-party non-free
driver : nvidia-driver-465 - third-party non-free
driver : nvidia-driver-495 - third-party non-free recommended
driver : nvidia-driver-470 - third-party non-free
driver : nvidia-driver-450-server - distro non-free
driver : nvidia-driver-460 - third-party non-free
driver : nvidia-driver-460-server - distro non-free
driver : nvidia-driver-450 - third-party non-free
driver : nvidia-driver-470-server - distro non-free
driver : xserver-xorg-video-nouveau - distro free builtin
进行驱动安装。
/home/kangkk
sudo apt install nvidia-driver-495
nvidia-smi
输入 nvidia-smi 命令查看支持的 cuda 版本。
[jian@kang /home/kangkk]$
nvidia-smi
Sun Nov 7 17:33:37 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 495.29.05 Driver Version: 495.29.05 CUDA Version: 11.5 |
|-------------------------------+----------------------+----------------------+
| 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 ... On | 00000000:01:00.0 Off | N/A |
| N/A 35C P8 5W / N/A | 362MiB / 5934MiB | 7% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 1195 G /usr/lib/xorg/Xorg 45MiB |
| 0 N/A N/A 1710 G /usr/lib/xorg/Xorg 112MiB |
| 0 N/A N/A 1886 G /usr/bin/gnome-shell 74MiB |
| 0 N/A N/A 2962 G ...AAAAAAAAA= --shared-files 119MiB |
+-----------------------------------------------------------------------------+
CUDA
官网下载,按照步骤安装即可。
检查
查询 CUDA 的版本。
[jian@kang /home/kangkk]$
cat /usr/local/cuda/version.json
{
"cuda" : {
"name" : "CUDA SDK",
"version" : "11.5.1"
},
"cuda_cudart" : {
"name" : "CUDA Runtime (cudart)",
"version" : "11.5.117"
},
...
测试 CUDA。
[jian@kang /home/kangkk]$
cd /usr/local/cuda/samples/1_Utilities/deviceQuery
sudo make
/usr/local/cuda-11.5/bin/nvcc -ccbin g++ -I../../common/inc -m64 --threads 0 --std=c++11 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_80,code=sm_80 -gencode arch=compute_86,code=sm_86 -gencode arch=compute_86,code=compute_86 -o deviceQuery.o -c deviceQuery.cpp
nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
/usr/local/cuda-11.5/bin/nvcc -ccbin g++ -m64 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_80,code=sm_80 -gencode arch=compute_86,code=sm_86 -gencode arch=compute_86,code=compute_86 -o deviceQuery deviceQuery.o
nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
mkdir -p ../../bin/x86_64/linux/release
cp deviceQuery ../../bin/x86_64/linux/release
编译完成之后,执行生成的 deviceQuery 程序。
[jian@kang /home/kangkk]$
sudo /usr/local/cuda/samples/1_Utilities/deviceQuery/deviceQuery
/usr/local/cuda/samples/1_Utilities/deviceQuery/deviceQuery Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "NVIDIA GeForce RTX 2060"
CUDA Driver Version / Runtime Version 11.5 / 11.5
CUDA Capability Major/Minor version number: 7.5
Total amount of global memory: 5935 MBytes (6222839808 bytes)
(030) Multiprocessors, (064) CUDA Cores/MP: 1920 CUDA Cores
GPU Max Clock rate: 1560 MHz (1.56 GHz)
Memory Clock rate: 5501 Mhz
Memory Bus Width: 192-bit
L2 Cache Size: 3145728 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: 65536 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 1024
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: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
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 / 1 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.5, CUDA Runtime Version = 11.5, NumDevs = 1
Result = PASS
run
下载并进行安装。
/home/kangkk
sudo sh cuda_*_linux.run
安装完成之后,使用 nvcc 命令,提示 sudo apt-get install nvidia-cuda-toolkit,这个时候不确定是否安装成功,需要到 /usr/local/cuda 文件夹下面检查 cuda 目录下的 bin 文件夹中是否存在 nvcc。
确定存在之后,在 bashrc 文件中加入 nvcc 的环境变量
~/bashrc
export PATH=/usr/local/cuda/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
/home/kangkk
source ~/.bashrc
nvidia-cuda-toolkit
多种安装方式,最简单的如下,但是版本滞后,不建议。
/home/kangkk
sudo apt install nvidia-cuda-toolkit -y
nvcc
NVIDIA (R) Cuda compiler driver(CUDA-C 和 CUDA-C++ 编译器)。
验证版本信息。
[jian@kang /home/kangkk]$
nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243
cuDNN
CUDNN 是基于 CUDA 的深度学习 GPU 加速库(扩展计算库),是深度神经网络的必备库。
插入式安装
只需要解压后,将 CUDNN 文件复制到 CUDA 的对应文件夹。
other
cuda 与 nvcc 版本不一致问题
刚接触 cuda 的时候,我使用 sudo apt install nvidia-driver-495 安装 nvidia 驱动,同时又使用 sudo apt install nvidia-cuda-toolkit -y 安装 nvcc,导致版本 cuda 与 nvcc 版本不一致,cuda 版本是 11.5,而 nvcc 版本是 9.5。
No categories