streamtools.h

The streamtools.h file collects multiple convenience functions for streams manipulation

Functions

template<unsigned int DataWidth, unsigned int NumAllowed, unsigned int NumTotal>
void StreamLimiter(hls::stream<ap_uint<DataWidth>> &in, hls::stream<ap_uint<DataWidth>> &out)

Stream limiter - limits the number of stream packets.

The block only let the first NumAllowed elements of a stream to pass through, the remainder (NumTotal-NumAllowed) are consumed from input but not re-emitted from the output. Useful to remove padding

Template Parameters
  • DataWidth: Width, in number of bits, of the input and output stream

  • NumAllowed: Number of words to pass through

  • NumTotal: Total number of words (NumAllowed+NumDropped)

Parameters
  • in: Input stream

  • out: Output stream

template<unsigned int DataWidth, unsigned int NumAllowed, unsigned int NumTotal>
void StreamLimiter_Batch(hls::stream<ap_uint<DataWidth>> &in, hls::stream<ap_uint<DataWidth>> &out, unsigned int numReps)

Stream limiter batch - limits the number of stream packets multiple times.

The block only let the first NumAllowed elements of a stream to pass through, the remainder (NumTotal-NumAllowed) are consumed from input but not re-emitted from the output. Useful to remove padding on multiple images (numReps)

Template Parameters
  • DataWidth: Width, in number of bits, of the input and output stream

  • NumAllowed: Number of words to pass through

  • NumTotal: Total number of words (NumAllowed+NumDropped)

Parameters
  • in: Input stream

  • out: Output stream

  • numReps: Number of times the StreamLimiter function has to be called

template<unsigned int ImgDim, unsigned int KernelDim, unsigned int Stride, unsigned int NumChannels, typename In_t, unsigned int PaddingStyle = 2>
void SameResize(stream<ap_uint<NumChannels * In_t::width>> &in, stream<ap_uint<NumChannels * In_t::width>> &out)

Stream Padding - Padds the input with zeroes for when the sliding window is centered on border pixels.

Used to add padding to the input with zeroes in case the sliding window is centered on border pixels

Template Parameters
  • ImgDim: Size of the input feature map

  • KernelDim: Size of the sliding window

  • Stride: Stride of the sliding window

  • NumChannels: Amount of channels of the input feature map

  • In_t: Input datatype

  • PaddingStyle: Type of padding that will be applied

Parameters
  • in: Input stream

  • out: Output stream

template<unsigned int ImgDim, unsigned int KernelDim, unsigned int Stride, unsigned int NumChannels, typename In_t, unsigned int PaddingStyle = 2>
void SameResize_Batch(stream<ap_uint<NumChannels * In_t::width>> &in, stream<ap_uint<NumChannels * In_t::width>> &out, const unsigned int numReps)

Stream Padding - Padds the input of multiple frames with zeroes for when the sliding window is centered on border pixels.

Used to add padding with zeroes to multiple inputs in case the sliding window is centered on border pixels

Template Parameters
  • ImgDim: Size of the input feature map

  • KernelDim: Size of the sliding window

  • Stride: Stride of the sliding window

  • NumChannels: Amount of channels of the input feature map

  • In_t: Input datatype

  • PaddingStyle: Type of padding that will be applied

Parameters
  • in: Input stream

  • out: Output stream

  • numReps: Amount of frames / images

template<typename InT, typename OutT>
void StreamingCast(hls::stream<InT> &in, hls::stream<OutT> &out, unsigned int numReps)

Stream cast - Casts the input stream to a different datatype (OutT)

Used to upscale or downscale a stream, enabling loss of information for downscaling or 0 padding for upscaling

Template Parameters
  • InT: Width, in number of bits, of the input and output stream

  • OutT: Number of words to pass through

Parameters
  • in: Input stream

  • out: Output stream

  • numReps: Number of times the StreamLimiter function has to be called

template<unsigned int ImgDim, unsigned int OutputDim, unsigned int Padding, unsigned int NumChannels, unsigned int SIMD, typename In_t, unsigned int PaddingStyle = 2>
void FMPadding(stream<ap_uint<SIMD * In_t::width>> &in, stream<ap_uint<SIMD * In_t::width>> &out)

FM Padding - Padds the input with zeroes for when the sliding window is centered on border pixels.

Used to add padding to the input with zeroes in case the sliding window is centered on border pixels

Template Parameters
  • ImgDim: Size of the input feature map

  • OutputDim: Size of the output feature map

  • Padding: Amount of padding in total

  • NumChannels: Amount of channels of the input feature map

  • SIMD: Input parallelism

  • In_t: Input datatype

  • PaddingStyle: Type of padding that will be applied

