Packet Stream Operations - 2020.2 English

Versal ACAP AI Engine Programming Environment User Guide (UG1076)

Document ID
Release Date
2020.2 English
Table 1. Supported Packet Stream Data Types
Input Stream Types Output Stream Types
input_pktstream output_pktstream

Two more stream data types are provided to denote streaming data consisting of packetized interleaving of several different streams. These data types are useful when the number of independent data streams in your program exceeds the number of hardware stream channels or ports available. This mechanism is described in more detail in Explicit Packet Switching.

Packet Stream Reading and Writing

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 denotes 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 TLAST argument help to read or write the end-of-packet condition if the packet size is not fixed.

Packet Processing

The first 32-bit word of a packet must always be a packet header, which encodes several bit fields as shown in the following table.

Table 2. Packet Bit Fields
Bits Field
4-0 Packet ID
11-5 7'b0000000
14-12 Packet Type
15 1'b0
20-16 Source Row
27-21 Source Column
30-28 3'b000
31 Odd parity of bits[30:0]

The packet ID is assigned by the compiler based on routing requirements. The packet type can be any 3-bit pattern that you want to insert to identify the type of packet. The source row and column denote the AI Engine tile coordinates from where the packet originated. By convention, source row and column for packets originating in the PL is -1,-1.

It is your responsibility to construct and send an appropriate packet header at the beginning of every packet. On the receive side, the packet header needs to be received and decoded before reading the data.

The following operations help to assemble or disassemble the packet header in the AI Engine kernel.

uint32 generateHeader(uint32 pktType, uint32 ID);
uint32 generateHeader(uint32 pktType, uint32 srcCol, uint32 srcRow, uint32

uint32 getPacketid(input_pktstream *w, int index);
uint32 getPacketid(output_pktstream *w, int index);

The generateHeader API allows a packet header to be assembled with a given packet ID and packet type. The source row and column can be provided explicitly (for PL code) or are inserted automatically using the coordinates of the AI Engine tile where this API is executed.

The getPacketid API allows the compiler assigned packet ID to be queried on the input or output packet stream data structure. The index argument refers to the split or merge branch edge in the graph specification.

Important: The generateHeader() and getPacketid() APIs are not supported in PL kernels.

See Explicit Packet Switching for more details.