欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > Versal - 基础6(Linux 开发 AIE-ML + 自动化脚本解析)

Versal - 基础6(Linux 开发 AIE-ML + 自动化脚本解析)

2025/2/23 13:26:01 来源:https://blog.csdn.net/DongDong314/article/details/145759070  浏览:    关键词:Versal - 基础6(Linux 开发 AIE-ML + 自动化脚本解析)

目录

1. 简介

2. 步骤解析

2.1 概览

2.1.1 步骤依赖关系

2.1.2 总目录结构

2.2 Vitis XPFM

2.2.1 Dir

2.2.2 Makefile

2.2.3 vitis_pfm.py

2.3 Kernels

2.3.1 Dir

2.3.2 Makefile

2.3.3 config 文件

2.4 AIE_app

2.4.1 Dir

2.4.2 Makefile

2.4.3 aie 要点

2.5.1 Link 概要

2.5.2 Makefile

2.5.3 system.cfg

2.6 Host_app

2.6.1 Dir

2.6.2 sdk

2.6.2 Makefile

2.7 Package

2.8 在硬件中运行

2.8.1 烧写

2.8.2 运行

3. All Makefile

4. 总结


1. 简介

本文以官方 AIE/Feature_Tutorials/09-debug-walkthrough/ 示例为基准,在 VD100 硬件平台上实现 Linux 开发 AIE,并分析自动化脚本。

Feature_Tutorials/09-debug-walkthrough /cmd_src/https://github.com/Xilinx/Vitis-Tutorials/tree/2024.1/AI_Engine_Development/AIE/Feature_Tutorials/09-debug-walkthrough/cmd_src

同时参考 XD101 文档:《Vitis Tutorials: Vitis Platform Creation (XD101)》
Vitis Tutorials: Vitis Platform Creation (XD101)https://docs.amd.com/r/2024.1-English/Vitis-Tutorials-Vitis-Platform-Creation/Customize-Root-File-System-Kernel-Device-Tree-and-U-boot

2. 步骤解析

2.1 概览

2.1.1 步骤依赖关系

  • Vivado XSA
    • 输入:HW Design
    • 输出:Vivado XSA
  • Petalinux
    • 输入:Vivado XSA
    • 输出:Linux 镜像
  • Vitis XPFM
    • 输入:Vivado XSA、Linux 镜像(通用镜像 或者 petalinux)
    • 输出:Vitis platform(*.xpfm)
  • Kernels
    • 输入:.xpfm、s2mm.cpp、s2mm.cfg、mm2s.cpp、mm2s.cfg
    • 输出:s2mm.xo、mm2s.xo
  • AIE_app
    • 输入:.xpfm、aie 目录所有文件(.cpp / .cc / .h)
    • 输出:libadf.a
  • Vpp_link_XSA
    • 输入:.xpfm、s2mm.xo、mm2s.xo、libadf.a
    • 输出:binary_container_1.xsa
  • Host_app
    • 输入:Linux 镜像(sdk)、host.cpp
    • 输出:host.exe
  • Package
    • ​​​​​​​输入:.xpfm、Linux 镜像、host.exe、binary_container_1.xsa、libadf.a
    • 输出:sd_card.img

2.1.2 总目录结构

├── aie
│   ├── graph.cpp
│   ├── graph.h
│   └── kernels
│       ├── data_shuffle.cc
│       ├── kernels.h
│       ├── peak_detect.cc
│       └── upscale.cc
├── data
│   └── inx.txt
├── Makefile
├── platform
│   ├── Makefile
│   ├── petalinux
│   │   ├── vd100
│   │   └── vd100_ex_pfm.xsa
│   └── vitis_pfm.py
├── pl_kernels
│   ├── mm2s.cfg
│   ├── mm2s.cpp
│   ├── s2mm.cfg
│   └── s2mm.cpp
├── sw
│   ├── data.h
│   ├── embedded_exec.sh
│   └── host.cpp
└── system.cfg

2.2 Vitis XPFM

2.2.1 Dir

├── Makefile
├── petalinux
│   ├── vd100
│   │   ├── build
│   │   ├── components
│   │   ├── images
│   │   └── project-spec
│   └── vd100_ex_pfm.xsa
└── vitis_pfm.py

1)在 images/linux 目录下,有重要的组件:

