Skip to Content
ドキュメントAIGPUのセットアップ

GPUのセットアップ

Note

この記事は、最初に Ubuntu 26.04 LTS 2026 年 4 月リリース ノートと照合してチェックされました。 AI/GPU ドライバーおよび CUDA/ROCm バージョンは、ベンダー サポート マトリックスに対して継続的に検証する必要があります。

GPU は、ほとんどの AI ワークロードを実行するための主要なハードウェアです。この記事では、ドライバーのインストール、CUDA ツールキット、cuDNN、検証手順など、Ubuntu 26.04 上で NVIDIA GPU 環境を構成するための詳細なガイドを提供します。また、AMD GPU ROCm の構成についても簡単に説明します。

26.04 リポジトリのステータス

Ubuntu 26.04 リポジトリでは、NVIDIA CUDA ツールキット (sudo apt install cuda-toolkit) および AMD が提供されるようになりました。 ROCm 7.1.0 (sudo apt install rocm)。これらはデフォルトではプリインストールされていません。運用トレーニング、特定の PyTorch/TensorFlow バージョン、またはマルチ GPU サーバーでは、引き続き NVIDIA/AMD ベンダー サポート マトリックスとフレームワーク リリース ノートを信頼できる最終情報源として扱います。

NVIDIA ドライバーのインストール

Ubuntu 26.04 は、NVIDIA ドライバーのインストールに便利な ubuntu-drivers ツールを提供します。

ハードウェアのチェック

# View NVIDIA GPUs in the system lspci | grep -i nvidia # Check recommended driver versions sudo ubuntu-drivers devices

出力例:

== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 == modalias : pci:v000010DEd00002684sv... vendor : NVIDIA Corporation model : AD102 [GeForce RTX 4090] driver : nvidia-driver-560 - third-party non-free recommended driver : nvidia-driver-550 - third-party non-free driver : nvidia-driver-555 - third-party non-free

自動インストール (推奨)

# Automatically install the recommended driver version sudo ubuntu-drivers autoinstall # Reboot to activate the driver sudo reboot

特定のバージョンの手動インストール

# View available driver versions apt list nvidia-driver-* 2>/dev/null | grep -v "Listing" # Install a specific version sudo apt install -y nvidia-driver-560 # Reboot sudo reboot

NVIDIA公式リポジトリからインストール(最新版)

# Add the NVIDIA official repository (Ubuntu 26.04 uses ubuntu2604) wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2604/x86_64/cuda-keyring_1.1-1_all.deb sudo dpkg -i cuda-keyring_1.1-1_all.deb sudo apt update # Install the latest driver sudo apt install -y nvidia-open # Reboot sudo reboot

ドライバーのインストールを確認する

# Check driver version and GPU status nvidia-smi

通常の出力例:

+-----------------------------------------------------------------------------------------+ | NVIDIA-SMI 560.35.03 Driver Version: 560.35.03 CUDA Version: 12.6 | |-----------------------------------------+------------------------+----------------------+ | GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. | |=========================================+========================+======================| | 0 NVIDIA GeForce RTX 4090 Off | 00000000:01:00.0 On | Off | | 0% 35C P8 18W / 450W | 512MiB / 24564MiB | 0% Default | +-----------------------------------------+------------------------+----------------------+
Tip

nvidia-smi 出力に表示される「CUDA バージョン」は、実際にインストールされている CUDA ツールキットのバージョンではなく、ドライバーでサポートされている最高の CUDA バージョンを示します。 CUDA ツールキットを個別にインストールする必要があります。


CUDA ツールキットのインストール

CUDA ツールキットは、NVIDIA の GPU コンピューティング プラットフォームおよびプログラミング モデルであり、ほとんどの AI フレームワーク (PyTorch、TensorFlow など) で必要となります。

ドライバーと CUDA のバージョンの関係

各 CUDA ツールキットには少なくとも NVIDIA ドライバー バージョンが必要で、新しい CUDA には新しいドライバーが必要です。インストールする前に、NVIDIA CUDA ツールキット リリース ノート  および PyTorch  / TensorFlow のバージョン サポート マトリックスを参照して、 3 つすべてに互換性のある組み合わせ。一般的なアプローチ: nvidia-smi を実行して、ドライバーがサポートする最も高い CUDA バージョンを確認し、それに応じて CUDA ツールキットとフレームワーク ホイールを選択します。

方法 1 (推奨): Ubuntu 26.04 リポジトリからインストールする

