Ubuntu20.04LTS+Cuda11.3安装 驱动
解决驱动 循环登录 报错
设备戴尔G7-7590
Intel® Core™ i7-9750H CPU @ 2.60GHz × 12 + GeForce RTX 2060 双显卡
Win10+Ubuntu20.04的双系统
我选择显卡驱动和cuda一起安装
-
查看英伟达显卡,会显示NVIDIA GPU 的信息
lspci | grep -I nvidia lspci | grep -i nvidia
-
查看自己的linux
uname -m && cat /etc/*release
-
查看正在运行的系统内核版本,安装对应的kernel header和package development
uname -r sudo apt-get install linux-headers-$(uname -r)
-
remove之前的驱动
sudo apt-get remove --purge nvidia*
-
安装gcc,g++,make等工具
sudo apt-get update sudo apt-get install dkms build-essential linux-headers-generic
-
禁用nouveau
sudo apt-get install vim sudo vim /etc/modprobe.d/blacklist.conf
-
在最后加上
blacklist nouveau blacklist lbm-nouveau options nouveau modeset=0 alias nouveau off alias lbm-nouveau off
-
禁用nouveau内核
echo options nouveau modeset=0 sudo update-initramfs -u
-
重启电脑,运行下面指令,如果nouveau禁用成功,则无输出。
lsmod | grep nouveau
-
下载cuda11.3(官网命令runfile)
wget https://developer.download.nvidia.com/compute/cuda/11.3.1/local_installers/cuda_11.3.1_465.19.01_linux.run
-
关闭图形界面并且安装cuda
sudo systemctl set-default multi-user.target sudo sh cuda_11.3.1_465.19.01_linux.run reboot
-
重启后应该进不去桌面,ctrl atl +F2或者F4等进入命令行模式,log in,开启图形界面,reboot
sudo systemctl set-default graphical.target sudo reboot
-
添加环境变量
sudo vim ~/.bashrc
-
最后一行加入(vim用i进入insert)
export CUDA_HOME=/usr/local/cuda export PATH=$PATH:$CUDA_HOME/bin export LD_LIBRARY_PATH=/usr/local/cuda-11.3/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
-
使其生效
source ~/.bashrc
-
检查命令:
cat /proc/driver/nvidia/version nvcc -V nvidia-smi cd /usr/local/cuda/samples/1_Utilities/deviceQuery sudo make ./deviceQuery
-
第一个cuda代码(guide上查看设备性能的code)
vim Device.cu
#include <stdio.h> int main() { int nDevices; cudaGetDeviceCount(&nDevices); for (int i = 0; i < nDevices; i++) { cudaDeviceProp prop; cudaGetDeviceProperties(&prop, i); printf("Device Num: %d\n", i); printf("Device name: %s\n", prop.name); printf("Device SM Num: %d\n", prop. multiProcessorCount); printf("Share Mem Per Block: %.2fKB\n", prop. sharedMemPerBlock / 1024.0); printf("Max Thread Per Block: %d\n", prop. maxThreadsPerBlock); printf("Memory Clock Rate (KHz): %d\n", prop.memoryClockRate); printf("Memory Bus Width (bits): %d\n", prop.memoryBusWidth); printf("Peak Memory Bandwidth (GB/s): %. 2f\n\n", 2.0 * prop.memoryClockRate * (prop. memoryBusWidth / 8) / 1.0e6); } return 0; }
-
编译并且运行
nvcc Device.cu -o Device.o ./Device.o
-
解决nvvp无法运行的问题——安装java
sudo apt install openjdk-8-jdk
-
To run Visual Profiler on Ubuntu
Make sure that you invoke Visual Profiler with the command-line option included as shown below:
nvvp -vm /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
Note: The-vmoption is only required when JRE is not included in CUDA Toolkit package and JRE 1.8 is not in the default path.
vim ~/.bashrc alias nvvp='nvvp -vm /usr/lib/jvm/java-8-openjdk-amd64/jre/ bin/java' source ~/.bashrc