Streaming

What Is Streaming?

Streaming is an area optimization in which HDL Coder™ transforms a vector data path to a scalar data path (or to several smaller-sized vector data paths). By default, the coder generates fully parallel implementations for vector computations. For example, the coder realizes a vector sum as several adders, executing in parallel during a single clock cycle. This technique can consume many hardware resources. With streaming, the generated code saves chip area by multiplexing the data over a smaller number of shared hardware resources.

By specifying a streaming factor for a subsystem, you can control the degree to which such resources are shared within that subsystem. When the ratio of streaming factor (Nst) to subsystem data path width (Vdim) is 1:1, HDL Coder implements an entirely scalar data path. A streaming factor of 0 (the default) produces a fully parallel implementation (that is, without sharing) for vector computations.

If you know the maximal vector dimensions and the sample rate for a subsystem, you can compute the possible streaming factors and resulting sample rates for the subsystem. However, even if the requested streaming factor is mathematically possible, the subsystem must meet other criteria for streaming. See Requirements and Limitations for Streaming for details.

By default, when you apply the streaming optimization, HDL Coder oversamples the shared hardware resource to generate an area-optimized implementation with the original latency. If the streamed data path is operating at a rate slower than the base rate, the coder implements the data path at the base rate. You can also limit the oversampling ratio to meet target hardware clock constraints. To learn more, see Clock-Rate Pipelining.

You can generate and use the validation model to verify that the output of the optimized DUT is bit-true to the results produced by the original DUT. To learn more about the validation model, see Generated Model and Validation Model.

Specify Streaming

You apply streaming at the subsystem level. Specify the streaming factor by setting the subsystem HDL parameter StreamingFactor. You can set StreamingFactor in the HDL Properties dialog box for a subsystem, as shown in the following figure.

Alternatively, you can set StreamingFactor using the hdlset_param function, as in the following example.

dut = 'sfir_fixed/symmetric_fir';
hdlset_param(dut,'StreamingFactor', 4);

Requirements and Limitations for Streaming

This section describes the criteria for streaming that subsystems must meet.

Blocks That Support Streaming

HDL Coder supports many blocks for streaming. As a best practice, run the checkhdl function before generating streaming code for a subsystem. checkhdl reports blocks in your subsystem that are incompatible with streaming. If you initiate streaming code generation for a subsystem that contains incompatible blocks, the coder works around those blocks and generates non-streaming code for them.

HDL Coder cannot apply the streaming optimization to a model reference.

How to Determine Streaming Factor and Sample Time

In a given subsystem, if Nst is the streaming factor, and Vdim is the maximum vector dimension, then the data path of the resultant streamed subsystem is one of the following:

  • Of width Vstream = (Vdim/Nst), if Vdim > Nst.

  • Of width Vstream = (Nst/Vdim), if Nst > Vdim.

  • Scalar.

If the original data path operated with a sample time, S, that is equal to the base sample time, then the streamed subsystem operates with a sample time of:

  • S / Nst, if Vdim > Nst.

  • S / Vdim, if Nst > Vdim.

If the original data path operated with a sample time, S, that is greater than the base sample time,Sbase, then the streamed subsystem operates with a sample time of Sbase / Oversampling. Notice that the streamed sample time is independent of the original sample time, S.

Checks and Requirements for Streaming Subsystems

Before applying streaming, HDL Coder performs a series of checks on the subsystems to be streamed. You can stream a subsystem if the streaming factor Nst is a perfect divisor of the vector width Vdim, or the vector width must be a perfect divisor of the streaming factor.

If the requested streaming factor cannot be implemented, HDL Coder generates non-streaming code. It is good practice to generate an Optimization Report. The Streaming and Sharing page of the report provides information about:

  • Success: Displays a link to highlight groups of blocks that belong to a streaming group in the Simulink® model and in the generated model.

  • Failure: Conditions that prevent streaming.

For more information on the streaming and sharing report, see Optimization Report.

More About

Was this topic helpful?