Parameters
  • in: Input stream

  • out: Output stream

template<unsigned int ImgDim, unsigned int OutputDim, unsigned int Padding, unsigned int NumChannels, unsigned int SIMD, typename In_t, unsigned int PaddingStyle = 2>
void FMPadding_Batch(stream<ap_uint<SIMD * In_t::width>> &in, stream<ap_uint<SIMD * In_t::width>> &out, const unsigned int numReps)

FM Padding - Padds the input of multiple frames with zeroes for when the sliding window is centered on border pixels.

Used to add padding with zeroes to multiple inputs in case the sliding window is centered on border pixels

Template Parameters
  • ImgDim: Size of the input feature map

  • OutputDim: Size of the output feature map

  • Padding: Amount of padding in total

  • NumChannels: Amount of channels of the input feature map

  • SIMD: Input parallelism

  • In_t: Input datatype

  • PaddingStyle: Type of padding that will be applied

Parameters
  • in: Input stream

  • out: Output stream

  • numReps: Amount of frames / images

template<unsigned int OutputDim_x, unsigned int OutputDim_y, unsigned int Padding_x, unsigned int Padding_y, unsigned int NumChannels, unsigned int SIMD, typename In_t, unsigned int PaddingStyle = 2>
void FMPadding_nonsquare(stream<ap_uint<SIMD * In_t::width>> &in, stream<ap_uint<SIMD * In_t::width>> &out)

FM Padding - Padds the input with zeroes for when the sliding window is centered on border pixels.

Used to add padding with zeroes to multiple inputs in case the sliding window is centered on border pixels - working on non-square images and padding

Template Parameters
  • OutputDim_x: Width of the output feature map (padded)

  • OutputDim_y: Height of the output feature map (padded)

  • Padding_x: Amount of padding over x axis

  • Padding_y: Amount of padding over y axis

  • NumChannels: Amount of channels of the input feature map

  • SIMD: Input parallelism

  • In_t: Input datatype

  • PaddingStyle: Type of padding that will be applied

Parameters
  • in: Input stream

  • out: Output stream

template<unsigned int OutputDim_x, unsigned int OutputDim_y, unsigned int Padding_x, unsigned int Padding_y, unsigned int NumChannels, unsigned int SIMD, typename In_t, unsigned int PaddingStyle = 2>
void FMPadding_nonsquare_Batch(stream<ap_uint<SIMD * In_t::width>> &in, stream<ap_uint<SIMD * In_t::width>> &out, const unsigned int numReps)

FM Padding Non Square - Padds the input of multiple frames with zeroes for when the sliding window is centered on border pixels.

Used to add padding with zeroes to multiple inputs in case the sliding window is centered on border pixels - working on non-square images and padding

Template Parameters
  • OutputDim_x: Width of the output feature map (padded)

  • OutputDim_y: Height of the output feature map (padded)

  • Padding_x: Amount of padding over x axis

  • Padding_y: Amount of padding over y axis

  • NumChannels: Amount of channels of the input feature map

  • SIMD: Input parallelism

  • In_t: Input datatype

  • PaddingStyle: Type of padding that will be applied

Parameters
  • in: Input stream

  • out: Output stream

  • numReps: Amount of frames / images

template<unsigned int InWidth, unsigned int OutWidth, unsigned int NumInWords>
void StreamingDataWidthConverter_Batch(hls::stream<ap_uint<InWidth>> &in, hls::stream<ap_uint<OutWidth>> &out, const unsigned int numReps)

Stream Data Width Converter - Converts the width of the input stream in the output stream.

Used to upscale or downscale a stream, without any loss of data in the procedure. For downscaling (InWidth > OutWidth), InWidth has to be a multiple of OutWidth. For upscaling (InWidth < OutWidth), OutWidth has to be a multiple of InWidth.

Template Parameters
  • InWidth: Width, in number of bits, of the input stream

  • OutWidth: Width, in number of bits, of the output stream

  • NumInWords: Number of input words to process

Parameters
  • in: Input stream

  • out: Output stream

  • numReps: Number of times the function has to be called

template<unsigned int InWidth, unsigned int OutWidth>
void StreamingDataWidthConverterNoMultiple(hls::stream<ap_uint<InWidth>> &in, hls::stream<ap_uint<OutWidth>> &out)

Stream Data Width Converter No Multiple - Converts the width of the input stream in the output stream for no multiple dimensions.

Used to downscale a stream, without any loss of data in the procedure. For downscaling (InWidth > OutWidth), InWidth has to be a multiple of OutWidth.

Template Parameters
  • InWidth: Width, in number of bits, of the input stream

  • OutWidth: Width, in number of bits, of the output stream

Parameters
  • in: Input stream

  • out: Output stream

