操做系統: Ubuntu 16.04/18.04
推薦使用 graphics drivers PPA 安裝 Nvidia 驅動。html
sudo add-apt-repository ppa:graphics-drivers/ppa sudo apt update
檢測推薦的 Nvidia 顯卡驅動:linux
ubuntu-drivers devices
安裝 Nvidia 驅動(如下是 RTX2060 上的狀況):git
# Ubuntu 16.04 only search 430 for CUDA < 10.2 apt-cache search nvidia sudo apt install nvidia-430 # Ubuntu 18.04 could search 440 for CUDA <= 10.2 apt-cache search nvidia | grep ^nvidia-driver sudo apt install nvidia-driver-440
驅動對應的 CUDA 版本,請見 CUDA Compatibility 。
最後, sudo reboot
重啓。以後,運行 nvidia-smi
輸出 Nvidia 驅動信息:github
$ nvidia-smi Fri Apr 17 07:31:55 2020 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 440.82 Driver Version: 440.82 CUDA Version: 10.2 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 GeForce RTX 2060 Off | 00000000:01:00.0 Off | N/A | | N/A 40C P8 5W / N/A | 263MiB / 5934MiB | 3% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 0 1560 G /usr/lib/xorg/Xorg 144MiB | | 0 1726 G /usr/bin/gnome-shell 76MiB | | 0 2063 G ...uest-channel-token=10544833948196615517 39MiB | +-----------------------------------------------------------------------------+
若是安裝 CUDA Toolkit ,請先了解 CUDA Compatibility 。安裝 CUDA Toolkit 時,注意其攜帶的驅動版本,最好將其與驅動分別進行安裝。而驅動從官方上直接找合適的版本。
# update the apt package index sudo apt-get update # install packages to allow apt to use a repository over HTTPS sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common # add Docker’s official GPG key curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - # set up the stable repository sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \ $(lsb_release -cs) \ stable" # update the apt package index sudo apt-get update # install the latest version of Docker Engine and containerd sudo apt-get install docker-ce docker-ce-cli containerd.io
以後,將 Docker 設爲 non-root 用戶可用:docker
sudo groupadd docker sudo usermod -aG docker $USER
# add the package repositories distribution=$(. /etc/os-release;echo $ID$VERSION_ID) curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list sudo apt-get update sudo apt-get install -y nvidia-container-toolkit sudo systemctl restart docker
#### Test nvidia-smi with the latest official CUDA image docker run --gpus all nvidia/cuda:10.0-base nvidia-smi # Start a GPU enabled container on two GPUs docker run --gpus 2 nvidia/cuda:10.0-base nvidia-smi # Starting a GPU enabled container on specific GPUs docker run --gpus '"device=1,2"' nvidia/cuda:10.0-base nvidia-smi docker run --gpus '"device=UUID-ABCDEF,1"' nvidia/cuda:10.0-base nvidia-smi # Specifying a capability (graphics, compute, ...) for my container # Note this is rarely if ever used this way docker run --gpus all,capabilities=utility nvidia/cuda:10.0-base nvidia-smi
$ docker run --gpus all nvidia/cuda:10.2-base-ubuntu16.04 nvidia-smi Unable to find image 'nvidia/cuda:10.2-base-ubuntu16.04' locally 10.2-base-ubuntu16.04: Pulling from nvidia/cuda 976a760c94fc: Pull complete c58992f3c37b: Pull complete 0ca0e5e7f12e: Pull complete f2a274cc00ca: Pull complete 708a53113e13: Pull complete 7dde2dc03189: Pull complete 2d21d4aba891: Pull complete Digest: sha256:1423b386bb4f950d12b3b0f3ad51eba42d754ee73f8fc4a60657a1904993b68c Status: Downloaded newer image for nvidia/cuda:10.2-base-ubuntu16.04 Fri Apr 24 08:17:26 2020 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 440.82 Driver Version: 440.82 CUDA Version: 10.2 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 GeForce RTX 2060 Off | 00000000:01:00.0 Off | N/A | | N/A 38C P8 10W / N/A | 523MiB / 5934MiB | 21% Default | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| +-----------------------------------------------------------------------------+
Go coding!shell
分享 Coding 中實用的小技巧、小知識!歡迎關注,共同成長!ubuntu