To build for software emulation, enter the following commands to setup the target build directory:
cd <Path to the cloned repo>/Getting_Started/Vitis/example/zcu102
mkdir sw_emu
cp xrt.ini sw_emu
cp run_sw_emu.sh sw_emu
cd sw_emu
Then, after changing into the target build directory, enter the following commands to build the host application and device binary:
$CXX -g -std=c++17 -Wall -O0 -fmessage-length=0 ../../src/host.cpp -o ./app.exe -I$SYSROOT/usr/include/xrt -LSYSROOT/usr/lib -lxrt_coreutil -pthread --sysroot=$SYSROOT
v++ -c -t sw_emu --platform xilinx_zcu102_base_202320_1 --config ../../src/zcu102.cfg -k vadd -I../../src ../../src/vadd.cpp -o ./vadd.xo
v++ -l -t sw_emu --platform xilinx_zcu102_base_202320_1 --config ../../src/zcu102.cfg ./vadd.xo -o ./vadd.xclbin
v++ -p -t sw_emu --platform xilinx_zcu102_base_202320_1 --config ../../src/zcu102.cfg ./vadd.xclbin --package.out_dir ./package --package.rootfs ${ROOTFS}/rootfs.ext4 --package.sd_file ${ROOTFS}/Image --package.sd_file ./xrt.ini --package.sd_file ./app.exe --package.sd_file ./vadd.xclbin --package.sd_file ./run_sw_emu.sh
Here is a brief explanation of each of these four commands:
$CXX
compiles the host application using the Arm cross-compiler. This variable contains the full compiler executable plus flags relevant to cross-compilation, and is set when you source the software development kit (SDK) environment setup script. Refer to Building the Software Application for more information. This should resolve to$XILINX_VITIS/gnu/aarch64/lin/aarch64-linux/bin/aarch64-linux-gnu-g++
.v++ -c -k vadd
compiles the source code for the vector-add accelerator into a compiled kernel object (.xo file) for software emulation. Note that this is a different command than is required for compiling the C++ code for hardware emulation or hardware. Refer to Compiling PL Kernels for Software Emulation for more information.v++ -l
links the compiled kernel with the target platform and generates the FPGA binary (.xclbin file). Refer to Linking the System for more information.v++ -p
packages the host executable, the rootfs, the FPGA binary and a few other files and generates a bootable image. Refer to Packaging for Embedded Platforms for more information.
There are two important differences to take note of here between building for Data Center accelerator cards and building for Embedded Platforms.
The first is the use of the
v++ --package
command. This is a required step in the Embedded Processor platform flow and is largely optional in the Data Center flow, except in the case of Versal devices. The Data Center application runs in the X86 environment, and loads the xclbin from disk. However, in the Embedded Platform flow, generally, the processor must be booted from an SD card, and the--package
option gathers the files and generates the SD card.The second is the
emconfigutil
command. This command is used in the Data Center flow to build an emulation version of the hardware platform. However, in the Embedded Platform flow, the embedded processor requires the use of an emulation environment (QEMU) as described in Simulating the Application with the Emulation Flow. In this flow, you will use alaunch_emulation
script rather than the emulation platform.
The -t
option of the v++
command specifies the build target. Here it is set to sw_emu
so you are building for software emulation.
Notice also the --config
option which is used to specify the name of a configuration file containing additional options.
save-temps=1
debug=1
# Enable profiling of data ports
[profile]
data=all:all:all
Building for software emulation is quick and should not take more than a few minutes. After the build process completes, you can launch the software emulation run as follows:
./package/launch_sw_emu.sh -forward-port 1440 22
This command will launch software emulation, start the Quick Emulation (QEMU) environment and initiate the boot sequence. Refer to launch_emulator Utility for more information.
IMPORTANT: You must use the
-forward-port
option as shown above in order to later retrieve files from the QEMU environment as described in Running Emulation on an Embedded Processor Platform.
When Linux has finished booting, enter the following commands from within the QEMU environment to run the example program:
cd /run/media/mmcblk0p1
export XCL_EMULATION_MODE=sw_emu
./app.exe
You should see the following messages, indicating that the run completed successfully:
INFO: Found Xilinx Platform INFO: Loading 'vadd.xclbin' TEST PASSED
If you look at the directory contents for the zcu104/sw_emu
directory, you should see some of the following files that were created during this exercise:
app.exe: The compiled and linked host application.
vadd.xclbin: The device binary linking the kernel and target platform.
native_trace.csv: A report of events occurring during the application runtime.
summary.csv: A report of the application profile.
xrt.ini: The runtime initilization file.
xrt.run_summary: A summary report of the events of the application runtime.
These files and reports are the results of the build and run process targeting the software emulation build. You will be taking a closer look at some of these files in Part 5 of this tutorial. To examine these files later, you must retrieve them from the QEMU environment and copy them into your local system. You can do this using the scp
command as described in Running Emulation on an Embedded Processor Platform.
This command must be run from a Linux shell, outside of the QEMU environment. For example:
scp -P 1440 root@127.0.0.1:/run/media/mmcblk0p1/xrt.run_summary ./xrt.run_summary
Press Ctrl+a+x to exit QEMU and return to your bash shell.
TIP: If you have trouble exiting the QEMU environment, you can use
kill -9 <qemu_pid>
to kill the process from another terminal window.