Vitis AI 2.5 环境搭建(Ubuntu20.04) + 在 KV260 中配置 PYNQ

目录

1. 环境

2. 工具及版本介绍

2.1 工具版本兼容性

2.2 DPU结构

2.3 DPU命名规则

3. Vitis AI 配置要点

3.1 配置安装 Docker Repo

3.2 Install Docker Engine

3.3 配置 docker hub mirror

3.4 添加 Docker 用户组并测试

3.5 克隆 Vitis AI 库

3.6 构建 Docker

3.6.1 Docker 常用命令

3.6.2 从 docker hub 查找镜像

3.6.3 使用预构建的镜像

3.6.4 从 Recipes 构建镜像

3.7 运行 Docker

3.8 激活 conda 环境

3.9 配置 Jupyter Lab

4. PYNQ for KV260 配置要点

4.1 烧录 Ubuntu 22.04 LTS

4.2 配置网络

4.3 关闭图形桌面

4.4 添加 AMD 软件源并更新升级 Kernel

4.5 配置 Docker (optional)

4.6 安装 xrt zocl driver (optional)

4.7 安装 Pynq (需配置代理)

4.8 Jupyter Lab 安装中文支持包

4.9 域名解析

5. 补充说明

5.1 git 直接下载 zip

5.2 Docker 代理

5.3 保存修改的 Docker 容器


1. 环境

Host: Ubuntu 22.04.4 LTS

Embeded: kv260 with Ubuntu 22.04

AMD KV260 starts with Ubuntu 22.04https://www.amd.com/zh-cn/products/system-on-modules/kria/k26/kv260-vision-starter-kit/getting-started-ubuntu/getting-started.html

2. 工具及版本介绍

GitHub - Xilinx/Vitis-AI at 2.5Vitis AI is Xilinx’s development stack for AI inference on Xilinx hardware platforms, including both edge devices and Alveo cards. - GitHub - Xilinx/Vitis-AI at 2.5https://github.com/Xilinx/Vitis-AI/tree/2.5

2.1 工具版本兼容性

IP and Tool Version Compatibility — Vitis™ AI 3.0 documentation

Software Tools VersionDPUCDZX8G IP VersionViTis AI Release Version
Vivado / Vitis / Petalinux 2022.24.1v3.0
Vivado / Vitis / Petalinux 2022.14v2.5
Vivado / Vitis / Petalinux 2021.23.4v2.0
Vivado / Vitis / Petalinux 2021.13.3v1.4
Vivado / Vitis / Petalinux 2020.23.3v1.3
Vivado / Vitis / Petalinux 2020.13.2v1.2
Vivado / Vitis / Petalinux 2019.23.2v1.1
Vivado / Vitis / Petalinux 2019.13.1v1.0
Vivado / Petalinux 2019.13N/A
Vivado / Petalinux 2018.22N/A
Vivado / Petalinux 2018.11First Release

PYNQ for Kria SOMs:

PYNQ for Kria SOMsPYNQ support and examples for Kria SOMs. Contribute to Xilinx/Kria-PYNQ development by creating an account on GitHub.https://github.com/Xilinx/Kria-PYNQ

DPU-PYNQ (v2.5)
This overlay contains a Vitis-AI 2.5.0 Deep Learning Processor Unit (DPU) and comes with a variety of notebook examples with pre-trained ML models.

Supported boards: KV260, KR260, KD240

从官方给的信息可以看出,KV260 PYNQ Installation 使用的是 Vitis-AI 2.5.0,对应的工具版本Vivado / Vitis / Petalinux 2022.1。

2.2 DPU结构

2.3 DPU命名规则

KV260使用DPUCZDX8G IP,表示:

应用领域:CNN

硬件平台:Zynq DDR

量化方法:decent

Decent:一种量化与优化工具,主要用于对神经网络模型进行压缩和量化,以适配于赛灵思的DPU硬件。Decent支持多种量化策略,包括定点量化(通常为INT8量化)。这种工具的目的是通过减小模型的存储与计算需求来优化执行效率,同时尽量保持推理精度。
Integer threshold:一种量化方法,使用整数阈值来确定量化的位宽和位置。
Float threshold:这种方法使用浮点数阈值来进行量化,与整数阈值类似,但使用的是浮点数。
RNN:循环神经网络(Recurrent Neural Network)的缩写,这是一种用于处理序列数据的神经网络结构,通常在量化时需要特别考虑,因为它们的时间依赖性。

