LoginSignup
3
0

More than 3 years have passed since last update.

Ubutnu 20.04インストールとVitis 2020.2とVitis AI 1.3関連の開発環境構築のメモ

Posted at

Ubutnu 20.04インストールとVitis 2020.2とVitis AI 1.3関連の開発環境構築のメモ

恒例の行事なので特別な作業はないが、2019.2とVitis AI 1.1の時と比べてXilinx環境の必要パッケージのインストールが楽になったり、gpu版のdocker環境構築でエラーが出たりしたので記事にしておく。

インストール先のPCのスペック

  • AMD Ryzen 5 3600
  • GeForce RTX 2060 SUPER

OSのインストール

USBのイメージが起動しない

Ubuntu 20.04 LTS 日本語 Remix リリースのページからisoファイルをダウンロードしてusbに書き込んでusbブートする。
isoファイルの書き込みは、rufusを使用した(choco install rufusでインストール)。

nvidiaのグラフィックスカードがついているとusbブートでも正しく起動できない。
grubの起動メニューで、eを押してコマンドを編集する必要がある。
linux行のquiet splashnomodesetに変更すると起動するようになる。

インストール中のパーティション編集でウィンドウが見えない

参考: Ubuntu18.04インストール時、パーティション作成画面のウィンドウの下部が隠れて操作が出来ない際の対処法

いったんインストール用の画面を閉じてから、ターミナルを起動してgnome-tweaksをインストールして起動。

sudo apt install gnome-tweaks
gnome-tweaks

フォント -> 倍率 の設定を 0.75 程度に変更することでウィンドウサイズが小さくなって、インストール中画面のすべてのボタン類が見えるようになる。

nvidiaの推奨ドライバをインストール

リポジトリを登録して、自動で推奨のドライバをインストールする。

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
sudo ubuntu-drivers autoinstall

自動でインストールしない場合、ubuntu-drivers devicesで使えるドライバを一覧できる。

$ ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:03.1/0000:08:00.0 ==
modalias : pci:v000010DEd00001F06sv00001462sd00008D93bc03sc00i00
vendor   : NVIDIA Corporation
model    : TU106 [GeForce RTX 2060 SUPER]
driver   : nvidia-driver-450-server - distro non-free
driver   : nvidia-driver-450 - distro non-free
driver   : nvidia-driver-440-server - distro non-free
driver   : nvidia-driver-460 - distro non-free recommended
driver   : xserver-xorg-video-nouveau - distro free builtin

手動でインストールする場合は以下。

sudo apt install nvidia-driver-460

homeフォルダ英語化

LANG=C xdg-user-dirs-gtk-update

ssh公開鍵登録

sftpなど適当な方法で公開鍵を持ってきて、配置する。

sudo apt install ssh
mv id_rsa.pub ~/.ssh/id_rsa.pub

Windows側の名前解決

sudo apt install samba winbind libnss-winbind

Windows側に参加出来るようにする。/etc/nsswitch.confwins追記

hosts:          files mdns4_minimal [NOTFOUND=return] dns wins

avahi-daemonがインストールされていない場合はインストールして起動する必要がある。

sudo apt install avahi-daemon
sudo systemctl start avahi-daemon

Windowsから見える共有フォルダ作成

sambaユーザを作成

sudo smbpasswd -a $USER

/etc/samba/smb.confを編集(変更のみ表示)

[global]
   unix charset = UTF-8
   dos charset = CP932

   interfaces = 127.0.0.0/8 enp0s3
   bind interfaces only = yes

;   map to guest = bad user

[homes]
   comment = Home Directories
   browseable = no
   writable = yes
   read only = no
   valid users = %S

# Shared HDD
[HDD]
   path = /mnt/HDD
   writable = yes
   readonly = no
   guest ok = yes
   guest only = yes

Windowsからリモートデスクトップ接続できるようにする

Ubuntu 20.04 LTSでxrdpを使用するを参考にしたが、独自スクリプトを実行させるようにしていた部分を.xsessionrcに書くように変更している。

