Using HLS Streams - 2021.1 English

Vitis High-Level Synthesis User Guide (UG1399)

Document ID
Release Date
2021.1 English

To use hls::stream<> objects, include the header file hls_stream.h. Streaming data objects are defined by specifying the type and variable name. In this example, a 128-bit unsigned integer type is defined and used to create a stream variable called my_wide_stream.

#include "ap_int.h"
#include "hls_stream.h"

typedef ap_uint<128> uint128_t;  // 128-bit user defined type
hls::stream<uint128_t> my_wide_stream;  // A stream declaration

Streams must use scoped naming. Xilinx recommends using the scoped hls:: naming shown in the example above. However, if you want to use the hls namespace, you can rewrite the preceding example as:

#include <ap_int.h>
#include <hls_stream.h>
using namespace hls;

typedef ap_uint<128> uint128_t;  // 128-bit user defined type
stream<uint128_t> my_wide_stream;  // hls:: no longer required

Given a stream specified as hls::stream<T>, the type T can be:

  • Any C++ native data type
  • A Vitis HLS arbitrary precision type (for example, ap_int<>, ap_ufixed<>)
  • A user-defined struct containing either of the above types
Note: General user-defined classes (or structures) that contain methods (member functions) should not be used as the type (T) for a stream variable.

A stream can also be specified as hls::stream<Type, Depth>, where Depth indicates the depth of the FIFO needed in the verification adapter that the HLS tool creates for RTL co-simulation.

Streams can be optionally named. Providing a name for the stream allows the name to be used in reporting. For example, Vitis HLS automatically checks to ensure all elements from an input stream are read during simulation. Given the following two streams:

stream<uint8_t> bytestr_in1;
stream<uint8_t> bytestr_in2("input_stream2");
WARNING: Hls::stream 'hls::stream<unsigned char>.1' contains leftover data, which 
may result in RTL simulation hanging.
WARNING: Hls::stream 'input_stream2' contains leftover data, which may result in RTL 
simulation hanging.
Any warning on elements left in the streams are reported as follows, where
         it is clear that the bytetr_in2 must be bytestr_in2:

When streams are passed into and out of functions, they must be passed-by-reference as in the following example:

void stream_function (
      hls::stream<uint8_t> &strm_out,
      hls::stream<uint8_t> &strm_in,
     uint16_t strm_len

Vitis HLS supports both blocking and non-blocking access methods.

A complete design example using streams is provided in the Vitis HLS examples. Refer to the hls_stream example in the design examples available from the Vitis IDE welcome screen.