x86 功能仿真器 - 2022.1 简体中文

Versal ACAP AI 引擎编程环境 用户指南 (UG1076)

Document ID
UG1076
Release Date
2022-05-25
Version
2022.1 简体中文

AI 引擎 graph 和内核上启动开发时,验证设计行为至关重要。这称为功能仿真,对于识别设计中的错误很有用。例如,graph 中的窗口大小与内核中的迭代数息息相关。通过故障排除来查看大型 graph 中是否每个内核都正在吸收和生成正确数量的样本,这本质上是一个耗时且迭代性的操作。x86 仿真器因其给开发者所提供的高速迭代和高层次的数据可视性,而成为对此类行为进行测试、调试和验证的理想选择。但 x86 仿真无法提供时序、资源或性能信息。x86 仿真器专在工具开发机器上运行。这意味着其性能和存储器使用均由开发机器来定义。

虽然 AI 引擎仿真器能对 AI 引擎阵列的存储器进行完整建模,但这也意味着 AI 引擎仿真器受到 AI 引擎存储器空间的限制。x86 仿真器则不受此限制,可提供近乎无限量的调试 printf()s、大型阵列和变量。通过搭配单步执行内核的能力,即可快速发现并解决非常复杂的问题。

其中还提供了多个宏用于改善内核调试。这些宏旨在搭配 x86 仿真器一起使用,可保留在代码中以便于维护。x86 仿真器有利有弊。部分类型的 graph 构造不受支持,在 AI 引擎仿真器与 x86 仿真器之间难以保证行为的周期精确性。x86 仿真器并非旨在替代 AI 引擎仿真器。AI 引擎仿真器仍必须在所有设计上运行以验证行为并获取性能信息。对于工程开发的不同阶段,总有某一种工具更适合您的需求。

注释: 要了解有关 X86 仿真限制的更多信息,请参阅“限制”部分

要运行 x86 仿真器,请将 AI 引擎编译器目标更改为 x86sim

aiecompiler --target=x86sim graph.cpp

为 x86 仿真完成应用编译后,即可按如下方式调用 x86 仿真器。

x86simulator

以下代码中显示了完整的 x86 仿真器命令帮助信息。

$ 
x86simulator [-h] [--help] [--h] [--pkg-dir=PKGDIR]
optional arguments:
-h,--help --h show this help message and exit
--pkg-dir=PKG_DIR Set the package directory. ex: Work
--i, -i ,--input-dir=PATH Set the input directory
--o, -o ,--output-dir=PATH Set the output directory
--timeout=secs Terminate simuation after specified number of seconds
--dump Enable snapshots of data traffic on kernel ports
--gdb Invoke from gdb
--valgrind Run simulator under valgrind to detect access violations
--valgrind-gdb Run simulator under valgrind and debug via gdb server
--valgrind-args=ARGS Override default options for valgrind. Used in conjunction with --valgrind.
--stop-on-deadlock Stop simulation if deadlock is detected
--trace Enable trace of kernel stall events
--trace-print Print kernel stall events during simulation
--enable-handshake-ext-tb Enable handshake protocol with external testbench

编译后的 x86 本机仿真二进制文件是由 AI 引擎编译器生成的,置于Work 目录(请参阅 编译 AI 引擎 graph 应用)下,并由 x86 仿真器自动启动。

在以下 graph 代码片段中指定了输入和输出文件。

adf::input_plio in1=adf::input_plio::create("In", adf::plio_32_bits, "In1.txt");
adf::output_plio out1=adf::output_plio::create("Out", adf::plio_32_bits, "Out1.txt");

x86 仿真器在运行时会在当前工作目录中查找 data/In1.txt,即 ADF graph 所使用的输入之一。为了将 x86 仿真器的输出文件与 AI 引擎仿真器的输出文件加以区分,Out1.txt 位于 current_working_dir/x86simulator_output/data/ 中。

(可选)由仿真器生成的输出文件可以与黄金输出进行比较(忽略空格差异)。

diff –w <data>/golden.txt <data>/output.txt
仿真器 log 日志和输出均可在 vitis_analyzer 中直观查看:
图 1. Vitis 分析器 log 日志视图
图 2. Vitis 分析器仿真器输出视图
“Simulator Output”(仿真器输出)视图允许您选择应显示的输出。