ADF APIs are used to control graph execution in the top-level application, or host code, as described in 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();
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.Running in Linux, the ADF API is
used to update run-time parameters (RTPs) for PL kernels that are inside the graph. 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 and PL kernels inside the graph.
Internally, the ADF API is calling the XRT API, and
adf::registerXRT()
is used to manage the
relationship between them.
The following is example code showing RTP update and execution by the ADF API:
// update graph parameters (RTP) & run
adf::registerXRT(dhdl, uuid);
gr.update(gr.size, 1024);//update PL kernel RTP
gr.run(16);//start PL kernel & AIE kernel
gr.wait();
For PL kernels inside the graph, graph.update()
must be called before graph.run()
. In the example shown above, gr.run(16)
specifies a run of 16 iterations. In each graph.run()
call, the PL kernels inside the graph are only
started once, no matter the number of iterations specified for the run. However, the
AI Engine kernels run the number of iterations
specified for the run.
In graph.wait()
, the application waits
for both the AI Engine kernels and PL kernels inside
the graph to complete. Thus, it is your responsibility to make sure the AI Engine kernels and PL kernels inside graph can start
and complete in synchronous mode.
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);