Targeting Software Emulation - 2022.2 English

Vitis Tutorials: Getting Started (XD098)

Document ID
XD098
Release Date
2022-11-07
Version
2022.2 English

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_202220_1 --config ../../src/zcu102.cfg -k vadd -I../../src ../../src/vadd.cpp -o ./vadd.xo 
v++ -l -t sw_emu --platform xilinx_zcu102_base_202220_1 --config ../../src/zcu102.cfg ./vadd.xo -o ./vadd.xclbin
v++ -p -t sw_emu --platform xilinx_zcu102_base_202220_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:

  1. $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 SDK environment setup script. Refer to Building the Host Program for more information. This should resolve to $XILINX_VITIS/gnu/aarch64/lin/aarch64-linux/bin/aarch64-linux-gnu-g++

  2. v++ -c compiles the source code for the vector-add accelerator into a compiled kernel object (.xo file). Refer to Compiling Kernels with the Vitis Compiler for more information.

  3. v++ -l links the compiled kernel with the target platform and generates the FPGA binary (.xclbin file). Refer to Linking the Kernels for more information.

  4. 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. 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 Running Emulation. In this flow you will use a launch_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 we 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 shouldn’t 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 Xilinx 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.

Once 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.