The Vitis platform usually contains multiple types of memories, or multiple memory banks. When creating the buffer objects for PL kernels or AI Engine GMIO ports, it needs to specify the correct memory group for the buffer objects.
xrt::kernel.group_id(<PORT
INDEX>) API to get the group id, for
example:auto mm2s_1_khdl = xrt::kernel(dhdl, uuid, "mm2s");
auto in_bohdl_1 = xrt::bo(dhdl,input_size_in_bytes, 0, mm2s_1_khdl.group_id(0));
This ensures that the host code works even if the connection changes in the platform or if the platform changes.
When creating buffer objects for AI Engine GMIO, it needs to specify group id manually for the buffer objects. The section NoC Memory Configuration in Embedded Design Development Using Vitis (UG1701) introduces how to configure the platform and connect with AI Engine GMIO ports.
There are different ways to check and select the memory group to use. One
method is to use xrt-smi to show all available
memory groups:
xrt-smi examine -r memory
It shows the available memory types and group id (Xclbin Index):
Memory Topology
HW Context Slot: 0
Xclbin UUID: 42bc36de-edcd-c1cc-2c5c-1e4159f212b4
Index Tag Type Temp(C) Size Base Address
---------------------------------------------------------
0 LPDDR MEM_DRAM N/A 2 GB 0x0
1 LPDDR MEM_DRAM N/A 2 GB 0x880000000
2 LPDDR MEM_DRAM N/A 3072 MB 0x50000000000
3 LPDDR MEM_DRAM N/A 3072 MB 0x60000000000
Then creating the buffer objects for the GMIO transactions with manually selected IDs:
auto din_buffer = xrt::aie::bo (device, BLOCK_SIZE_in_Bytes,xrt::bo::flags::normal, /*memory group*/0);
auto dout_buffer = xrt::aie::bo (device, BLOCK_SIZE_in_Bytes,xrt::bo::flags::normal, /*memory group*/0);
You can also query the memory groups in the host code and choose any one as needed:
auto xclbin=xrt::xclbin(<XCLBIN FILE>);
auto mem_toplogy=xclbin.mem_topology();
//Iterate through the memory banks
for(const auto& mem : mem_topology){
std::cout<<"Memory Bank:"<<mem.m_tag<<std::endl;
std::cout<<"Type:"<<mem.m_type<<std::endl;
std::cout<<"Size:"<<mem.m_size<<" bytes"<<std::endl;
}