编写定制 Makefile - 2023.2 简体中文

Vitis 统一软件平台文档 应用加速开发 (UG1393)

Document ID
UG1393
Release Date
2023-12-13
Version
2023.2 简体中文

您的定制 Makefile 所提供的函数应与模板 Makefile 类似。VSC 中的基本编译步骤与其他 Vitis 工具流程是类似的,如下所示:

v++ --compile my_acc.cpp -o my_acc.o
v++ --link my_acc.o -o hw.xclbin # also outputs hw.o
g++ -c main.cpp -o main.o
g++ -o host.exe main.o my_acc.o hw.o -lvpp_acc -lxrt_core -lpthread
在这些命令中值得注意的有:
  1. v++ 编译命令不使用 -k 选项来指定内核名称。这是因为源代码定义的类衍生自 VPP_ACC 类,后者支持 Vitis 工具对 VSC 系统进行编译。
  2. v++ --compile 编译命令会生成 .o 文件替代 .xo 文件。这些文件供 Vitis 编译器和 g++ 用于构建硬件和主机系统。
  3. v++ --link 命令将使用 .o 文件作为输入,并生成用于硬件加速器的 .xclbin 和包含已编译对象的 hw.o,其中已编译的对象用于 VSC 硬件软件接口,这些接口是主机应用所必需的,供 g++ 使用。
  4. 这些命令还需包含特定选项用于相应的工具和模式,例如,--platform--target

或者,您可创建共享(可动态加载)库,以便将加速器轻松集成到第三方应用中。例如,以下提供的 libmy_acc.so

v++ -c my_acc.cpp -o my_acc.o
v++ -l my_acc.o kernel.xo -o hw.xclbin # also produces hw.o
g++ -c -fPIC app.cpp -o app.o 
## Command to create the shared library:
g++ -shared -fPIC -o libmy_acc.so app.o my_acc.o \
    -Wl,--whole-archive ${XILINX_VITIS}/system_compiler/lib/x86/libvpp_acc.a \
    -Wl,--no-whole-archive
## The link command using the shared library
g++ -o host.exe main.o -lmy_acc -lxrt_hw -lpthread