Ubuntu 26.04 は、リポジトリに CUDA ツールキットを同梱しています。ほとんどのローカル開発では、これが最も簡単なオプションです。

# Install the CUDA Toolkit from the Ubuntu repository sudo apt install -y cuda-toolkit # Verify nvcc --version

方法 2: NVIDIA リポジトリから特定のバージョンをインストールする

特定の CUDA ツールキット バージョンが必要な場合 (たとえば、特定の PyTorch ホイールに一致させるため):

# Add the NVIDIA official repository (Ubuntu 26.04 uses ubuntu2604) wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2604/x86_64/cuda-keyring_1.1-1_all.deb sudo dpkg -i cuda-keyring_1.1-1_all.deb sudo apt update # List available CUDA Toolkit versions in the repository apt-cache search cuda-toolkit # Install a specific version (replace XX-Y with an actual available version, e.g. cuda-toolkit-13-0) sudo apt install -y cuda-toolkit-XX-Y
Note

Ubuntu 26.04 には、公式リポジトリに NVIDIA CUDA ツールキットが同梱されているため、sudo apt install cuda-toolkit は直接動作します。 NVIDIA の ubuntu2604 リポジトリは、特定の CUDA バージョンが必要な場合 (たとえば、特定の PyTorch ホイールに一致させるため) に引き続き役立ちます。

環境変数の構成

# Add CUDA to PATH cat >> ~/.bashrc << 'EOF' # CUDA Toolkit export CUDA_HOME=/usr/local/cuda export PATH=$CUDA_HOME/bin:$PATH export LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH EOF source ~/.bashrc

CUDA のインストールを確認する

# Check CUDA compiler version nvcc --version # Example output: # nvcc: NVIDIA (R) Cuda compiler driver # Cuda compilation tools, release X.Y, VX.Y.xxx # Run CUDA samples (optional) # Newer CUDA versions no longer ship samples with the Toolkit; clone them from GitHub sudo apt install -y cmake build-essential git git clone https://github.com/NVIDIA/cuda-samples.git cd cuda-samples cmake -B build && cmake --build build -j$(nproc) # Run device query (path may vary by version) ./build/Samples/1_Utilities/deviceQuery/deviceQuery # If output shows "Result = PASS", installation is successful

複数の CUDA バージョンのインストール

# With the NVIDIA repository you can install multiple versions (replace XX-Y with actual versions) sudo apt install -y cuda-toolkit-XX-Y sudo apt install -y cuda-toolkit-ZZ-W # View installed versions ls /usr/local/ | grep cuda # Switch default version (by updating the symlink; replace X.Y with the target version) sudo rm /usr/local/cuda sudo ln -s /usr/local/cuda-X.Y /usr/local/cuda # Verify current version nvcc --version

cuDNN のインストール

cuDNN (CUDA ディープ ニューラル ネットワーク ライブラリ) は、NVIDIA のディープ ラーニング アクセラレーション ライブラリです。 PyTorch と TensorFlow は両方ともこれに依存します。

apt 経由でインストール (推奨)

# Ensure the NVIDIA repository has been added # Install cuDNN for CUDA 12 sudo apt install -y cudnn9-cuda-12 # Or install specific packages sudo apt install -y libcudnn9-cuda-12 libcudnn9-dev-cuda-12 # Verify installation dpkg -l | grep cudnn

tar パッケージ経由でインストールする

# Download cuDNN from the NVIDIA developer website # https://developer.nvidia.com/cudnn-downloads # Requires a free NVIDIA developer account # Extract to the CUDA directory sudo tar -xzf cudnn-linux-x86_64-9.x.x.x_cuda12-archive.tar.xz sudo cp cudnn-linux-x86_64-9.x.x.x_cuda12-archive/include/* /usr/local/cuda/include/ sudo cp cudnn-linux-x86_64-9.x.x.x_cuda12-archive/lib/* /usr/local/cuda/lib64/ sudo ldconfig

cuDNN を検証する

# Check if cuDNN can be found ldconfig -p | grep cudnn # Verify via Python (requires PyTorch to be installed first) python3 -c "import torch; print('cuDNN version:', torch.backends.cudnn.version()); print('cuDNN enabled:', torch.backends.cudnn.enabled)"

GPU の可用性を確認する

すべてのコンポーネントをインストールした後、包括的な検証を実行します。

システムレベルの検証

# 1. Check driver nvidia-smi # 2. Check CUDA nvcc --version # 3. Check cuDNN ldconfig -p | grep cudnn # 4. View detailed GPU information nvidia-smi -q | head -50 # 5. Monitor real-time GPU status watch -n 1 nvidia-smi

