AI エンジン GMIO は、同期転送と非同期転送をサポートします。次に、XRT API を用いた非同期 GMIO のインプリメンテーションの例を示します。
char* xclbinFilename = argv[1];
// Open xclbin
auto device = xrt::device(0); //device index=0
auto uuid = device.load_xclbin(xclbinFilename);
auto din_buffer = xrt::aie::bo (device, BLOCK_SIZE_in_Bytes, xrt::bo::flags::normal, /*memory group*/0); //Only non-cacheable buffer is supported
int* dinArray= din_buffer.map<int*>();
auto dout_buffer = xrt::aie::bo (device, BLOCK_SIZE_in_Bytes, xrt::bo::flags::normal, /*memory group*/0); //Only non-cacheable buffer is supported
int* doutArray= dout_buffer.map<int*>();
int ret=0;
int error=0;
//Initialization
for(int i=0;i<ITERATION*1024/4;i++){
dinArray[i]=i;
}
din_buffer.async("gr.gmioIn",XCL_BO_SYNC_BO_GMIO_TO_AIE,BLOCK_SIZE_in_Bytes,/*offset*/0);
auto ghdl=xrt::graph(device,uuid,"gr");
ghdl.run(ITERATION);
auto out_buffer_run=dout_buffer.async("gr.gmioOut",XCL_BO_SYNC_BO_AIE_TO_GMIO,BLOCK_SIZE_in_Bytes,/*offset*/0);
ghdl.wait();//Wait for graph to complete
dout_buffer_run.wait();//Wait for gmioOut to complete
//Post-processing
...
注記:
AI エンジンの GMIO バッファーでは、キャッシュ不可能なバッファーのみがサポートされます。