NameDescriptionComponent
ImageLinux kernel ImageLinux Software Components
rootfs.ext4Linux file systemLinux Software Components
sysrootCross compile and header filesLinux SDK
boot.scrU-boot configuration file to store in FAT32 partition of SD cardFAT32 partition
bl31.elfArm trusted firmware / secure monitorBOOT.BIN
u-boot.elfSecond stage boot loaderBOOT.BIN
system.dtbDevice tree information fileBOOT.BIN

注:内核映像、Linux 文件系统和 Sysroot 并非 Vitis 平台本身必需的组件,它们用于编译应用程序和生成 SD 卡映像。

2)通用镜像下载地址

Common Images for Embedded Vitis Platforms - 2024.1 Vivado, Vitis, Vitis Embedded Platform, PetaLinux, Device modelshttps://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/embedded-platforms/2024-1.html通用镜像包不包括 DTB 文件,因此需要额外步骤使用 createdts 命令生成设备树文件。

2.2.2 Makefile

1)本级 Makefile

.PHONY: vitis_pfm clean check_vitisvitis_pfm: check_vitisvitis -s vitis_pfm.pyclean:rm -rf ./vitis_pfm/check_vitis:@command -v vitis > /dev/null 2>&1 || { echo >&2 "Source Vitis Settings first."; exit 1; }

2)上级 Makefile

###########################################################################
RELATIVE_PATH := /platform/vitis_pfm/platform/export/platform/platform.xpfm
VITIS_PLATFORM := $(CURDIR)$(RELATIVE_PATH)vitis_platform: $(VITIS_PLATFORM)$(VITIS_PLATFORM):$(MAKE) vitis_pfm -C platform
###########################################################################

$(MAKE) :是一个特殊的变量,它引用当前正在使用的 make 工具的命令。

代码作用:从当前的 Makefile 中,切换到 platform 目录,递归地调用 make 命令,并在那个目录的 Makefile中执行 vitis_pfm 目标。

2.2.3 vitis_pfm.py

import vitisclient = vitis.create_client()
client.set_workspace(path="./vitis_pfm")platform = client.create_platform_component(name = "platform",hw_design = "./petalinux/vd100_ex_pfm.xsa",os = "linux",cpu = "psv_cortexa72",domain_name = "linux_psv_cortexa72")domain = platform.add_domain(cpu = "ai_engine", os = "aie_runtime", name = "aie_app", display_name = "aie_app")domain = platform.get_domain(name="linux_psv_cortexa72")status = domain.generate_bif()status = domain.set_qemu_args(qemu_option="PS", path="./vitis_pfm/platform/resources/linux_psv_cortexa72/qemu/qemu_args.txt")
status = domain.set_qemu_args(qemu_option="PMC", path="./vitis_pfm/platform/resources/linux_psv_cortexa72/qemu/pmc_args.txt")
status = domain.set_bif(path="./vitis_pfm/platform/resources/linux_psv_cortexa72/linux.bif")
status = domain.set_dtb(path="./petalinux/vd100/images/linux/system.dtb")
status = domain.set_boot_dir(path="./petalinux/vd100/images/linux")status = platform.build()
  • domain.generate_bif() 用于生成 linux.bif 文件。文件内容如下:
/* linux */
the_ROM_image:
{{ load=0x1000, file=<dtb,boot/system.dtb> }{ core=a72-0, exception_level=el-3, trustzone, file=<atf,boot/bl31.elf> }{ core=a72-0, exception_level=el-2, load=0x8000000, file=<uboot,boot/u-boot.elf> }
}

2.3 Kernels

2.3.1 Dir

├── pl_kernels
│   ├── mm2s.cfg
│   ├── mm2s.cpp
│   ├── s2mm.cfg
│   └── s2mm.cpp

2.3.2 Makefile

######################################################
VPP_XO_FLAGS := --compile   \--mode hls  \--platform $(VITIS_PLATFORM)kernels: ./pl_kernels/s2mm.xo ./pl_kernels/mm2s.xo./pl_kernels/s2mm.xo:v++ $(VPP_XO_FLAGS) --config ./pl_kernels/s2mm.cfg./pl_kernels/mm2s.xo:v++ $(VPP_XO_FLAGS) --config ./pl_kernels/mm2s.cfg
######################################################

2.3.3 config 文件

1)s2mm.cfg