PyTorch GPU の検証

# Install PyTorch (inside an activated virtual environment) # pip install torch installs the wheel for the current CUDA by default; # older drivers can pin a lower CUDA, e.g. cu126 pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126 # Verify GPU availability python3 << 'EOF' import torch print(f"PyTorch version: {torch.__version__}") print(f"CUDA available: {torch.cuda.is_available()}") print(f"CUDA version: {torch.version.cuda}") print(f"cuDNN version: {torch.backends.cudnn.version()}") print(f"GPU count: {torch.cuda.device_count()}") if torch.cuda.is_available(): print(f"Current GPU: {torch.cuda.get_device_name(0)}") print(f"GPU VRAM: {torch.cuda.get_device_properties(0).total_memory / 1024**3:.1f} GB") # Simple GPU compute test x = torch.randn(1000, 1000, device='cuda') y = torch.randn(1000, 1000, device='cuda') z = torch.mm(x, y) print(f"GPU compute test passed! Matrix multiplication result shape: {z.shape}") else: print("Warning: CUDA not available. Please check driver and CUDA installation") EOF

TensorFlow GPU の検証

# Install TensorFlow pip install tensorflow # Verify python3 << 'EOF' import tensorflow as tf print(f"TensorFlow version: {tf.__version__}") gpus = tf.config.list_physical_devices('GPU') print(f"Available GPU count: {len(gpus)}") for gpu in gpus: print(f" GPU: {gpu.name}") if gpus: # Simple test with tf.device('/GPU:0'): a = tf.random.normal([1000, 1000]) b = tf.random.normal([1000, 1000]) c = tf.matmul(a, b) print(f"GPU compute test passed! Matrix multiplication result shape: {c.shape}") EOF

ROCm (AMD GPU) の概要

ROCm (Radeon Open Compute) は、NVIDIA の CUDA と同様、AMD のオープンソース GPU コンピューティング プラットフォームです。

サポートされている AMD GPU

ROCm は主に次の AMD GPU シリーズをサポートします。

  • Radeon RX 7900 XTX / 7900 XT (RDNA 3)
  • Radeon RX 7800 XT / 7700 XT (RDNA 3)
  • Radeon PRO W7900 / W7800
  • Instinct MI300X / MI250X / MI210 (データセンター)

ROCm をインストールする

Ubuntu 26.04 は、単一の apt コマンドで ROCm をインストールできる最初のリリースです。 26.04 リポジトリに同梱されているパッケージを優先します。

# Method 1 (recommended): use the ROCm packaged in the Ubuntu 26.04 repository # Full runtime stack sudo apt install -y rocm # Or just the libraries and headers for development # sudo apt install -y rocm-dev # Add user to render and video groups sudo usermod -aG render,video $USER # Reboot sudo reboot
Note

Ubuntu 26.04 リポジトリには ROCm 7.1.0 が同梱されています。新しいバージョンが必要な場合は、以下の AMD の公式リポジトリを使用し、AMD の公式ドキュメントから現在のバージョン番号に従ってください。

# Method 2: install a newer version from AMD's official repository # Check the current version at https://repo.radeon.com/rocm/apt/ and replace <version> below # Until AMD ships an Ubuntu 26.04 (resolute) repo, the 24.04 (noble) repo can be used as a fallback wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | \ gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/<version> noble main" | \ sudo tee /etc/apt/sources.list.d/rocm.list sudo apt update sudo apt install -y rocm sudo usermod -aG render,video $USER sudo reboot

ROCm を確認する

# View AMD GPU information rocm-smi # Check ROCm version rocminfo | head -20 # Install PyTorch ROCm version pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.2 # Verify python3 -c "import torch; print('ROCm available:', torch.cuda.is_available()); print('Device:', torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'N/A')"
Note

AMD ROCm のソフトウェア エコシステムは、NVIDIA CUDA ほど成熟していません。一部の AI ツールはサポートされていないか、サポートが制限されている場合があります。主な用途が AI 開発である場合は、NVIDIA GPU がより安全な選択肢となります。ただし、ROCm は継続的に改善されており、PyTorch といくつかの主要なフレームワークは適切にサポートされるようになりました。


よくあるトラブルシューティング

問題 1: nvidia-smi で出力またはエラーが表示される

