hls::stream.capacity() Method - 2024.1 English

Vitis High-Level Synthesis User Guide (UG1399)

Document ID
UG1399
Release Date
2024-05-30
Version
2024.1 English

The hls::stream.capacity() method returns an unsigned integer which defines the maximum number of elements the stream can hold, or the total depth of the stream This lets you check how much space is available in the channel prior to writing.

hls::stream<int> my_stream;
int var = 16;

if ((my_stream.capacity() - my_stream.size()) >= N) {
  for (int=0; i<N;i++)
    my_stream.write(...); // this will not block
}
Tip: In C-simulation hls::stream.capacity() returns MAXINT as a theoretical limit. In synthesis and C/RTL Co-simulation it returns the computed capacity of the stream.

The hls::stream.capacity() and hls::stream.size() methods enable advanced flow control to write or read the stream only when there is specific amounts of space or data available for the transaction. For example, before starting a read burst of size N, you can check if there are N data items in the input stream so that the burst can complete without stalling. For write bursts you can also check if there is enough space available in an output stream to store the burst data without stalling.