[hls]
flow_target=vitis
syn.file=./s2mm.cpp
syn.cflags=-I.
syn.top=s2mm
syn.debug.enable=1
package.ip.name=s2mm
package.output.syn = true
package.output.format=xo
package.output.file=s2mm.xo

2)mm2s.cfg

[hls]
flow_target=vitis
syn.file=./mm2s.cpp
syn.cflags=-I.
syn.top=mm2s
syn.debug.enable=1
package.ip.name=mm2s
package.output.syn = true
package.output.format=xo
package.output.file=mm2s.xo

2.4 AIE_app

2.4.1 Dir

├── aie
│   ├── graph.cpp
│   ├── graph.h
│   └── kernels
│       ├── data_shuffle.cc
│       ├── kernels.h
│       ├── peak_detect.cc
│       └── upscale.cc

2.4.2 Makefile

############################################################
AIE_INCLUDES := --include "./aie"          \--include "./data"         \--include "./aie/kernels"  \--include "./"             \--include "$(XILINX_VITIS)/aietools/include"aie: ./libadf.a./libadf.a:v++ --compile                       \--mode aie                      \--target hw                     \--platform $(VITIS_PLATFORM)    \--work_dir "./Work"             \$(AIE_INCLUDES)                 \--input_files "./aie/graph.cpp"@echo "COMPLETE: libadf.a created."
############################################################

2.4.3 aie 要点

在 Vitis 平台中编译和连接 AI Engine ADF Graph 的要点:

1)ADF Graph 与 Vitis PFM 的连接:

  • ADF Graph 可以与 Vitis Extensible Platform 连接。
  • Graph 的输入/输出(I/O)可以通过 v++ 连接指令连接到平台端口或 Vitis 内核的端口。

2)AI Engine ADF C++ Graph 的组成:

  • AI Engine ADF C++ Graph 仅包含 AI Engine 内核。
  • AI Engine 内核之间的所有互连都在 C++ Graph(project.h)中定义。

3)外部I/O的连接:

  • 所有与外部I/O的连接都在C++仿真测试平台(graph.cpp)中完全指定,该测试平台实例化了C++ ADF图对象。
  • 从 Graph 到 PLIO(Programmable Logic I/O)的所有平台连接都映射到 AI Engine 子系统图的端口上,这些端口通过 v++ 连接指令进行连接。

4)v++的限制:

  • v++ 不允许存在悬空端口或隐式连接。

5)流连接的指定:

  • 流连接通过 v++ 的 --sc 选项指定。
  • 可以使用基于 PL 的 Data Mover,这些 Data Mover 可以在平台中定义,也可以在 ADF Graph 外部定义为 Vitis PL 内核。

2.5.1 Link 概要

在 AIE_app、PL kernel 完成编译和模拟后,可以使用 v++ 将它们与平台链接起来,以生成一个 .xsa 文件。

2.5.2 Makefile

##############################################################
xsa: ./binary_container_1.xsa./binary_container_1.xsa:v++ --link                                \--target hw                           \--platform $(VITIS_PLATFORM)          \--config "./system.cfg"               \--output "./binary_container_1.xsa"   \--input pl_kernels/s2mm.xo pl_kernels/mm2s.xo libadf.a@echo "COMPLETE: .xsa created."
##############################################################

2.5.3 system.cfg

system.cfg 中的内容:

debug=1
save-temps=1
temp_dir=binary_container_1
report_dir=binary_container_1/reports
log_dir=binary_container_1/logs[advanced]
misc=solution_name=binary_container_1
param=compiler.addOutputTypes=hw_export[connectivity]
nk=mm2s:1:mm2s
nk=s2mm:2:s2mm_1.s2mm_2
sc=mm2s.s:ai_engine_0.inx
sc=ai_engine_0.data_shuffle:s2mm_1.s
sc=ai_engine_0.upscale_out:s2mm_2.s

2.6 Host_app

2.6.1 Dir

├── sw
│   ├── data.h
│   ├── embedded_exec.sh
│   └── host.cpp

2.6.2 sdk

1)Source ENV

与 sw_emu 中使用 g++ 编译器编译 host 不同,在 hw/hw_emu 中,需要使用 Arm cross-compiler aarch64-xilinx-linux-g++。因此需要使用 sdk。

source ./platform/petalinux/vd100/images/linux/sdk/environment-setup-cortexa72-cortexa53-xilinx-linux

