Load and Store Using Pointers - 2024.2 English

AI Engine-ML Kernel and Graph Programming Guide (UG1603)

Document ID
UG1603
Release Date
2024-11-28
Version
2024.2 English

Applications can load from DM into vector registers and store the contents of vector registers into DM. Memory instructions in the AI Engine-ML that operate on vectors have alignment requirements. Functions are provided for both aligned and unaligned accesses:

aie::load_v
Load a vector of Elems size whose elements have type T (for example, aie::load_v<Elems>(T*)). The pointer is assumed to meet the alignment requirements for a vector load of this size.
aie::store_v
Store a vector of Elems size whose elements have type T (for example, aie::store_v<Elems>(T*)). The pointer is assumed to meet the alignment requirements for a vector store of this size.
aie::load_unaligned_v
Load a vector of Elems size whose elements have type T. The pointer is assumed to be aligned to T.
aie::store_unaligned_v
Store a vector of Elems size whose elements have type T. The pointer is assumed to be aligned to T.
alignas(aie::vector_decl_align) int16 delay_value[N]={...};
aie::vector<int16,8> va=aie::load_v<8>(delay_value);
aie::store_v(delay_value,va);

int16* scatter_value=delay_value+3;
aie::vector<int16,8> vv=aie::load_unaligned_v<8>(scatter_value);
aie::store_unaligned_v(scatter_value,vv);

The compiler supports standard pointer de-referencing and pointer arithmetic for vectors. For using vector iterators to iterate on memory, see Iterators.

In the kernel code, it is possible to use a direct pointer to load/store data.

void func(input_buffer<int16> &w_input, 
			output_buffer<cint16> &w_output){
  .....
  aie::vector<int16,16> datain=aie::load_v<16>((int16*)w_input.data());
  aie::vector<cint16,8> dataout=datain.cast_to<cint16>();
  aie::store_v((cint16*)w_output.data(),dataout);
  ......
}
Note: If using pointers to load and store data, it is the designer’s responsibility to avoid out-of-bound memory access.