量化精度:8 bit

设计目标:通用

3. Vitis AI 配置要点

3.1 配置安装 Docker Repo

  • 安装必要的包
sudo apt update
sudo apt install ca-certificates curl
  • 添加 Docker 的官方 GPG 密钥
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
  • 设置镜像源,更新包索引
echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update

在国内访问 docker 官方源可能会存在问题:

Err:7 https://download.docker.com/linux/ubuntu focal InRelease                
  Cannot initiate the connection to download.docker.com:443 (2a03:2880:f10d:83:face:b00c:0:25de). - connect (101: Network is unreachable) Could not connect to download.docker.com:443 (128.121.146.228). - connect (113: No route to host)
Reading package lists... Done                                              
Building dependency tree       
Reading state information... Done
All packages are up to date.
W: Failed to fetch https://download.docker.com/linux/ubuntu/dists/focal/InRelease  Cannot initiate the connection to download.docker.com:443 (2a03:2880:f10d:83:face:b00c:0:25de). - connect (101: Network is unreachable) Could not connect to download.docker.com:443 (128.121.146.228). - connect (113: No route to host)
W: Some index files failed to download. They have been ignored, or old ones used instead.

请更改国内的源,以阿里源为例:

  • 添加阿里的 GPG 密钥
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  •  设置阿里的镜像源,更新包索引
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update

成功更新包索引后:

Get:1 https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal InRelease [57.7 kB]
..
Get:6 https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal/stable amd64 Packages [48.0 kB]
..
Fetched 233 kB in 2s (94.0 kB/s)
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.

参考:Install Docker Engine on Ubuntu | Docker Docs 

3.2 Install Docker Engine

sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

作用,安装 Docker 及其相关组件: 

  • docker-ce:安装 Docker 社区版(Community Edition)。
  • docker-ce-cli:安装 Docker 命令行工具。
  • containerd.io:安装 containerd,这是一个用于管理容器生命周期的守护进程。
  • docker-buildx-plugin:安装 Docker Buildx 插件,用于构建多架构镜像。
  • docker-compose-plugin:安装 Docker Compose 插件,用于定义和运行多容器 Docker 应用。

3.3 配置 docker hub mirror

使用代理:参见 5.2 Docker 代理。

或者使用国内镜像源

新建或者修改 /etc/docker/daemon.json 文件,追加以下内容:

{
    "registry-mirrors": ["http://hub-mirror.c.163.com"]
}
  • 网易:http://hub-mirror.c.163.com

  • 中科大:http://mirrors.ustc.edu.cn

重新加载 systemd 单元文件,并重启 docker 守护进程:

systemctl daemon-reload
systemctl restart docker

3.4 添加 Docker 用户组并测试

sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker

运行:docker run hello-world,进行测试。(重启 Ubuntu 系统,以使配置生效)

没有添加权限组,运行失败:

ubuntu:$ docker run hello-world
docker: permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Head "http://%2Fvar%2Frun%2Fdocker.sock/_ping": dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.

运行成功的结果:

ubuntu:$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

3.5 克隆 Vitis AI 库

git clone -b 2.5 --single-branch https://github.com/Xilinx/Vitis-AI.git
cd Vitis-AI

这里安装 Vitis AI 2.5 版本是基于 KV260 的 PYNQ 配置而定的。

Kria-PYNQPYNQ support and examples for Kria SOMs. Contribute to Xilinx/Kria-PYNQ development by creating an account on GitHub.https://github.com/Xilinx/Kria-PYNQ

3.6 构建 Docker

3.6.1 Docker 常用命令

列出本地镜像:

ubuntu:$ docker images
REPOSITORY            TAG       IMAGE ID       CREATED         SIZE
hello-world           latest    9c7a54a9a43c   14 months ago   13.3kB

列出正在运行的容器:

docker ps

删除镜像(强制):

docker rmi -f <镜像ID或镜像名称>

查看镜像详细信息:

docker inspect <镜像ID或镜像名称>

保存镜像到文件:

docker save -o <文件名.tar> <镜像名称>

从文件加载镜像:

docker load -i <文件名.tar>

3.6.2 从 docker hub 查找镜像

 Docker hubhttps://hub.docker.com/search?q=xilinx+vitis

 

3.6.3 使用预构建的镜像

使用代理:参见 5.2 Docker 代理。

参考 Vitis AI 2.5 的 github 说明:

