Controlling the AI Engine Graph with the ADF API - 2021.2 English

Versal ACAP AI Engine Programming Environment User Guide (UG1076)

Document ID
UG1076
Release Date
2021-12-17
Version
2021.2 English

ADF APIs are used to control graph execution in the top-level application, or host code, as described in Introduction to AI Engine Programming. For example, the following code is for a synchronous update of run-time parameters for AI Engine kernels in the graph:

// ADF API:run and update graph parameters (RTP)
gr.run(4);
gr.update(gr.trigger,10);
gr.update(gr.trigger,10);
gr.update(gr.trigger,100);
gr.update(gr.trigger,100);
gr.wait();
Tip: The use of graph.end() terminates the graph. It will not recover after end() has been called. Instead, you can use graph.wait() to wait for runs to be completed.

In the host application (host.cpp), the graph.update() function is called to update the RTPs, and graph.run() is called to launch the AI Engine kernels in the graph. In hardware emulation and hardware flows, the ADF API is calling the XRT API, and adf::registerXRT() is used to manage the relationship between them.

Important: adf::registerXRT() must be called before any ADF API control or interaction with the graph.

The following is example code showing the RTP update and execution by the ADF API.

// update graph parameters (RTP) & run
adf::registerXRT(dhdl, uuid);
gr.update(gr.size, 1024);//update RTP
gr.run(16);//start AIE kernel
gr.wait();

In the preceding example, gr.run(16) specifies a run of 16 iterations.

In graph.wait(), the application waits for the AI Engine kernels to complete.

The code example shows that adf::registerXRT() requires the device handle (dhdl) and UUID of the XCLBIN image. They can be obtained using the XRT APIs:

auto dhdl = xrtDeviceOpen(0);//device index=0
xrtDeviceLoadXclbinFile(dhdl,xclbinFilename);
xuid_t uuid;
xrtDeviceGetXclbinUUID(dhdl, uuid);