LoginSignup
9
15

More than 1 year has passed since last update.

PyTorch-CUDA+cuDNN環境構築 on Windows 11

Last updated at Posted at 2022-08-10

環境

  • Windows 11
  • GeForce RTX 3090
  • Anaconda Navigator

Visual Studio

DOWNLOAD

  • 掲載画像は Visual Studio Enterprise 2022 ですが Community(無償)でも同じ.... だと思います
    • ダウンロードページの下の方にある [Build Tools for Visual Studio 2022] でも良いようです

INSTALL

  • Desktop Development with C++ の中にある [MSVC v143 - VS 2022 C++ x64/x86 build tools] にチェック
    • Visual Studio を使う予定がなければ他のチェックは全て外してOK
    • CUDA のバージョンが低いと,Visual Studio 2022 だと動作しないため version を下げる必要がある
      • 下の方に MSVC v142...140 があり,version を下げる際にはこちらを使用します
        image.png

CUDA Toolkit (+ NVIDIA Graphics Driver)

DOWNLOAD

  • version 11.7.1 (2022/8/10現在)

image.png

  • exe (network)でもOK
    image.png

INSTALL

  • すべてデフォルトでもOKですが,CUDA, Graphics Driver 以外は必要ありませんので Custom Install でチェックを外しておきましょう。
  • GeForce Experience はご自由に

2022-08-25.png
2022-08-25 (1).png

正常にインストールできているかの確認

  • メニュー(WINDOWSボタン)の検索から [環境変数] を入力し[システム環境変数の編集] を開く
    image.png
  • システム環境変数(下段)の[CUDA_PATH] [CUDA_PATH_V11_7] にPathが通っていることを確認しておきましょう。
    2.png
  • command prompt から [nvcc -V] を入力、下記のようになれば正常にインストールできています。
    image.png

cuDNN

DOWNLOAD

  • ログインが必要(nvidia account は基本無償のようです)
    image.png
  • I Agree To the Terms of the ***** にチェックし、[Download cuDNN v8.5.0 (August 8th, 2022), for CUDA 11.x -> Local Installer for Windows (Zip)] と進みダウンロード

INSTALL

ファイルのコピー

  • あらかじめ[C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN] のフォルダを作成 ※環境によっては管理者権限が必要
  • ダウンロードしたファイルを解凍し、中身一式(bin, include, lib, LICENSE) を先程作成した [C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN ] へコピー

環境変数の登録

  1. システム環境変数の編集
  2. 設定 > システム > バージョン情報 > システム詳細設定 > [環境変数] をクリック
  3. [システム環境変数] の新規(New)から
    1. 環境変数名: CUDNN_PATH
      値: C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN
      を登録 -> OK
    2. 環境変数名: Path
      値: C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN\bin
      を登録 -> OK

インストールの確認

  • command prompt から [where cudnn64_8.dll] を入力
    • C:\Program Files\NVIDIA GPU Computing Toolkit\cuDNN\bin\cudnn64_8.dll であれば正常にインストールできています
    • Could not find files for the given pattern(s). はPATH が通っていません

CUDAの動作確認

Anaconda Navigator

  • ENviroments -> Create -> 新規に環境を作成(例は py39-cuda)->Create
    image.png
  • Open Terminal から [conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch] を入力
    (pip では [pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116] となります)
    その他の環境(pipなど)は 下記へアクセスし,自分の環境にあったコマンドを入手してくださいね.

  • 選択肢が出たら [y] です,いろいろなライブラリをインストールしていきますのでかなり時間がかかります
  • Open with Python から [ import torch |ここでエンター| torch.cuda.is_available() ]を入力して,True が出力されれば正常にインストールされています.
    image.png
    以上です,お疲れ様でした.

参考

9
15
2

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
9
15