In the Vitis™ environment, the host application can be written in native C++ using the Xilinx® runtime (XRT) native C++ API or industry standard OpenCL™ API. The XRT native API is described here in brief, with additional details available under XRT Native API on the XRT documentation site. Refer to OpenCL Programming for a discussion on writing the host application using the OpenCL API.
Tip: For examples of host
programming using the XRT native API refer to host_xrt in the Vitis_Accel_Examples.
In general, the structure of the host application can be divided into the following steps:
- Specifying the accelerator device ID and loading the .xclbin
- Setting up the kernel and kernel arguments
- Transferring data between the host and kernels
- Running the kernel and returning results
To use the native XRT APIs, the host application must link with the
xrt_coreutil
library. Compiling host code with XRT
native C++ API requires C++ standard with -std=c++14
or newer. For example:
g++ -g -std=c++14 -I$XILINX_XRT/include -L$XILINX_XRT/lib -lxrt_coreutil -pthread
Important: For multithreading the
host program, exercise caution when calling a
fork()
system call from a Vitis core development kit
application. The fork()
does not duplicate all the
runtime threads. Hence, the child process cannot run as a complete application in the
Vitis core development kit. It is advisable to
use the posix_spawn()
system call to launch another
process from the Vitis software platform
application.