Compiling the Embedded Application for the x86 Processor - 2023.1 English

AI Engine Tools and Flows User Guide (UG1076)

Document ID
UG1076
Release Date
2023-06-23
Version
2023.1 English

In order to compile your embedded application for x86 model of PS in software emulation, you must use the x86 version of GCC or g++ compiler.

The x86 compilation is supported in the software emulation flow using native x86 compilation and requires GCC 8.3 or later. This feature requires the x86 installation of XRT as described in Installing Xilinx Runtime and Platforms in Vitis Unified Software Platform Documentation: Application Acceleration Development (UG1393).

Command to Compile the Host Application

g++ -Wall -c -std=c++17 -Wno-int-to-pointer-cast -I${XILINX_XRT}/include \
-I./src/aie -I./ -I${XILINX_VITIS}/aietools/include \
-o aie_control_xrt.o ./Work/ps/c_rts/aie_control_xrt.cpp $(HOST_SRCS) -o main.o

Command to Link the Host Application Against Required XRT APIs and Generate the Executable

g++ *.o -lxrt_coreutil -ladf_api_xrt -L${XILINX_VITIS}/aietools/lib/lnx64.o \
-L${XILINX_XRT}/lib -o $(EXECUTABLE)
Note: As mentioned above, you need to install the x86 XRT which automatically sets the LD_LIBRARY_PATH variable to point to XRT libraries.
Note: For ps_on_x86 compilation, you must set the GCC path from the Vitis Install:
setenv PATH $XILINX_VITIS/aietools/tps/lnx64/gcc/bin:$PATH

If you want to switch between the embedded (ARM-GCC) flow and x86 compilation flow on the same setup (terminal), you need to explicitly specify ARM-GCC and SYSROOT paths for compiling and linking the application for ARM-GCC based flow. The scenario is applicable if you are trying to run the emulation using cross compilation of the host application and simultaneously want to run software emulation using native x86 compilation of the host application on the same shell (terminal).

Note: After running native x86 compilation, if you are trying to compile the host application using ARM-GCC compiler in the same terminal, you will source the environment setup script xilinx-versal-common-v2023.1/environment-setup-cortexa72-cortexa53-xilinx-linux. Ensure the LD_LIBRARY_PATH variable is not set since a warning will be issued if this variable is set. You must then unset the LD_LIBRARY_PATH and re-run the environment setup script.

For information on how to run PS on x86 for an AI Engine kernel, see the AIE Adder example on GitHub.

Limitations

Arm-only data types or libraries are not supported in the host code while running the x86 compilation.

Below is the host code example using _fp16 (floating point 16) data types which is only supported in the ARM-GCC based compiler. The x86 compiler issues error while compiling the same host code. In such situation, AMD recommends using the QEMU model of the PS and compiling the PS application with ARM-GCC based compiler.

#define LENGTH (1024)
#define HALF __fp16
int main(int argc, char* argv[])
{
unsigned fileBufSize;
std::string binaryFile = argv[1];
size_t vector_size_bytes = sizeof(HALF) * LENGTH;
//Source Memories
std::vector<HALF> source_a(LENGTH);
std::vector<HALF> source_b(LENGTH);
std::vector<HALF> result_sim (LENGTH);
std::vector<HALF> result_krnl(LENGTH);
/* Create the test data and golden data locally */
for(int i=0; i < LENGTH; i++){
source_a[i] = i;
source_b[i] = i*2;
result_sim[i] = source_a[i] + source_b[i];
} 
Tip: As described in Compiling the Embedded Application for the Cortex-A72 Processor, you can also target the QEMU model of the PS by compiling the embedded application in software emulation flow using the ARM-GCC compiler.