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
}
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.