# Check if the driver is loaded lsmod | grep nvidia # If no output, try reloading the driver sudo modprobe nvidia # Check for Secure Boot issues mokutil --sb-state # If Secure Boot is enabled, you may need to sign the driver or disable Secure Boot # Check kernel logs dmesg | grep -i nvidia sudo journalctl -b | grep -i nvidia

問題 2: ドライバーのバージョンの競合

# Remove all NVIDIA drivers sudo apt purge -y 'nvidia-*' sudo apt purge -y 'libnvidia-*' sudo apt autoremove -y # Reboot sudo reboot # Reinstall sudo ubuntu-drivers autoinstall sudo reboot

問題 3: CUDA バージョンと PyTorch の不一致

# Check current CUDA version nvcc --version # Check PyTorch expected CUDA version python3 -c "import torch; print(torch.version.cuda)" # If mismatched, install the PyTorch wheel for the corresponding CUDA version # Default (current CUDA) pip install torch # CUDA 12.6 pip install torch --index-url https://download.pytorch.org/whl/cu126 # CUDA 12.8 pip install torch --index-url https://download.pytorch.org/whl/cu128 # Available cuXXX indexes are listed at https://pytorch.org/get-started/locally/

問題 4: GPU のメモリ不足 (OOM)

# Check current GPU memory usage nvidia-smi # Find processes using the GPU nvidia-smi --query-compute-apps=pid,name,used_memory --format=csv # Free GPU memory (kill the occupying process) # First confirm the process PID kill -9 <PID> # Clear PyTorch cache python3 -c "import torch; torch.cuda.empty_cache()"

問題 5: Nouveau ドライバーの競合

# Nouveau is the open-source NVIDIA driver, which may conflict with the official driver # Check if nouveau is loaded lsmod | grep nouveau # If there is output, disable nouveau sudo bash -c 'cat > /etc/modprobe.d/blacklist-nouveau.conf << EOF blacklist nouveau options nouveau modeset=0 EOF' # Regenerate initramfs sudo update-initramfs -u # Reboot sudo reboot

問題 6: Docker コンテナーでの GPU の使用

# Install NVIDIA Container Toolkit 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 update sudo apt install -y nvidia-container-toolkit # Configure Docker sudo nvidia-ctk runtime configure --runtime=docker sudo systemctl restart docker # Test Docker GPU access docker run --rm --gpus all nvidia/cuda:12.6.0-base-ubuntu24.04 nvidia-smi # Tip: nvidia/cuda image tags are organized by CUDA version and base OS; # pick an existing tag at https://hub.docker.com/r/nvidia/cuda/tags
Tip

NVIDIA ドライバーをインストールした後、すぐに NVIDIA Container Toolkit をインストールすることをお勧めします。これにより、コンテナー内でドライバーを個別に構成しなくても、Docker コンテナー (Open WebUI、ComfyUI など) で AI ツールを実行するときに GPU アクセラレーションを使用できるようになります。


完全なインストール スクリプト

次のスクリプトは、GPU 環境のセットアップ プロセス全体を統合します。

#!/bin/bash # gpu-setup.sh -- Ubuntu 26.04 NVIDIA GPU Environment One-Click Setup set -e echo "=== 1. Install NVIDIA Driver ===" sudo apt update sudo ubuntu-drivers autoinstall echo "=== 2. Install CUDA Toolkit (Ubuntu 26.04 repository) ===" sudo apt install -y cuda-toolkit echo "=== 3. (Optional) For a newer version from the NVIDIA repository, use the following instead ===" # wget -q https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2604/x86_64/cuda-keyring_1.1-1_all.deb # sudo dpkg -i cuda-keyring_1.1-1_all.deb # sudo apt update # sudo apt install -y cuda-toolkit-XX-Y # replace with an actual available version echo "=== 4. Install cuDNN ===" sudo apt install -y cudnn9-cuda-12 echo "=== 5. Configure Environment Variables ===" if ! grep -q "CUDA_HOME" ~/.bashrc; then cat >> ~/.bashrc << 'ENVEOF' # CUDA Environment export CUDA_HOME=/usr/local/cuda export PATH=$CUDA_HOME/bin:$PATH export LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH ENVEOF fi echo "=== 6. Install NVIDIA Container Toolkit ===" 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 update sudo apt install -y nvidia-container-toolkit echo "" echo "=== Installation Complete! ===" echo "Please reboot and then run nvidia-smi and nvcc --version to verify." echo "Reboot command: sudo reboot"
# Save and run the script chmod +x gpu-setup.sh ./gpu-setup.sh