## 什么是 CUDA NVIDIA CUDA(Compute Unified Device Architecture)是一个综合性的并行计算平台和编程模型,利用 NVIDIA GPU 的强大计算能力来完成通用计算任务。CUDA 包括一整套的工具、库和编程模型,使得开发者能够在各类应用中利用 GPU 的并行计算能力。 ## 安装 CUDA 以下步骤演示了如何在 Ubuntu 22 系统中安装最新的显卡驱动和CUDA 1. 更新系统 ```shell $ sudo apt update $ sudo apt upgrade ``` 2. 查看当前系统可用驱动程序 ```shell $ sudo ubuntu-drivers list --gpgpu ``` 2. 安装驱动 ```shell $ sudo ubuntu-drivers install $ reboot # 重启系统 $ sudo nvidia-smi # 查看 nvidia-smi 信息 ``` 3. 安装 CUDA ```shell $ wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin $ sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600 $ wget https://developer.download.nvidia.com/compute/cuda/12.8.0/local_installers/cuda-repo-ubuntu2204-12-8-local_12.8.0-570.86.10-1_amd64.deb $ sudo dpkg -i cuda-repo-ubuntu2204-12-8-local_12.8.0-570.86.10-1_amd64.deb $ sudo cp /var/cuda-repo-ubuntu2204-12-8-local/cuda-*-keyring.gpg /usr/share/keyrings/ $ sudo apt-get update $ sudo apt-get -y install cuda-toolkit-12-8 ``` 4. 更新驱动 ```shell $ sudo apt-get install -y cuda-drivers $ sudo apt-get install -y nvidia-kernel-open-570 $ sudo apt-get install -y cuda-drivers-570 $ reboot # 重启系统 $ /usr/local/cuda-12.8/bin/nvcc --version # 查看 CUDA 信息 ``` ## 安装 NVIDIA Container Toolkit 以下步骤演示了如何在 Ubuntu 22 系统中安装最新的 NVIDIA Container Toolkit,并配置 Docker 1. 安装 NVIDIA Container Toolkit ```shell $ curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \ && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \ sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \ sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list $ sudo apt-get update $ sudo apt-get install -y nvidia-container-toolkit ``` 2. 配置 Docker ```shell $ sudo nvidia-ctk runtime configure --runtime=docker $ sudo systemctl restart docker ``` ## 参考 - https://ubuntu.com/server/docs/nvidia-drivers-installation - https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=22.04&target_type=deb_local