input_gmio
/output_gmio
不仅能搭配 AI 引擎仿真器使用,也可用于硬件仿真流程和硬件流程。为了使其能在硬件仿真流程和硬件流程中工作,请向 graph.cpp 添加以下代码。
#if !defined(__AIESIM__) && !defined(__X86SIM__)
#include "adf/adf_api/XRTConfig.h"
#include "experimental/xrt_kernel.h"
// Create XRT device handle for ADF API
char* xclbinFilename = argv[1];
auto dhdl = xrtDeviceOpen(0);//device index=0
xrtDeviceLoadXclbinFile(dhdl,xclbinFilename);
xuid_t uuid;
xrtDeviceGetXclbinUUID(dhdl, uuid);
adf::registerXRT(dhdl, uuid);
#endif
通过使用守卫宏 __AIESIM__ 和 __X86SIM__,即可将相同版本的 graph.cpp 用于 AI 引擎仿真器、x86simulator、硬件仿真流程和硬件流程。请注意,前述代码应置于调用 graph 或 GMIO ADF API 的代码之前。程序结束时,请使用 xrtDeviceClose()
API 关闭器件。
#if !defined(__AIESIM__)
xrtDeviceClose(dhdl);
#endif
要为硬件流程编译代码,请参阅 PS 主机应用编程。
虽然建议使用 ADF API 来控制 GMIO,但是可以使用 XRT。但仅支持同步模式 GMIO 传输事务。在 experimental/xrt_aie.h 中可找到用于执行同步数据传输的 API:
/**
* xrtAIESyncBO() - Transfer data between DDR and Shim DMA channel
*
* @handle: Handle to the device
* @bohdl: BO handle.
* @gmioName: GMIO name
* @dir: GM to AIE or AIE to GM
* @size: Size of data to synchronize
* @offset: Offset within the BO
*
* Return: 0 on success, or appropriate error number.
*
* Synchronize the buffer contents between GMIO and AIE.
* Note: Upon return, the synchronization is done or error out
*/
int
xrtAIESyncBO(xrtDeviceHandle handle, xrtBufferHandle bohdl, const char *gmioName, enum xclBOSyncDirection dir, size_t size, size_t offset);