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 SF for a subsystem or a MATLAB Function block. HDL Coder tries to identify a certain number of identical, shareable resources N up to SF. How the code generator shares these resources depends on N, SF, and the Oversampling factor.

By default, the Oversampling factor is 1, and resource sharing overclocks the shared resources by an overclocking factor (OCF) that depends on the remainder of SF and N.

if rem(SF,N) == 0
    OCF = N;
    OCF = SF;

If you specify an Oversampling factor greater than 1, your design operates a faster clock rate on the target hardware because clock-rate pipelining is enabled by default. 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

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 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

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';
hdlset_param(dut,'SharingFactor', 4);

Limitations for Resource Sharing

HDL Coder does not support model references for resource sharing.

Block Requirements for Resource Sharing

Blocks to be shared must have the following requirements:

  • Single-rate.

  • No infinite sample rate. 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'); 

  • 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.

Related Examples

More About