Resource sharing is an area optimization in which HDL Coder™ identifies multiple functionally equivalent resources and replaces them with a single resource. The data is time-multiplexed over the shared resource to perform the same operations.
You can specify a sharing factor N for a subsystem or a MATLAB Function block. HDL Coder tries to identify up to N shareable resources, and, by default, oversamples by a factor of N to generate an area-optimized implementation with the original latency. If the coder cannot identify N shareable resources, it shares as many as it can, but still oversamples by a factor of N.
You can limit the oversampling ratio to meet target hardware clock constraints. For details, see Optimization with Constrained Overclocking.
You can 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.
If you specify a nonzero sharing factor for a MATLAB Function block, HDL Coder identifies and shares functionally equivalent multipliers.
If you specify a nonzero sharing factor for a subsystem, HDL Coder identifies and shares functionally equivalent instances of the following types of blocks:
Gain
Product
Multiply-Add
Add or Sum with two inputs
Atomic Subsystem
MATLAB Function
Resource sharing can substantially reduce your chip area. For example, the generated code can use one multiplier to perform the operations of several identically configured multipliers from the original model. However, resource sharing has the following costs:
Uses more multiplexers and can use more registers.
Reduces opportunities for distributed pipelining or retiming, because HDL Coder does not pipeline across clock rate boundaries.
Multiplies the clock rate of the target hardware by the sharing factor.
To specify resource sharing from the UI:
Right-click the subsystem, model reference, or MATLAB Function block.
Select HDL Code > HDL Block Properties.
In the SharingFactor field, enter the number of shareable resources.
Set the SharingFactor
using hdlset_param
,
as in the following example.
dut = 'ex_dimcheck/Channel'; hdlset_param(dut,'SharingFactor',3);
HDL Coder does not support model references for resource sharing.
The DUT must not contain
blocks with Sample time set to Inf
.
For example, Constant blocks must have Sample
time set to -1. To set the sample time to -1 for all Constant blocks
in your DUT, use the following MATLAB code:
blks = find_system(dut, 'BlockType', 'Constant'); for i = 1:length(blks) set_param(blks{i}, 'SampleTime', '-1'); end
Blocks to be shared have the following requirements:
Single-rate.
No bus inputs or outputs.
If the block is within a feedback loop, at least one Unit Delay or Delay block connected to each output port.
If you set the maximum oversampling ratio to 1, shared resources cannot be inside feedback loops.
If you set the maximum oversampling ratio to 1, shared resources cannot have latency.
If you want to share Atomic Subsystem blocks:
The only state elements that these blocks can contain are:
Delay
Unit Delay
Unit Delay Enabled
Unit Delay Resettable
Unit Delay Enabled Resettable
These blocks must have the Initial condition parameter set to 0.
These blocks must not contain a subsystem that does not meet the requirements for resource sharing.
If you want to share MATLAB Function blocks, they must not use:
Persistent variables
Loop streaming
Output pipelining
For resource sharing, the Product blocks and Gain blocks can have different word-lengths. To share the blocks, specify the multiplier promotion threshold and the sharing factor. The multiplier promotion threshold is the maximum word-length by which HDL Coder promotes a multiplier for sharing with other multipliers.
To specify the multiplier promotion threshold, in the Configuration
Parameters dialog box, on the HDL Code Generation > Target and Optimizations > Resource
sharing tab, for Multiplier promotion
threshold, enter an integer. For more information, see MultiplierPromotionThreshold
.
HDL Coder can share Atomic Subsystem and MATLAB Function blocks that have:
The same Simulink® checksum. Use Simulink.Subsystem.getChecksum
to determine
the checksum.
The same HDL block properties.
In addition, if you use the DSPStyle
block
property, HDL Coder does not share multipliers that have different
synthesis attribute settings.
You cannot apply resource sharing to a subset of instances for a particular atomic subsystem; you must share all instances. If you want to share a subset of atomic subsystem instances, change the remaining instances to virtual subsystems.
The only blocks with state elements that can be part of a shared atomic subsystem are:
Delay
Unit Delay
Unit Delay Enabled
Unit Delay Resettable
Unit Delay Enabled Resettable
Therefore, you cannot share atomic subsystems that contain the following blocks or block implementations:
Detect Change
Discrete Transfer Fcn
HDL FFT
HDL FIFO
Math Function (conj, hermitian, transpose)
MATLAB Function blocks that contain persistent variables
Sqrt
Cascade architecture (MinMax, Product, Sum)
CORDIC architecture
Reciprocal Newton architecture
Filter blocks, except Discrete FIR Filter
Communications System Toolbox™ blocks
DSP System Toolbox™ blocks, except Discrete FIR Filter
Stateflow® blocks
Blocks that are not supported for delay balancing. For details, see Delay Balancing Limitations.
If you generate a code generation report for each subsystem or MATLAB Function block that implements sharing, the report includes the following information:
Success: Lists resource usage changes caused by sharing and displays a link to highlight groups of blocks in the Simulink model that shared resources.
Failure: Identifies which criterion was violated and displays the link to any offending blocks in the Simulink model that caused resource sharing to fail.
Latency changes.
For more information on the sharing report, see streaming and sharing report in Optimization Report