template<unsigned int DataWidth, unsigned int NumTotal>
void DuplicateStreams(stream<ap_uint<DataWidth>> &in, stream<ap_uint<DataWidth>> &out1, stream<ap_uint<DataWidth>> &out2)

Stream Duplicator - Reads in a stream and writes the data into two identical streams.

Used to generate the inputs to the bypass and convolutional branches in Resnet-50

Template Parameters
  • DataWidth: Width, in number of bits, of the streams

  • NumTotal: Total number of words in the input stream

Parameters
  • in: Input stream

  • out1: Output stream I

  • out2: Output stream II

template<unsigned int DataWidth, unsigned int NumTotal>
void DuplicateStreams_Batch(stream<ap_uint<DataWidth>> &in, stream<ap_uint<DataWidth>> &out1, stream<ap_uint<DataWidth>> &out2, const unsigned int numReps)

Batch Stream Duplicator - Reads in a stream multiple times and writes the data into two identical streams.

Used to generate the inputs to the bypass and convolutional branches in Resnet-50 when dealing with multiple ‘frames’

Template Parameters
  • DataWidth: Width, in number of bits, of the streams

  • NumTotal: Total number of words in the input stream

Parameters
  • in: Input stream

  • out1: Output stream I

  • out2: Output stream II

  • numReps: Number of frames / images

template<unsigned int NumChannels, typename In1_t, typename In2_t, typename Out_t, unsigned int NumTotal, int offset = 0>
void AddStreams(stream<ap_uint<NumChannels * In1_t::width>> &in1, stream<ap_uint<NumChannels * In2_t::width>> &in2, stream<ap_uint<NumChannels * Out_t::width>> &out)

Element-Wise Addition - Reads in data elements from two streams and writes the sum of these elements to an output.

Template Parameters
  • NumChannels: Amount of channels of the streams

  • In1_t: First operand datatype

  • In2_t: Second operand datatype

  • Out_t: Datatype of the accumulation output

  • NumTotal: Total number of words in the input streams

  • offset: Offset value for the accumulation

Parameters
  • in1: Input stream I

  • in2: Input stream II

  • out: Output stream

template<unsigned int NumChannels, typename In1_t, typename In2_t, typename Out_t, unsigned int NumTotal, int offset = 0>
void AddStreams_Batch(stream<ap_uint<NumChannels * In1_t::width>> &in1, stream<ap_uint<NumChannels * In2_t::width>> &in2, stream<ap_uint<NumChannels * Out_t::width>> &out, const unsigned int numReps)

Used to implement point-wise addition in Resnet-50 for multiple images.

Template Parameters
  • NumChannels: Amount of channels of the streams

  • In1_t: First operand datatype

  • In2_t: Second operand datatype

  • Out_t: Datatype of the accumulation output

  • NumTotal: Total number of words in the input streams

  • offset: Offset value for the accumulation

Parameters
  • in1: Input stream I

  • in2: Input stream II

  • out: Output stream

  • numReps: Number of frames / images

template<unsigned int NumChannels, typename In1_t, typename In2_t, typename Out_t, unsigned int NumTotal, unsigned int PECount, int offset = 0>
void AddStreamsLayer_Batch(stream<ap_uint<NumChannels * In1_t::width>> &in1, stream<ap_uint<NumChannels * In2_t::width>> &in2, stream<ap_uint<NumChannels * Out_t::width>> &out, const unsigned int numReps)

Addition Layer - Reads in two streams and writes the sum of these streams to an output.

Used to merge the outputs of the bypass and convolutional branches in Resnet-50

Template Parameters
  • NumChannels: Amount of channels of the streams

  • In1_t: First operand datatype

  • In2_t: Second operand datatype

  • Out_t: Datatype of the accumulation output *

  • NumTotal: Total number of words in the input streams

  • PECount: Amount of processing elements working in parallel

  • offset: Offset value for the accumulation

Parameters
  • in1: Input stream I

  • in2: Input stream II

  • out: Output stream

  • numReps: Number of frames / images

template<unsigned int InWidth, unsigned int OutWidth, unsigned int NumInWords, unsigned int NumVecs>
void MultiChanDataWidthConverter_Batch(stream<MultiChanData<NumVecs, InWidth>> &in, stream<MultiChanData<NumVecs, OutWidth>> &out, const unsigned int numReps)

Stream Multi Chan Data Width Converter - Converts the width of the input stream in the output stream, working on multiple parallel streams.

Used to upscale or downscale a stream, without any loss of data in the procedure. For downscaling (InWidth > OutWidth), InWidth has to be a multiple of OutWidth. For upscaling (InWidth < OutWidth), OutWidth has to be a multiple of InWidth. This version works on the MMV structure, with multiple parallel streams

