1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GPUを使用するPodmanコンテナをOS起動直後に実行する場合の注意点

1
Posted at

はじめに

NVIDIA GPUを使用するPodmanコンテナをsystemdなどでOS起動直後に実行するケースがあると思います。Podmanでは、GPUへのアクセスにCDI(Container Device Interface)を利用することが推奨されていますが、OS起動直後にコンテナを実行しようとすると、CDIのエラーが出ることがあり、本記事ではその対処法を示します。

目次

PodmanコンテナでGPUを使用する設定

PodmanコンテナでGPUを使用する場合、CDIを利用することが推奨されています。
CDIを設定するには、nvidia-ctk コマンドを使用して、GPUのデバイス情報を生成します。

# nvidia-ctk cdi generate --output=/etc/cdi/nvidia.yaml

デバイス情報生成後、listするとデバイスを確認できます。

# nvidia-ctk cdi list

INFO[0000] Found 3 CDI devices
nvidia.com/gpu=0
nvidia.com/gpu=GPU-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
nvidia.com/gpu=all

OS起動直後のコンテナ実行時のエラー

CDIを設定後、PodmanコンテナをOS起動直後に実行したところ、以下のエラーにより、コンテナの起動に失敗する事象が発生しました。

Error: unable to start container "xxxxxx": setting up CDI devices: 
failed to inject devices: failed to stat CDI host device "/dev/nvidia-uvm": 
no such file or directory

コンテナ実行エラーの対処法

上記のエラーは /dev/nvidia-uvm の準備ができていないことが原因のようで、先にnvidia-smiコマンドを実行することにより、この問題を回避できそうです。そのため、例えば以下のようにsystemdの設定ファイルにおいて、ExecStartPre=/usr/bin/nvidia-smi を設定しておくことにより、CDIを使用するPodmanコンテナをOS直後に起動できるようになりました。

[Unit]
Description="Podman container"
Requires=podman.socket
Wants=network.target
After=network-online.target
After=podman.socket
[Service]
User=root
WorkingDirectory=/root
ExecStartPre=/usr/bin/nvidia-smi
ExecStart=podman start container
ExecStop=podman stop container
Restart=on-failure
RemainAfterExit=true
KillMode=none
[Install]
WantedBy=multi-user.target
Also=podman.socket

まとめ

CDIを利用したPodmanコンテナをOS起動直後に実行しようとすると初期化エラーが起きることがあり、コンテナ実行の前にnvidia-smiを実行することでエラーを回避できることが分かりました。

参考文献

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?