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, HDL Coder generates fully parallel implementations for vector computations. For example, the code generator 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 (
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
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.
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 code generator 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.
To specify streaming from the UI:
In the Apps tab, select HDL Coder. The HDL Code tab appears. Select the subsystem, model reference, or MATLAB Function block and then click HDL Block Properties. In the StreamingFactor field, enter the number of resources that you want to stream.
For MATLAB Function blocks, to specify the StreamingFactor, in the HDL Block Properties dialog box, you must set the HDL architecture of the block to
Right-click the subsystem, model reference, or MATLAB Function block and select HDL Code > HDL Block Properties. In the StreamingFactor field, enter the number of resources that you want to stream.
At the command-line, you can set
StreamingFactor using the
hdlset_param function, as in the following example.
modelname = 'sfir_fixed' dut = 'sfir_fixed/symmetric_fir'; open_system(modelname) hdlset_param(dut,'StreamingFactor', 4);
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
If the original data path operated with a sample time,
is equal to the base sample time, then the streamed subsystem operates with a sample
S / Nst, if
S / Vdim, if
If the original data path operated with a sample time,
is greater than the base sample
Sbase, then the streamed subsystem
operates with a sample time of
Oversampling. Notice that the streamed sample time is
independent of the original sample time,
Determine 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
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.
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
Nstis a perfect divisor of the vector width
Vdim, or the vector width must be a perfect divisor of the streaming factor.
All inputs to the subsystem have the same vector size. If the inputs have different vector sizes, you can stream the subsystem by flattening the subsystem hierarchy. When you flatten the hierarchy, the streaming optimization identifies regions with different vector sizes and creates streaming groups for these regions. These groups have different streaming factors that are inferred from the vector sizes.
To see the streaming information in the report, before you generate code for each subsystem or model reference, enable the optimization report. To enable this report, in the HDL Code tab, select Report Options, and then select Generate optimization report.
When you generate an optimization report, in the Streaming and Sharing section, you see the effect of the streaming optimization. If streaming is unsuccessful, the report shows diagnostic messages and offending blocks that caused streaming to fail. When the requested streaming factor cannot be implemented, HDL Coder generates non-streaming code.
If streaming is successful, the report displays the StreamingFactor that was inferred, and a table that specifies:
Group: A unique group ID for a group of Simulink® blocks that belong to a streaming group.
Inferred Streaming Factor: Streaming factor inferred by HDL Coder with the Streaming Factor that you specify in the HDL Block Properties.
To see groups of blocks that belong to a streaming group in your Simulink model and in the generated model, click the Highlight streaming groups and diagnostics link in the report.