Packet Stream Interfaces and Operations - 2022.2 English

Vitis Tutorials: AI Engine Development

Document ID
Release Date
2022.2 English

Two stream types are provided to denote streaming data, consisting of packetized interleaving of several different streams. These types are listed in the following table.

Input Stream Types Output Stream Types
input_pktstream output_pktstream

A data packet consists of a one word (32-bit) packet header, followed by some number of data words where the last data word has the TLAST field denoting the end-of-packet. The following operations are used to read and advance input packet streams and write and advance output packet streams.

int32 readincr(input_pktstream *w);
int32 readincr(input_pktstream *w, bool &tlast);
void writeincr(output_pktstream *w, int32 value);
void writeincr(output_pktstream *w, int32 value, bool tlast);

The API with the TLAST argument reads or writes the end-of-packet condition if the packet size is not fixed.

The AI Engine tools provide the built-in function writeHeader to generate a packet header for packets originating from the AI Engine kernel and writes them to the output.

void writeHeader(output_pktstream *str, unsigned int pcktType, unsigned int ID);
void writeHeader(output_pktstream *str, unsigned int pcktType, unsigned int ID, bool tlast);

The AI Engine tools also provide the built-in function getPacketid to get the packet ID for the packet stream interface. The index for getPacketid only applies if the packet stream feeds into a pktsplit. In this example, each AI Engine kernel output sees only one logical stream (0 for index).

uint32_t getPacketid(input_pktstream * in, int index);
uint32_t getPacketid(output_pktstream * out, int index);   

Change working directory to pktstream_aie. Review the AI Engine kernels (aie/aie_core1.cpp, … , aie/aie_core4.cpp). The code for aie_core1 (aie/aie_core1.cpp) is as follows.

void aie_core1(input_pktstream *in,output_pktstream *out){
	readincr(in);//read header and discard
	uint32 ID=getPacketid(out,0);//for output pktstream
	writeHeader(out,pktType,ID); //Generate header for output

	bool tlast;
	for(int i=0;i<8;i++){
		int32 tmp=readincr(in,tlast);
		writeincr(out,tmp,i==7);//TLAST=1 for last word

It can be seen that the input packet header is discarded. The output header is generated by writeHeader, and the packet ID for the header is obtained by getPacketid. TLAST equals 1 for the last word in the packet.