Sample Code for Stream Input and Output - 2025.1 English - XD100

Vitis Tutorials: AI Engine Development (XD100)

Document ID
XD100
Release Date
2025-08-25
Version
2025.1 English

The following code segment shows how to calculate the squared magnitude of a complex vector using streams for input and output.

template  <typename Ti, typename To, unsigned vlen, unsigned burst_count>
void sqmag(input_stream<Ti>  *istrm,	// input stream
           output_stream<To> *ostrm		// output stream
) {

	for (auto i = 0u; i < burst_count; i++) {

        auto vin = readincr_v<vlen>(istrm);	// read "vlen" samples from "istrm" (re + j*im)
                                        	// into the vector register "vin"
        auto magsq = abs_square<To>(vin);  	// use "abs_square()" API to calculate (re^2 + im^2)
                                            // for each element and store in vector register "magsq"

		writeincr(ostrm, magsq);    // write vector register "magsq"
                                    // to output stream "ostrm"

	} // end for (auto i = 0u; i < burst_cnt; i++)

} // end sqmag()

The input stream port is declared as input_stream\<T\>, where T is the typename specified in the template parameter list. Similarly, the output stream port is declared as output_stream\<T\>.

readincr_v\<N\>( ) is an API which takes N values from an input stream and places them into a vector register. Note that:

  • The AIE tile stream is 32 bits wide running at 1.25 GHz on the VCK190 platform

  • The PL stream may be 32, 64, or 128 bits wide (defined in the ADF graph) running at a slower clock (usually half or a quarter of the AIE clock)

  • There are FIFO and clock domain crossing circuits at the AIE array and PL boundary such that:

    • a 32-bit PL stream running at half the AIE clock will provide 32-bit data to the AIE tile at half the AIE tile rate, potentially resulting in stalls (with the AIE tile waiting for data to be available)

    • a 64-bit PL stream running at half the AIE clock can provide 32-bit data to the AIE tile at the AIE tile rate

    • a 128-bit PL stream running at a quarter of the AIE clock can provide 32-bit data to the AIE tile at the AIE tile rate

aie::abs_square\<T\>( ) is an API which calculates the squared magnitude of the input.

writeincr( ) is an API which writes values from a vector register to an output stream. The number of elements to write is determined by the size of the vector register.

stream