# xrdpだけでなく、xserver-xorg-core xorgxrdpも必要らしい
# xserver-xorg-input-allがないとマウスキーボードが効かない
sudo apt install xserver-xorg-input-all xserver-xorg-core xorgxrdp xrdp

# Gnomeでログインできるようにする
# ただし、同時ログインはできない
cat <<EOF > ~/.xsessionrc
export GNOME_SHELL_SESSION_MODE=ubuntu
export XDG_CURRENT_DESKTOP=ubuntu:GNOME
export XDG_DATA_DIRS=/usr/share/ubuntu:/usr/local/share:/usr/share:/var/lib/snapd/desktop
export XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
EOF

# カーソル周りの不具合回避
sudo sed -e 's/^new_cursors=true/new_cursors=false/g' -i /etc/xrdp/xrdp.ini

# rename the redirected drives to 'shared-drives'
# 個人的にあまり気にならないのでそのままにした
# sudo sed -i -e 's/FuseMountName=thinclient_drives/FuseMountName=shared-drives/g' /etc/xrdp/sesman.ini

# Changed the allowed_users
sudo sed -i_orig -e 's/allowed_users=console/allowed_users=anybody/g' /etc/X11/Xwrapper.config

# Configure the policy xrdp session
cat <<EOF | sudo tee /etc/polkit-1/localauthority/50-local.d/45-allow-colord.pkla
[Allow Colord all Users]
Identity=unix-user:*
Action=org.freedesktop.color-manager.create-device;org.freedesktop.color-manager.create-profile;org.freedesktop.color-manager.delete-device;org.freedesktop.color-manager.delete-profile;org.freedesktop.color-manager.modify-device;org.freedesktop.color-manager.modify-profile
ResultAny=no
ResultInactive=no
ResultActive=yes
EOF

# https://askubuntu.com/questions/1193810/authentication-required-to-refresh-system-repositories-in-ubuntu-19-10
cat <<EOF | sudo tee /etc/polkit-1/localauthority/50-local.d/46-allow-update-repo.pkla
[Allow Package Management all Users]
Identity=unix-user:*
Action=org.freedesktop.packagekit.system-sources-refresh
ResultAny=yes
ResultInactive=yes
ResultActive=yes
EOF

# サービスを再起動
sudo systemctl restart xrdp
sudo systemctl restart polkit

Xilinxツール(2020.2)のインストール

事前にインストール先を作っておく。

sudo mkdir /opt/Xilinx
sudo chown $USER /opt/Xilinx
sudo mkdir /opt/petalinux
sudo mkdir /opt/petalinux/2020.2

インストール用のバイナリをダウンロードして、インストール。
必要なパッケージをインストールためのスクリプトも用意されているので実行。

# Vitisのインストール
chmod +x ./Xilinx_Unified_2020.2_1118_1232_Lin64.bin
./Xilinx_Unified_2020.2_1118_1232_Lin64.bin
# 必要なパッケージをインストール
sudo /opt/Xilinx/Vitis/2020.2/scripts/installLibs.sh


# petalinuxのインストール
chmod +x ./petalinux-v2020.2-final-installer.run
./petalinux-v2020.2-final-installer.run -d /opt/Xilinx/petalinux/2020.2

# 必要なパッケージをインストール
wget https://www.xilinx.com/Attachment/plnx-env-setup.sh
chmod +x plnx-env-setup.sh
./plnx-env-setup.sh

Vitis-AI関連

githubのVitis-AIページを見ながらインストールを進める。

docker

まずはdockerをdocker公式ページを見てインストールするとのこと。

sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

# Add GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# set up the stable repository
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

# install
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

動作確認してみる。

sudo docker run hello-world

管理者権限がないユーザーでもdockerを管理できるようにする。(dockerグループにユーザを加える)

# sudo groupadd docker
sudo usermod -aG docker $USER

一度ログアウトしてログインしな直して動作確認する。(sudoなしで実行できるかの確認)

docker run hello-world

Vitis-AI本体(docker環境)

git clone --recurse-submodules https://github.com/Xilinx/Vitis-AI
cd Vitis-AI