Vitis AI 2.5https://github.com/Xilinx/Vitis-AI/tree/2.5

对于 Vitis AI 2.5,请直接使用这条命令抓取即可: 

docker pull xilinx/vitis-ai-cpu:latest

注意,使用 Vitis AI 2.5 版本,与之后的 Vitis AI 3.0 和  Vitis AI 3.5 有一些区别,后者对于 pytorch 和 tensorflow、tensorflow2 均有不同的的 docker 镜像,而前者只有一个。

Vitis AI 3.0 Pre-built Container Options

3.6.4 从 Recipes 构建镜像

对于 Vitis AI 2.5 版本:

  • CPU Docker
cd docker
./docker_build_cpu.sh

运行 CPU docker

./docker_run.sh xilinx/vitis-ai-cpu:latest
  • GPU Docker

如果使用了 GPU,则需要自行构建 docker 镜像:

cd docker
./docker_build_gpu.sh

 运行 CPU docker

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

3.7 运行 Docker

./docker_run.sh xilinx/vitis-ai-cpu:latest
ubuntu@ubuntu:$ ./docker_run.sh xilinx/vitis-ai-cpu:latest
Setting up ubuntu's environment in the Docker container...
usermod: no changes
Running as vitis-ai-user with ID 0 and group 0 


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

Docker Image Version: 2.5.0.1260   (CPU) 
Vitis AI Git Hash: 502703c 
Build Date: 2022-06-12

For TensorFlow 1.15 Workflows do:
     conda activate vitis-ai-tensorflow 
For PyTorch Workflows do:
     conda activate vitis-ai-pytorch 
For TensorFlow 2.8 Workflows do:
     conda activate vitis-ai-tensorflow2 
For WeGo Tensorflow 1.15 Workflows do:
     conda activate vitis-ai-wego-tf1 
For WeGo Tensorflow 2.8 Workflows do:
     conda activate vitis-ai-wego-tf2 
For WeGo Torch Workflows do:
     conda activate vitis-ai-wego-torch 
Vitis-AI /workspace > 

出现如上结果,表示启动docker成功,留意版本信息。

3.8 激活 conda 环境

找到对应的深度学习框架,并激活相应的环境:

For TensorFlow 1.15 Workflows do:
     conda activate vitis-ai-tensorflow 
For PyTorch Workflows do:
     conda activate vitis-ai-pytorch 
For TensorFlow 2.8 Workflows do:
     conda activate vitis-ai-tensorflow2 
For WeGo Tensorflow 1.15 Workflows do:
     conda activate vitis-ai-wego-tf1 
For WeGo Tensorflow 2.8 Workflows do:
     conda activate vitis-ai-wego-tf2 
For WeGo Torch Workflows do:
     conda activate vitis-ai-wego-torch 

例如,激活 tensorflow2 请使用命令:

conda activate vitis-ai-tensorflow2

激活 pytorch 请使用命令:

conda activate vitis-ai-pytorch

激活完毕,会显示对应的环境信息:

(vitis-ai-tensorflow2) Vitis-AI /workspace >

3.9 配置 Jupyter Lab

  • jupyter --version # 查看是否安装 jupyterlab
(vitis-ai-tensorflow2) Vitis-AI /workspace > jupyter --version
Selected Jupyter core packages...
IPython          : 7.33.0
ipykernel        : 6.13.1
ipywidgets       : 7.7.0
jupyter_client   : 7.3.4
jupyter_core     : 4.10.0
jupyter_server   : not installed
jupyterlab       : not installed
nbclient         : 0.6.4
nbconvert        : 6.5.0
nbformat         : 5.4.0
notebook         : 6.4.12
qtconsole        : 5.3.1
traitlets        : 5.2.2

安装 jupyterlab: 

pip install jupyterlab

或者使用临时国内安装源(速度快):

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple jupyterlab

再次查看版本信息:

(vitis-ai-tensorflow2) Vitis-AI /workspace > jupyter --version
Selected Jupyter core packages...
IPython          : 7.33.0
ipykernel        : 6.13.1
ipywidgets       : 7.7.0
jupyter_client   : 7.3.4
jupyter_core     : 4.12.0
jupyter_server   : 1.24.0
jupyterlab       : 3.6.7
nbclient         : 0.6.4
nbconvert        : 6.5.0
nbformat         : 5.4.0
notebook         : 6.4.12
qtconsole        : 5.3.1
traitlets        : 5.9.0

可见所有模块已经安装完毕。 