2)CXX 已包含的内容:

>> echo $CXX
---
aarch64-xilinx-linux-g++         \-mcpu=cortex-a72.cortex-a53  \-march=armv8-a+crc           \-fstack-protector-strong     \-O2                          \-D_FORTIFY_SOURCE=2          \-Wformat                     \-Wformat-security            \-Werror=format-security      \--sysroot=<sdk>/sysroots/cortexa72-cortexa53-xilinx-linux

2.6.2 Makefile

#############################################################
GCC_FLAGS := -Wall -c -g \-std=c++17 -Wno-int-to-pointer-castGCC_INCLUDES = -I$(SDKTARGETSYSROOT)/usr/include/xrt \-I$(SDKTARGETSYSROOT)/usr/include     \-I./GCC_LIB := -lxrt_coreutilhost: ./sw/host.exe./sw/host.exe: ./sw/host.cppcd ./sw$(CXX) $(GCC_FLAGS) $(GCC_INCLUDES) -o host.o host.cpp$(CXX) *.o $(GCC_LIB) -std=c++17 -o host.exe@echo "COMPLETE: Host application created."
#############################################################

2.7 Package

1)Makefile

###########################################################################
ROOTFS = $(CURDIR)/platform/petalinux/vd100/images/linux/rootfs.ext4
IMAGE = $(CURDIR)/platform/petalinux/vd100/images/linux/Imagepackage: ./sw/sd_card.img./sw/sd_card.img:cd ./swv++ --package                               \--target hw                             \--platform $(VITIS_PLATFORM)            \--package.rootfs=$(ROOTFS)              \--package.image_format=ext4             \--package.boot_mode=sd                  \--package.kernel_image=$(IMAGE)         \--package.defer_aie_run                 \--package.sd_file ./embedded_exec.sh    \--package.sd_file ./host.exe ../binary_container_1.xsa ../libadf.a@echo "COMPLETE: Package created."
###########################################################################

2)选项解释

  • --package 流程将自动创建一个 a.xclbin 文件。
  • --package.defer_aie_run:AIE cores 将由 ps_app 启用。如果未设置,则在 PDI 加载期间生成 CDO 命令以启用 AIE cores。此操作在输入文件含 AIE Compiler archive file(libadf.a)并与 Versal 平台一起使用时有效。

3)输出

在 sw 目录下,输出 ​​​​​​​sd_card.img 文件,用于烧写。

2.8 在硬件中运行

2.8.1 烧写

烧写方法见:3.9 Run on VD100https://blog.csdn.net/DongDong314/article/details/145429197?spm=1001.2014.3001.5501#t35

2.8.2 运行

>> sudo su
>> cd /run/media/mmcblk1p1/
>> ls -l
---
total 30279
-rwxrwx--- 1 root disk  2694800 Jan  1  2015 BOOT.BIN
-rwxrwx--- 1 root disk 23865856 Jan  1  2015 Image
-rwxrwx--- 1 root disk  4118215 Jan  1  2015 a.xclbin
-rwxrwx--- 1 root disk     3472 Jan  1  2015 boot.scr
-rwxrwx--- 1 root disk      166 Jan  1  2015 embedded_exec.sh
-rwxrwx--- 1 root disk   321048 Jan  1  2015 host.exe

运行结果:

>> ./host.exe a.xclbin
---
XAIEFAL: INFO: Resource group Avail is created.
XAIEFAL: INFO: Resource group Static is created.
XAIEFAL: INFO: Resource group Generic is created.
Input memory virtual addr 0x0xffffb5997000x
Output memory virtual addr 0x0xffffb5996000x
Output memory virtual addr 0x0xffffb5995000x
run mm2s
run s2mm
graph run
graph end
After MM2S wait
After S2MM_1 wait
After S2MM_2 wait
TEST PASSED

3. All Makefile

在 Makefile 中有段检查环境的脚本,用于确保系统已正确安装 v++ 工具,并且 CXX 和 SDKTARGETSYSROOT 这两个关键变量已被定义。如果缺少其中的任何一个,会打印错误并中断构建。它们依次执行如下功能:

  • 检查 v++ 是否存在
  • 检查 CXX 是否定义
  • 检查 SDKTARGETSYSROOT 是否定义
