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__ を使用すると、AI エンジン シミュレータ、x86simulator、ハードウェア エミュレーション、およびハードウェア フローで graph.cpp の同じバージョンを使用できます。上記のコードは、グラフまたは GMIO ADF API を呼び出す前に配置する必要があります。プログラムの最後に、xrtDeviceClose()
API を使用してデバイスを閉じます。
#if !defined(__AIESIM__) && !defined(__X86SIM__)
xrtDeviceClose(dhdl);
#endif
ハードウェア フロー向けのコードのコンパイルについては、 『AI エンジン ツールおよびフロー ユーザー ガイド』 (UG1076) の PS ホスト アプリケーションのプログラミングを参照してください。
GMIO の制御には ADF API を使用することが推奨されますが、XRT を使用することも可能です。ただし、同期モードの GMIO トランザクションのみがサポートされます。同期データ転送を実行する API は、experimental/xrt_aie.h にあります。
/**
* 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);