11
5

Ubuntu 24.04@WSL2にCUDAをインストールする(libtinfo5が見つからない問題)

Posted at

まとめ

  • 2024/4/29現在、以下のコマンドでCUDAをWSL2上のUbuntu 24.04 LTSにインストールできます

$ wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.1-1_all.deb

$ sudo dpkg -i cuda-keyring_1.1-1_all.deb

$ sudo tee /etc/apt/sources.list.d/jammy.list << EOF
deb http://archive.ubuntu.com/ubuntu/ jammy universe
EOF

$ sudo tee /etc/apt/preferences.d/pin-jammy <<EOF
Package: *
Pin: release n=jammy
Pin-Priority: -10

Package: libtinfo5
Pin: release n=jammy
Pin-Priority: 990
EOF

$ sudo apt-get update

$ sudo apt-get -y install cuda-toolkit

問題

(以下の問題は、今後修正される可能性が高いです)

$ wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.1-1_all.deb
$ sudo dpkg -i cuda-keyring_1.1-1_all.deb
$ sudo apt-get update
$ sudo apt-get install cuda-toolkit
  • しかし、実際にインストールをしてみると最後にcuda-toolkitをインストールするステップで以下のようなエラーが発生してしまいます
$ sudo apt install cuda-toolkit
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 nsight-systems-2023.4.4 : Depends: libtinfo5 but it is not installable
E: Unable to correct problems, you have held broken packages.

  • nsight-systemsのパッケージと依存関係があるlibtinfo5のインストールに失敗してしまっているようです

原因

image.png

  • そのため、apt installによって自動的に依存関係を解決、ダウンロードすることができなくなってしまっています

対応

  • 対応策はいくつか考えられます
  1. libtinfo5のdebファイルを手動でダウンロード、インストールする
  2. libtinfo5を含む古いubuntuバージョンのレポジトリを追加する
  • ここでは2の、古いUbuntuバージョンのレポジトリを追加する方法をとることとします

  • まずは、Ubuntu 22.04 LTSのレポジトリを登録します

$ sudo tee /etc/apt/sources.list.d/jammy.list << EOF
deb http://archive.ubuntu.com/ubuntu/ jammy universe
EOF
  • 次に、Ubuntu 22.04 LTSのレポジトリの優先度を、libtinfo5のパッケージでは高く、ほかのパッケージでは低く設定します
    • これによりlibtinfo5以外のパッケージが、Ubuntu 22.04で提供されていた古いバージョンでインストールされることを防いでいます
    • (このステップは無くてもおそらく問題はありません。)
$ sudo tee /etc/apt/preferences.d/pin-jammy <<EOF
Package: *
Pin: release n=jammy
Pin-Priority: -10

Package: libtinfo5
Pin: release n=jammy
Pin-Priority: 990
EOF
  • あとは通常通り、apt update と apt install を行えば cuda をインストールすることができます!
$ sudo apt-get update
$ sudo apt-get -y install cuda-toolkit

動作確認

  • CUDAが動作しているかどうかは、次のようなpythonプログラムで検証できます
import torch

if torch.cuda.is_available():
    print("CUDA is available!")
    print("Device count:", torch.cuda.device_count())
    for i in range(torch.cuda.device_count()):
        print(f"Device {i}: {torch.cuda.get_device_name(i)}")
else:
    print("CUDA is not available.")

  • 次のような実行結果がでればCUDAが正しくインストールされています

11
5
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
11
5