LoginSignup
2
4

Windows11 + WSL2 + NVIDIA CUDAの環境構築

Last updated at Posted at 2023-08-10

1. WSLのインストール

コントローパネルを開ける。
スクリーンショット 2023-08-10 144659.png
プログラム > Windowsの機能の有効化または無効化 にいどうする。
スクリーンショット 2023-08-10 144831.png
スクリーンショット 2023-08-10 144846.png
以下の3つを有効にする。

  • Linux 用 Windows サブシステム
  • Windows ハイパーバイザー プラットホーム
  • 仮想マシン プラットホーム
    スクリーンショット 2023-08-10 145257.png
    スクリーンショット 2023-08-10 145317.png
    インストール後は再起動する。
    スクリーンショット 2023-08-10 145534.png
    管理者としてWindows PowerShellを開ける。
    スクリーンショット 2023-08-10 195709.png
    wsl -l -oのコマンドでディストリビューションを確認する。
    スクリーンショット 2023-08-10 145803.png
    wsl --install <ディストリビューション名>でインストールする。
    スクリーンショット 2023-08-10 200451.png

2. CUDAの設定

タスクマネージャーを開ける。
スクリーンショット 2023-08-10 203517.png
プロセスに移動して、GPUを確認する。
スクリーンショット 2023-08-10 203530.png
下記よりNVIDIAのドライバーをインストールする。

インストーラーを実行する。
スクリーンショット 2023-08-10 203905.png
インストール後は再起動する。
スクリーンショット 2023-08-10 205257.png
sudo apt-key del 7fa2af80で古いGPGキーを削除する。
以下のコマンドを順番に入力して、CUDA Toolkitをインストールする。

  • sudo install gcc
  • sudo wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
  • sudo sh cuda_11.8.0_520.61.05_linux.run
    acceptを入力する。
┌──────────────────────────────────────────────────────────────────────────────┐
│  End User License Agreement                                                  │
│  --------------------------                                                  │
│                                                                              │
│  NVIDIA Software License Agreement and CUDA Supplement to                    │
│  Software License Agreement. Last updated: October 8, 2021                   │
│                                                                              │
│  The CUDA Toolkit End User License Agreement applies to the                  │
│  NVIDIA CUDA Toolkit, the NVIDIA CUDA Samples, the NVIDIA                    │
│  Display Driver, NVIDIA Nsight tools (Visual Studio Edition),                │
│  and the associated documentation on CUDA APIs, programming                  │
│  model and development tools. If you do not agree with the                   │
│  terms and conditions of the license agreement, then do not                  │
│  download or use the software.                                               │
│                                                                              │
│  Last updated: October 8, 2021.                                              │
│                                                                              │
│                                                                              │
│  Preface                                                                     │
│  -------                                                                     │
│                                                                              │
│──────────────────────────────────────────────────────────────────────────────│
│ Do you accept the above EULA? (accept/decline/quit):                         │
│ accept                                                                       │
└──────────────────────────────────────────────────────────────────────────────┘

以下の3つを選択する。

  • CUDA Toolkit 11.8
  • CUDA Demo Suite 11.8
  • Cuda Documentation 11.8

選択した後は、Installを選択してインストールする。

┌──────────────────────────────────────────────────────────────────────────────┐
│ CUDA Installer                                                               │
│ + [X] CUDA Toolkit 11.8                                                      │
│   [X] CUDA Demo Suite 11.8                                                   │
│   [X] CUDA Documentation 11.8                                                │
│ - [ ] Kernel Objects                                                         │
│      [ ] nvidia-fs                                                           │
│   Options                                                                    │
│   Install                                                                    │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│ Up/Down: Move | Left/Right: Expand | 'Enter': Select | 'A': Advanced options │
└──────────────────────────────────────────────────────────────────────────────┘

3. GPUの使用可の確認

sudo apt install python3.10-venvで仮想環境を作るためのパッケージをインストールする。
スクリーンショット 2023-08-10 224524.png
以下のコマンドを使って、仮想環境を作ってそれを有効にする。

  • python3 -m venv env
  • source env/bin/activate
    スクリーンショット 2023-08-10 224605.png
    pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 --no-cache-dirでpytorchをインストールする。
    スクリーンショット 2023-08-10 233611.png
    以下のコマンドでGPUの使用可を確認する。
  • python
  • import torch
  • torch.cuda.is_available()
    スクリーンショット 2023-08-10 232837.png
    Trueが返されたら正しく動作している。
2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4