# CPU版/GPU版docker環境のビルド(CPU版はpullでも可)
cd setup/docker
./docker_build_cpu.sh
# docker pull xilinx/vitis-ai-cpu:latest
./docker_build_gpu.sh

# CPU/GPU版dokcer環境の実行
cd ../..
./docker_run.sh xilinx/vitis-ai-cpu:latest
./docker_run.sh xilinx/vitis-ai-gpu:latest
gpu版が以下のエラーで起動できないとき

動作確認用に、nvidia/cudaを実行してもダメ。
Docker(19.03)でgpu有効化してpytorchで訓練するまでやる(Ubuntu18.04)を参考に対処する。

$ docker run --rm --gpus all nvidia/cuda:10.0-cudnn7-runtime-ubuntu18.04 nvidia-smi
docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]].

上記のQiita記事ではNew Docker CLI API Support for NVIDIA GPUs under Docker Engine 19.03.0 Pre-Releaseを参考にしたらしいが、スクリプトの作成は不要だと思うので省略した。
以下のようにリポジトリを追加して、ランタイムをインストールする。(再起動が必要かも)

curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey | \
  sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-container-runtime/$(. /etc/os-release;echo $ID$VERSION_ID)/nvidia-container-runtime.list | \
  sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list
sudo apt-get update
sudo apt-get install nvidia-container-runtime

これで、正しく実行できる。

$ docker run --rm --gpus all nvidia/cuda:10.0-cudnn7-runtime-ubuntu18.04 nvidia-smi
Sun Jan 10 08:24:18 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.32.03    Driver Version: 460.32.03    CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce RTX 206...  Off  | 00000000:08:00.0  On |                  N/A |
| 40%   33C    P8    10W / 184W |     45MiB /  7973MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
+-----------------------------------------------------------------------------+

xilinx/vitis-ai-gpu:latestも問題なし。

$ ./docker_run.sh xilinx/vitis-ai-gpu:latest

...(ライセンスなどのプロンプト表示があるが、省略)

==========================================

__      ___ _   _                   _____
\ \    / (_) | (_)            /\   |_   _|
 \ \  / / _| |_ _ ___ ______ /  \    | |
  \ \/ / | | __| / __|______/ /\ \   | |
   \  /  | | |_| \__ \     / ____ \ _| |_
    \/   |_|\__|_|___/    /_/    \_\_____|

==========================================

Docker Image Version:  latest
Build Date: 2021-01-10
VAI_ROOT: /opt/vitis_ai

For TensorFlow Workflows do:
     conda activate vitis-ai-tensorflow
For Caffe Workflows do:
     conda activate vitis-ai-caffe
For Neptune Workflows do:
     conda activate vitis-ai-neptune
For PyTorch Workflows do:
     conda activate vitis-ai-pytorch
For TensorFlow 2.3 Workflows do:
     conda activate vitis-ai-tensorflow2
For Darknet Optimizer Workflows do:
     conda activate vitis-ai-optimizer_darknet
For Caffe Optimizer Workflows do:
     conda activate vitis-ai-optimizer_caffe
For TensorFlow 1.15 Workflows do:
     conda activate vitis-ai-optimizer_tensorflow
For LSTM Workflows do:
     conda activate vitis-ai-lstm
Vitis-AI /workspace >

XRT

2020.2向けのXRTのパッケージが用意されていないようなのでビルドする。
まずはソースコードをダウンロードして、それっぽいブランチをcheckoutしておく。

git clone https://github.com/Xilinx/XRT
cd XRT
git checkout origin/2020.2

Building the XRT Software Stackを参考にビルド。

# 依存パッケージなどをインストール
sudo ./src/runtime_src/tools/scripts/xrtdeps.sh
# ランタイムをビルド
cd build
./build.sh
# debパッケージ作成
cd build/Release
make package
# インストール
sudo dpkg -i xrt_202020.2.8.0_20.04-amd64-xrt.deb
# 必要なら、生成したdebを適当な場所においておく
cp xrt_202020.2.8.0_20.04-amd64-xrt.deb ~/Downloads/
3
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
3
0