Template Parameters
  • InWidth: Width, in number of bits, of the input stream

  • OutWidth: Width, in number of bits, of the output stream

  • NumInWords: Number of input words to process

  • NumVecs: Number of parallel vectors MMV

Parameters
  • in: Input stream

  • out: Output stream

  • numReps: Number of times the function has to be called

template<unsigned int NumChannels, unsigned int DataWidth>
void FlattenMultiChanData(stream<MultiChanData<NumChannels, DataWidth>> &in, stream<ap_uint<NumChannels * DataWidth>> &out, const unsigned int numReps)

Flatten Multi Chan Data - Converts the parallel input stream in a flatten output stream.

Used to pach a flattened stream into a structure with multiple parallel streams

Template Parameters
  • NumChannels: Number of channels flattened in the input stream

  • DataWidth: Width, in number of bits, of each stream

Parameters
  • in: Input parallel stream

  • out: Output stream

  • numReps: Number of times the function has to be called

template<unsigned int NumChannels, unsigned int DataWidth>
void PackMultiChanData(stream<ap_uint<NumChannels * DataWidth>> &in, stream<MultiChanData<NumChannels, DataWidth>> &out, const unsigned int numReps)

Pack Multi Chan Data - Converts the flatten input stream into a parallel output stream.

Used to pach a flattened stream into a structure with multiple parallel streams

Template Parameters
  • NumChannels: Number of channels flattened in the input stream

  • DataWidth: Width, in number of bits, of each stream

Parameters
  • in: Input stream

  • out: Output parallel stream

  • numReps: Number of times the function has to be called

template<unsigned int DataWidth, unsigned int NumTotal>
void Qdma2Stream_Batch(hls::stream<qdma_axis<DataWidth, 0, 0, 0>> &in, hls::stream<ap_uint<DataWidth>> &out, const unsigned int numReps)

QDMA stream to normal stream conversion - Reads in a QDMA stream and strips metadata (TLAST, TKEEP)

Used as an adapter when connecting blocks through top-level Vitis streams (kernel to kernel or host to plaform streaming)

Template Parameters
  • DataWidth: Width, in number of bits, of the data on streams

  • NumTotal: Total number of words in the input stream

Parameters
  • in: Input stream

  • out: Output stream

  • numReps: Number of frames / images

template<unsigned int DataWidth, unsigned int NumTotal>
void Stream2Qdma_Batch(hls::stream<ap_uint<DataWidth>> &in, hls::stream<qdma_axis<DataWidth, 0, 0, 0>> &out, const unsigned int numReps)

Normal stream to QDMA stream conversion - Reads in a stream and outputs a QDMA stream including metadata (TLAST, TKEEP)

Used as an adapter when connecting blocks through top-level Vitis streams (kernel to kernel or host to plaform streaming)

Template Parameters
  • DataWidth: Width, in number of bits, of the data on streams

  • NumTotal: Total number of words in the input stream

Parameters
  • in: Input stream

  • out: Output stream

  • numReps: Number of frames / images

template<unsigned IW, unsigned OW, unsigned N>
class WidthAdjustedInputStream
#include <streamtools.h>

Public Functions

WidthAdjustedInputStream(hls::stream<ap_uint<IW>> &source, unsigned const reps)
~WidthAdjustedInputStream()
operator hls::stream<ap_uint<OW>>&()

Private Members

hls::stream<ap_uint<OW>> m_target
template<unsigned W, unsigned N>
class WidthAdjustedInputStream<W, W, N>
#include <streamtools.h>

Public Functions

WidthAdjustedInputStream(hls::stream<ap_uint<W>> &source, unsigned const reps)
~WidthAdjustedInputStream()
operator hls::stream<ap_uint<W>>&()

Private Members

hls::stream<ap_uint<W>> &m_source
template<unsigned IW, unsigned OW, unsigned N>
class WidthAdjustedOutputStream
#include <streamtools.h>

Public Functions

WidthAdjustedOutputStream(hls::stream<ap_uint<OW>> &target, unsigned const reps)
~WidthAdjustedOutputStream()
operator hls::stream<ap_uint<IW>>&()

Private Members

hls::stream<ap_uint<IW>> m_buffer
hls::stream<ap_uint<OW>> &m_target
unsigned const m_reps
template<unsigned W, unsigned N>
class WidthAdjustedOutputStream<W, W, N>
#include <streamtools.h>

Public Functions

WidthAdjustedOutputStream(hls::stream<ap_uint<W>> &target, unsigned const reps)
~WidthAdjustedOutputStream()
operator hls::stream<ap_uint<W>>&()

Private Members

hls::stream<ap_uint<W>> &m_target