1. NVIDIA驱动
系统设置->软件和更新->附加驱动->选择NVIDIA驱动->应用更改。该界面会自动根据电脑上的GPU显示推荐的NVIDIA显卡驱动。
运行nvidia-smi
:
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.
1.1 使用nvcc -V
检查驱动和cuda:
Command 'nvcc' not found, but can be installed with:sudo apt install nvidia-cuda-toolkit
运行:
sudo apt install nvidia-cuda-toolkit
再次运行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
证明驱动是存在的,于是进行下一步。
1.2 检查是否已安装 NVIDIA 驱动:
dpkg -l | grep nvidia
出现
ii libnvidia-cfg1-535:amd64 535.183.01-0ubuntu0.20.04.1 amd64 NVIDIA binary OpenGL/GLX configuration library
ii libnvidia-common-535 535.183.01-0ubuntu0.20.04.1 all Shared files used by the NVIDIA libraries
ii libnvidia-compute-535:amd64 535.183.01-0ubuntu0.20.04.1 amd64 NVIDIA libcompute package
ii libnvidia-compute-535:i386 535.183.01-0ubuntu0.20.04.1 i386 NVIDIA libcompute package
ii libnvidia-decode-535:amd64 535.183.01-0ubuntu0.20.04.1 amd64 NVIDIA Video Decoding runtime libraries
ii libnvidia-decode-535:i386 535.183.01-0ubuntu0.20.04.1 i386 NVIDIA Video Decoding runtime libraries
ii libnvidia-encode-535:amd64 535.183.01-0ubuntu0.20.04.1 amd64 NVENC Video Encoding runtime library
ii libnvidia-encode-535:i386 535.183.01-0ubuntu0.20.04.1 i386 NVENC Video Encoding runtime library
ii libnvidia-extra-535:amd64 535.183.01-0ubuntu0.20.04.1 amd64 Extra libraries for the NVIDIA driver
ii libnvidia-fbc1-535:amd64 535.183.01-0ubuntu0.20.04.1 amd64 NVIDIA OpenGL-based Framebuffer Capture runtime library
ii libnvidia-fbc1-535:i386 535.183.01-0ubuntu0.20.04.1 i386 NVIDIA OpenGL-based Framebuffer Capture runtime library
ii libnvidia-gl-535:amd64 535.183.01-0ubuntu0.20.04.1 amd64 NVIDIA OpenGL/GLX/EGL/GLES GLVND libraries and Vulkan ICD
ii libnvidia-gl-535:i386 535.183.01-0ubuntu0.20.04.1 i386 NVIDIA OpenGL/GLX/EGL/GLES GLVND libraries and Vulkan ICD
ii libnvidia-ml-dev 10.1.243-3 amd64 NVIDIA Management Library (NVML) development files
ii nvidia-compute-utils-535 535.183.01-0ubuntu0.20.04.1 amd64 NVIDIA compute utilities
ii nvidia-cuda-dev 10.1.243-3 amd64 NVIDIA CUDA development files
ii nvidia-cuda-doc 10.1.243-3 all NVIDIA CUDA and OpenCL documentation
ii nvidia-cuda-gdb 10.1.243-3 amd64 NVIDIA CUDA Debugger (GDB)
ii nvidia-cuda-toolkit 10.1.243-3 amd64 NVIDIA CUDA development toolkit
ii nvidia-dkms-535 535.183.01-0ubuntu0.20.04.1 amd64 NVIDIA DKMS package
ii nvidia-driver-535 535.183.01-0ubuntu0.20.04.1 amd64 NVIDIA driver metapackage
ii nvidia-firmware-535-535.183.01 535.183.01-0ubuntu0.20.04.1 amd64 Firmware files used by the kernel module
ii nvidia-kernel-common-535 535.183.01-0ubuntu0.20.04.1 amd64 Shared files used with the kernel module
ii nvidia-kernel-source-535 535.183.01-0ubuntu0.20.04.1 amd64 NVIDIA kernel source package
ii nvidia-opencl-dev:amd64 10.1.243-3 amd64 NVIDIA OpenCL development files
ii nvidia-prime 0.8.16~0.20.04.2 all Tools to enable NVIDIA's Prime
ii nvidia-profiler 10.1.243-3 amd64 NVIDIA Profiler for CUDA and OpenCL
ii nvidia-settings 470.57.01-0ubuntu0.20.04.3 amd64 Tool for configuring the NVIDIA graphics driver
ii nvidia-utils-535 535.183.01-0ubuntu0.20.04.1 amd64 NVIDIA driver support binaries
ii nvidia-visual-profiler 10.1.243-3 amd64 NVIDIA Visual Profiler for CUDA and OpenCL
ii screen-resolution-extra 0.18build1 all Extension for the nvidia-settings control panel
ii xserver-xorg-video-nvidia-535 535.183.01-0ubuntu0.20.04.1 amd64 NVIDIA binary Xorg driver
说明已安装NVIDIA 驱动。
1.3 查看已安装驱动的版本信息
ls /usr/src | grep nvidia
出现驱动版本信息nvidia-535.183.01
。
1.4 安装 DKMS 工具,帮助自动重新编译和安装NVIDIA 驱动程序的内核模块
sudo apt-get install dkms
1.5 安装或重新安装特定版本(535.183.01)的 NVIDIA 驱动模块
错误…… 回到第一步,设置更换驱动后一定要重启!!!!或运行命令sudo reboot
。
1.6 运行sudo reboot
后,再次nvidia-smi
成功!
2. CUDA
2.1 首先查看cuda是否安装:
运行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
没有安装cuda。
2.2 参考1
2.3 参考2
2.4 查看CUDA版本
cat /usr/local/cuda/version.txt
2.5 查看cuDNN版本
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2