Resource Sharing
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.
How Resource Sharing Works
You can specify a sharing factor for a subsystem or a MATLAB Function block. HDL Coder tries to identify a certain number of identical, shareable resources up to the value of the sharing factor. How HDL Coder shares these resources depends on the number of resources, the sharing factor, and the oversampling value for your design. To learn how to set an oversampling value for your design, see Specifying the Oversampling Value.
By default, the oversampling value is 1, and resource sharing overclocks the
shared resources by an overclocking factor that depends on the remainder of the
sharing factor and the number of resources. In this code, OCF
is
the overclocking factor, N
is the number of sharable resources,
and SF
is the sharing factor:
if rem(SF,N) == 0 OCF = N; else OCF = SF; end
If you specify an oversampling value greater than 1, either automatically by using
the Treat Simulink rates as actual hardware rates parameter or
manually by using the Oversampling factor parameter, your
design operates a faster clock rate on the target hardware when clock-rate
pipelining is enabled. When you specify a SharingFactor, the
resource sharing optimization tries to share up to N
resources
and overclocks the shared resources by a factor given by:
Overclocking factor = (block_rate ÷ DUT_base_rate) × Oversampling value
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.
Benefits and Costs of Resource Sharing
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.
Shareable Resources in Different Blocks
If you specify the sharing factor for a MATLAB Function block to a value greater than 1, HDL Coder identifies and shares functionally equivalent multipliers.
If you specify the sharing factor for a Subsystem to a value greater than 1, 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
The code generator shares functionally equivalent MATLAB Function
blocks with fixed-point types. When you use floating-point types or use the
MATLAB Datapath
architecture for MATLAB
Function blocks with fixed-point types, HDL Coder treats the MATLAB Function block as a regular
Subsystem. You can then share functionally equivalent resources
inside the MATLAB Function block. To learn more, see Use MATLAB Datapath Architecture for Sharing with MATLAB Function Blocks.
Specify Resource Sharing
To specify resource sharing 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 SharingFactor field, enter the number of shareable resources.
Right-click the subsystem, model reference, or MATLAB Function block and select HDL Code > HDL Block Properties. In the SharingFactor field, enter the number of shareable resources.
At the command-line, set the SharingFactor
using
hdlset_param
, as in the following
example.
modelname = 'sfir_fixed' dut = 'sfir_fixed/symmetric_fir'; open_system(modelname) hdlset_param(dut,'SharingFactor', 4);
Block Requirements for Resource Sharing
For blocks to be shared, they must meet these requirements:
Single rate.
The DUT must not contain blocks with
inf
sample time. During HDL code generation, HDL Coder only resolvesinf
sample times when the sample times do not propagate to the DUT output. For more information, see Use Discrete and Finite Sample Time for Constant Block.No bus inputs or outputs.
No tunable mask parameters. To share these blocks, in the Mask Editor, clear the Tunable check box.
If the block is within a feedback loop, at least one Unit Delay or Delay block must be connected to each output port.
To learn about block-specific settings and requirements for resource sharing, see:
Resource Sharing Report
To see the resource sharing 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 the optimization report, in the Streaming and Sharing section, you see the effect of the resource sharing optimization. If resource sharing is unsuccessful, the report shows diagnostic messages and offending blocks that cause resource sharing to fail.
If resource sharing is successful, the report displays the SharingFactor, and a table that contains groups of blocks that shared resources. The table contains:
Group Id: A unique ID for a group of similar Simulink® blocks, such as add or product blocks, that share resources.
Resource Type: The type of Simulink block in a sharing group.
I/O Wordlengths: Word lengths of inputs to and output from the block in a sharing group.
Group size: Number of blocks of the same type in a sharing group.
Block name: Name of a block that belongs to a sharing group.
Color Legend: Color that highlights all the blocks in a sharing group.
To see the shared resources in your Simulink model and in the generated model, click the Highlight shared resources and diagnostics link.
Limitations for Resource Sharing
Multirate sharing cannot share resources that have a different number of pipelines inserted from adaptive pipelining.
Model references are not supported for resource sharing.