##############################################################
ifeq (, $(shell which v++))$(error v++ not found, please install it or check your PATH)
endififeq ($(origin CXX), undefined)$(error CXX is not defined)
endififeq ($(origin SDKTARGETSYSROOT), undefined)$(error SDKTARGETSYSROOT is not defined)
endif.ONESHELL:
.PHONY: clean all vitis_platform kernels aie xsa host packageall: vitis_platform kernels aie xsa host package
#########################################################################################################################################
RELATIVE_PATH := /platform/vitis_pfm/platform/export/platform/platform.xpfm
VITIS_PLATFORM := $(CURDIR)$(RELATIVE_PATH)vitis_platform: $(VITIS_PLATFORM)$(VITIS_PLATFORM):$(MAKE) vitis_pfm -C platform
#################################################################################################################################
VPP_XO_FLAGS := --compile   \--mode hls  \--platform $(VITIS_PLATFORM)kernels: ./pl_kernels/s2mm.xo ./pl_kernels/mm2s.xo./pl_kernels/s2mm.xo:v++ $(VPP_XO_FLAGS) --config ./pl_kernels/s2mm.cfg./pl_kernels/mm2s.xo:v++ $(VPP_XO_FLAGS) --config ./pl_kernels/mm2s.cfg
##################################################################################################################
AIE_INCLUDES := --include "./aie"          \--include "./data"         \--include "./aie/kernels"  \--include "./"             \--include "$(XILINX_VITIS)/aietools/include"aie: ./libadf.a./libadf.a:v++ --compile                       \--mode aie                      \--target hw                     \--platform $(VITIS_PLATFORM)    \--work_dir "./Work"             \$(AIE_INCLUDES)                 \--input_files "./aie/graph.cpp"@echo "COMPLETE: libadf.a created."
##########################################################################################################################
xsa: ./binary_container_1.xsa./binary_container_1.xsa:v++ --link                                \--target hw                           \--platform $(VITIS_PLATFORM)          \--config "./system.cfg"               \--output "./binary_container_1.xsa"   \--input pl_kernels/s2mm.xo pl_kernels/mm2s.xo libadf.a@echo "COMPLETE: .xsa created."
###########################################################################################################################
GCC_FLAGS := -Wall -c -g \-std=c++17 -Wno-int-to-pointer-castGCC_INCLUDES = -I$(SDKTARGETSYSROOT)/usr/include/xrt \-I$(SDKTARGETSYSROOT)/usr/include     \-I./GCC_LIB := -lxrt_coreutilhost: ./sw/host.exe./sw/host.exe: ./sw/host.cppcd ./sw$(CXX) $(GCC_FLAGS) $(GCC_INCLUDES) -o host.o host.cpp$(CXX) *.o $(GCC_LIB) -std=c++17 -o host.exe@echo "COMPLETE: Host application created."
########################################################################################################################################
ROOTFS = $(CURDIR)/platform/petalinux/vd100/images/linux/rootfs.ext4
IMAGE = $(CURDIR)/platform/petalinux/vd100/images/linux/Imagepackage: ./sw/sd_card.img./sw/sd_card.img:cd ./swv++ --package                               \--target hw                             \--platform $(VITIS_PLATFORM)            \--package.rootfs=$(ROOTFS)              \--package.image_format=ext4             \--package.boot_mode=sd                  \--package.kernel_image=$(IMAGE)         \--package.defer_aie_run                 \--package.sd_file ./embedded_exec.sh    \--package.sd_file ./host.exe ../binary_container_1.xsa ../libadf.a@echo "COMPLETE: Package created."
###############################################################################################################################################################################
clean:rm -f pl_kernels/s2mm.xo pl_kernels/mm2s.xo libadf.a *.log *.db *.csv *.jsonrm -rf ./*binary_container_1* ./Work/ ./s2mm/ ./mm2s/ ./.ipcache ./platform/vitis_pfm/rm -f sw/sd_card.img sw/*.o sw/*.exe sw/*.xclbin sw/*.bin sw/*.BIN sw/*.bif sw/*.txt sw/*summaryrm -rf sw/sd_card/ sw/*.log sw/.Xil/ sw/_x/

4. 总结

  • 滤清 “2.1.1 步骤依赖关系” 非常重要,理解其中的输入输出关系。
  • Vpp_link_XSA 步骤是调用 vivado 执行综合、布局布线。
  • host.exe 存在问题,无法第二次运行。需要解决。

​​​​​​​

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com