Programming the PS Host Application - 2025.2 English

AI Engine Tools and Flows User Guide (UG1076)

Document ID
UG1076
Release Date
2025-11-20
Version
2025.2 English

Creating a Data Flow Graph (Including Kernels) in AI Engine Kernel and Graph Programming Guide (UG1079), discusses a simple AI Engine graph application. The top-level application initialized the graph, ran the graph, and ended the graph. However, for actual AI Engine graph applications the host code must do much more than those simple tasks. The top-level PS application running on the Cortex®-A72, controls the graph and PL kernels: manage data inputs to the graph, handle data outputs from the graph, and control any PL kernels working with the graph.

In addition, you can run AI Engine graph applications on Linux operating systems or on bare-metal systems. The programming requirements for these two systems are significantly different, as outlined in the following topics. AMD provides drivers used by the API calls in the host program to control the graph and PL kernels based on the operating system. The XRT API provides this in Linux. In bare-metal, graph APIs control AI Engine kernels, and libUIOdriver calls control PL kernels.

Preventing Multiple Graph Executions

If your graph is runs in a PS-based host application, define a conditional pragma (#ifdef) for your graph.cpp code. The conditional pragma ensures the graph initializes or runs only once. This example code is the simple application defined in Creating a Data Flow Graph (Including Kernels) in AI Engine Kernel and Graph Programming Guide (UG1079). It contains the additional guard macro __AIESIM__ and __X86SIM__.

#include "project.h"

simpleGraph mygraph;

#if defined(__AIESIM__) || defined(__X86SIM__)

int main(void) {
  mygraph.init();
  mygraph.run(<number_of_iterations>);
  mygraph.end();
  return 0;
}
#endif

This conditional directive compiles the application only for use with the AI Engine simulator. It prevents the graph from being initialized or run multiple times, from both the graph and PS host application. The directive lets the graph.cpp run in the AI Engine simulator and the x86 simulator. However when running in hardware and hardware emulation, the graph is initialized and run from the PS application, rather than from the graph.cpp.