接下来进入 jupyter lab。

启动 Vitis AI

(vitis-ai-tensorflow2) Vitis-AI /workspace > jupyter lab
...
  _   _          _      _
 | | | |_ __  __| |__ _| |_ ___
 | |_| | '_ \/ _` / _` |  _/ -_)
  \___/| .__/\__,_\__,_|\__\___|
       |_|
                                                                           
Read the migration plan to Notebook 7 to learn about the new features and the actions to take if you are using extensions.

...
    
    To access the server, open this file in a browser:
        file:///home/vitis-ai-user/.local/share/jupyter/runtime/jpserver-131-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/lab?token=fc22846b34c116e5c8ab1dd216527ba34444e42a7d409746
     or http://127.0.0.1:8888/lab?token=fc22846b34c116e5c8ab1dd216527ba34444e42a7d409746

复制链接地址,在浏览器中打开:

可选,安装中文界面: 

pip install jupyterlab-language-pack-zh-CN

注意,安装中文支持包,需要直接在 jupyterlab 的终端中运行命令。

4. PYNQ for KV260 配置要点

4.1 烧录 Ubuntu 22.04 LTS

烧录 Ubuntu 22.04 LTShttps://www.amd.com/zh-cn/products/system-on-modules/kria/k26/kv260-vision-starter-kit/getting-started-ubuntu/getting-started.html

4.2 配置网络

4.3 关闭图形桌面

xmutil desktop_disable

4.4 添加 AMD 软件源并更新升级 Kernel

sudo add-apt-repository ppa:xilinx-apps
sudo add-apt-repository ppa:ubuntu-xilinx/sdk
sudo apt update
sudo apt upgrade

4.5 配置 Docker (optional)

sudo groupadd docker
sudo usermod -a -G docker  $USER
newgrp docker

4.6 安装 xrt zocl driver (optional)

sudo apt install xrt-dkms

4.7 安装 Pynq (需配置代理)

配置代理,请参见4.2 配置网络章节。

  1. git clone https://github.com/Xilinx/Kria-PYNQ.git
  2. cd Kria-PYNQ
  3. 需要修改 install.sh 文件,branch 分支版本问题。
  4. sudo bash install.sh -b KV260

4.8 Jupyter Lab 安装中文支持包

  1. pip install jupyterlab-language-pack-zh-CN

4.9 域名解析

  1. 打开 C:\Windows\System32\drivers\etc\hosts 文件。
  2. 添加:192.168.101.224 kria

5. 补充说明

5.1 git 直接下载 zip

从 GitHub 直接下载 ZIP 文件不会包含 .git 文件夹。ZIP 文件只包含项目的当前文件内容,而不包括版本控制信息。如果你需要完整的 Git 仓库,包括所有的版本历史和 .git 文件夹,建议使用 git clone 命令来克隆仓库。

5.2 Docker 代理

docker pull 命令不会使用 terminal 代理设置,因为 docker pull 是由 Docker 守护进程(dockerd)执行的,而不是直接在你的终端会话中运行的。因此,需要为 Docker 守护进程配置代理。

  • 创建配置目录和文件
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo touch /etc/systemd/system/docker.service.d/proxy.conf
  • 编辑 proxy.conf 文件,添加以下内容
[Service]
Environment="HTTP_PROXY=http://localhost:20170"
Environment="HTTPS_PROXY=http://localhost:20171"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"
  • 重新加载 systemd 配置并重启 Docker
sudo systemctl daemon-reload
sudo systemctl restart docker

5.3 保存修改的 Docker 容器

如果对 Docker 容器进行了修改,需要通过以下步骤进行保存:

1. 查找容器 ID 或名称:

ubuntu:$ docker ps
CONTAINER ID   IMAGE                        COMMAND   CREATED          STATUS          PORTS     NAMES
79bf77d93196   xilinx/vitis-ai-cpu:latest   "bash"    39 minutes ago   Up 39 minutes             boring_nightingale

2. 提交容器为新的镜像,使用 docker commit 命令将容器的当前状态保存为新的镜像:

docker commit [CONTAINER_ID_OR_NAME] [new_image_name]:[tag]

比如:

ubuntu:$ docker commit 79bf77d93196 xilinx/vitis-ai-cpu:240805
sha256:99025d86bf237dcc8b36f0663b1d12d0b08cc1cce3cb8084f9fda6043ad8cd09

3. 验证新镜像:

docker images

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值