Streaming Kernel Coding Guidelines - 2023.2 English

Vitis Unified Software Platform Documentation: Application Acceleration Development (UG1393)

Document ID
UG1393
Release Date
2023-12-13
Version
2023.2 English

In a PL kernel, the streaming interface directly sending data to or receiving data from another kernel streaming interface is defined by hls::stream with the ap_axiu<D,0,0,0> data type. The ap_axiu<D,0,0,0> data type requires the use of the ap_axi_sdata.h header file.

The following example shows the streaming interfaces of the producer and consumer kernels.

// Producer kernel - provides output as a data stream
// For simplicity the example only shows the streaming output.

void kernel1 (.... , hls::stream<ap_axiu<32, 0, 0, 0> >& stream_out) {
      
  for(int i = 0; i < ...; i++) {
    int a = ...... ;         // Internally generated data
    ap_axiu<32, 0, 0, 0> v;  // temporary storage for ap_axiu
    v.data = a;              // Writing the data
    stream_out.write(v);         // Writing to the output stream.
  }
}
 
// Consumer kernel - reads data stream as input
// For simplicity the example only shows the streaming input.

void kernel2 (hls::stream<ap_axiu<32, 0, 0, 0> >& stream_in, .... ) {
 
  for(int i = 0; i < ....; i++) {
    ap_axiu<32, 0, 0, 0> v = stream_in.read(); // Reading the input stream
    int a = v.data; // Extract the data
          
    // Do further processing
  }
}

Because the hls::stream data type is defined, the Vitis HLS tool infers axis interfaces. The following INTERFACE pragmas are shown as an example, but are not required in the code.

#pragma HLS INTERFACE axis port=stream_out
#pragma HLS INTERFACE axis port=stream_in
Tip: These example kernels show the definition of the streaming input/output ports in the kernel signature, and the handling of the input/output stream in the kernel code. The connection of the streaming interfaces from kernel1 to kernel2 must be defined during the linking process as described in Specifying Streaming Connections.