CUDA 安裝教程
安裝教程主要針對 Linux (Ubuntu 20.04)
一、使用 Docker 鏡像(推薦)
打包好的 cuda 鏡像 https://hub.docker.com/r/nvidia/cuda https://catalog.ngc.nvidia.com/orgs/nvidia/containers/cuda/tags
cuda 鏡像的 dockerfile 文件 https://gitlab.com/nvidia/container-images/cuda
Three flavors of images are provided:
base: Includes the CUDA runtime (cudart)
runtime: Builds on the base and includes the CUDA math libraries, and NCCL. A runtime image that also includes cuDNN is available.
devel: Builds on the runtime and includes headers, development tools for building CUDA images. These images are particularly useful for multi-stage builds.
cuda 鏡像幾個版本之間的關系為
base > runtime > devel > cudnn
#?拉取鏡像
docker?pull?nvidia/cuda:10.2-devel-ubuntu18.04
#?運行
docker?run?-itd?--name?cuda-11.7.1?\?#?名稱不能重復
-v?~/${username}/Workspace/Docker/:/service?\?#?映射本機路徑到容器路徑
--gpus?'"device=1"'?\?#?選擇?gpu?0?是第一張卡
nvidia/cuda:11.7.1-cudnn8-devel-ubuntu20.04?bash?#?鏡像地址?選擇shell
推薦使用 vscode docker 插件,運行后就可直接在 vscode 中使用容器了
二、手動安裝
1.顯卡驅動安裝(必須)
驅動下載地址: https://www.nvidia.com/download/index.aspx?lang=en-us
#?驅動安裝
apt-get?update
apt-get?install?nvidia-drivers
#?查看驅動版本
nvidia-smi?
#?查看結果
+-----------------------------------------------------------------------------+
|?NVIDIA-SMI?515.65.01????Driver?Version:?515.65.01????CUDA?Version:?11.7?????|
|-------------------------------+----------------------+----------------------+
|?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??Tesla?T4????????????On???|?00000000:13:00.0?Off?|????????????????????0?|
|?N/A???74C????P8????22W?/??70W?|??????2MiB?/?15360MiB?|??????0%??????Default?|
|???????????????????????????????|??????????????????????|??????????????????N/A?|
+-------------------------------+----------------------+----------------------+
???????????????????????????????????????????????????????????????????????????????
+-----------------------------------------------------------------------------+
|?Processes:??????????????????????????????????????????????????????????????????|
|??GPU???GI???CI????????PID???Type???Process?name??????????????????GPU?Memory?|
|????????ID???ID???????????????????????????????????????????????????Usage??????|
|=============================================================================|
|??No?running?processes?found?????????????????????????????????????????????????|
+-----------------------------------------------------------------------------+
如果沒有類似的結果,說明驅動沒安裝成功。
其中需要關注的是
Driver Version: 515.65.01
顯卡驅動版本CUDA Version: 11.7
最高支持CUDA版本
cuda 對驅動的要求
Table 3. CUDA Toolkit and Corresponding Driver Versions 中給出 cuda 對應驅動版本,高版本驅動可向下兼容
2.CUDA 安裝(必須)
https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
nvcc?-V?#?查看CUDA版本
#?查看結果
nvcc:?NVIDIA?(R)?Cuda?compiler?driver
Copyright?(c)?2005-2022?NVIDIA?Corporation
Built?on?Wed_Jun__8_16:49:14_PDT_2022
Cuda?compilation?tools,?release?11.7,?V11.7.99
Build?cuda_11.7.r11.7/compiler.31442593_0
3.cuDNN 安裝(可選)
https://developer.nvidia.com/rdp/cudnn-download https://developer.nvidia.com/rdp/cudnn-archive